Skip to content
Snippets Groups Projects
Commit abba7e6e authored by marco's avatar marco
Browse files

clustalw bindings

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2014 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 9fb346c4
Branches
Tags
No related merge requests found
pymod(NAME bindings PY __init__.py lga.py hbplus.py msms.py tmtools.py dssp.py) pymod(NAME bindings PY __init__.py lga.py hbplus.py msms.py tmtools.py
dssp.py clustalw.py utils.py)
from ost.bindings import utils
from ost import settings, io, seq
import os
import subprocess
def ClustalW(seq1, seq2, clustalw=None):
clustalw_path=settings.Locate(('clustalw', 'clustalw2'),
explicit_file_name=clustalw)
seq_list=seq.CreateSequenceList()
seq_list.AddSequence(seq1)
seq_list.AddSequence(seq2)
temp_dir=utils.TempDirWithFiles((seq_list,))
out=os.path.join(temp_dir.dirname, 'out.fasta')
command='%s -infile="%s" -output=fasta -outfile="%s"' % (clustalw_path,
temp_dir.files[0],
out)
ps=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
ps.stdout.readlines()
aln=io.LoadAlignment(out)
temp_dir.Cleanup()
return aln
\ No newline at end of file
import os
from ost import seq, mol, io
import tempfile
def SaveToTempDir(objects, seq_format='fasta', structure_format='pdb'):
"""
Take all objects and saves them to a temporary directory. The paths of the
saved files will be returned as a tuple. This works for alignments, and
structure files. The output format for sequence files and structure files can
be changed by setting to seq_format and structure_format parameters
appropriately.
"""
# create temporary directory
tmp_dir_name=tempfile.mkdtemp()
file_names=[]
for index, obj in enumerate(objects):
if isinstance(obj, seq.AlignmentHandle):
name=os.path.join(tmp_dir_name, 'aln%02d.fasta' % (index+1))
io.SaveAlignment(obj, name, seq_format)
file_names.append(name)
continue
if isinstance(obj, seq.SequenceHandle):
name=os.path.join(tmp_dir_name, 'seq%02d.fasta' % (index+1))
io.SaveSequence(obj, name, seq_format)
file_names.append(name)
continue
if isinstance(obj, seq.ConstSequenceList) or isinstance(obj, seq.SequenceList):
name=os.path.join(tmp_dir_name, 'sql%02d.fasta' % (index+1))
io.SaveSequenceList(obj, name, seq_format)
file_names.append(name)
continue
if isinstance(obj, mol.EntityView) or isinstance(obj, mol.EntityHandle):
name=os.path.join(tmp_dir_name, tmp_dir_name, 'mol%02d.pdb' % (index+1))
io.SaveEntity(model, name, structure_format)
file_names.append(name)
continue
return file_names
class TempDirWithFiles:
def __init__(self, objects, seq_format='fasta', structure_format='pdb'):
self.files=SaveToTempDir(objects, seq_format=seq_format,
structure_format=structure_format)
self.dirname=os.path.dirname(self.files[0])
def Cleanup(self):
import shutil
shutil.rmtree(self.dirname)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment