2 from ost
import settings, io, seq, LogError
6 def ClustalW(seq1, seq2=None, clustalw=None, keep_files=False, nopgap=False,
7 clustalw_option_string=
False):
8 clustalw_path=settings.Locate((
'clustalw',
'clustalw2'),
9 explicit_file_name=clustalw)
13 seq_list=seq.CreateSequenceList()
14 seq_list.AddSequence(seq1)
15 seq_list.AddSequence(seq2)
16 elif isinstance(seq1, str)
and isinstance(seq2, str):
17 seqh1=seq.CreateSequence(
"seq1", seq1)
18 seqh2=seq.CreateSequence(
"seq2", seq2)
19 seq_list=seq.CreateSequenceList()
20 seq_list.AddSequence(seqh1)
21 seq_list.AddSequence(seqh2)
23 LogError(
"WARNING: Specify at least two Sequences")
28 LogError(
"WARNING: Specify either two SequenceHandles or one SequenceList")
32 out=os.path.join(temp_dir.dirname,
'out.fasta')
33 command=
'%s -infile="%s" -output=fasta -outfile="%s"' % (clustalw_path,
38 if clustalw_option_string!=
False:
39 command=command+
" "+clustalw_option_string
41 ps=subprocess.Popen(command, shell=
True, stdout=subprocess.PIPE)
43 aln=io.LoadAlignment(out)
46 for sequence
in seq_list:
47 for seq_num,aln_seq
in enumerate(aln.sequences):
48 if aln_seq.GetName()==sequence.GetName():
50 aln.SetSequenceOffset(seq_num,sequence.offset)
51 if sequence.HasAttachedView():
52 aln.AttachView(seq_num,sequence.GetAttachedView().Copy())