Back to index

python-biopython  1.60
Classes | Functions | Variables
test_Emboss Namespace Reference

Classes

class  SeqRetSeqIOTests
class  SeqRetAlignIOTests
class  PairwiseAlignmentTests
class  TranslationTests

Functions

def get_emboss_version
def emboss_convert
def emboss_piped_SeqIO_convert
def emboss_piped_AlignIO_convert
def compare_records
def compare_alignments
def emboss_translate
def check_translation
def clean_up

Variables

list exes_wanted
tuple exes = dict()
list path = os.environ["EMBOSS_ROOT"]
tuple output = commands.getoutput("%s -help" % name)
tuple emboss_version = get_emboss_version()
tuple runner = unittest.TextTestRunner(verbosity = 2)

Function Documentation

def test_Emboss.check_translation (   sequence,
  translation,
  table = None 
)

Definition at line 803 of file test_Emboss.py.

00803 
00804 def check_translation(sequence, translation, table=None):
00805     if table is None:
00806         t = 1
00807     else:
00808         t = table
00809     if translation != str(sequence.translate(t)) \
00810     or translation != str(translate(sequence,t)) \
00811     or translation != translate(str(sequence),t):
00812         #More details...
00813         for i, amino in enumerate(translation):
00814             codon = sequence[i*3:i*3+3]
00815             if amino != str(codon.translate(t)):
00816                 raise ValueError("%s -> %s not %s (table %s)" \
00817                          % (codon, amino, codon.translate(t), t))
00818         #Shouldn't reach this line:
00819         raise ValueError("%s -> %s (table %s)" \
00820                          % (sequence, translation, t))
00821     return True

Here is the call graph for this function:

Here is the caller graph for this function:

Fallback clean up method to remove temp files.

Definition at line 899 of file test_Emboss.py.

00899 
00900 def clean_up():
00901     """Fallback clean up method to remove temp files."""
00902     for filename in os.listdir("Emboss"):
00903         if filename.startswith("temp_"):
00904             try:
00905                 os.remove(filename)
00906             except:
00907                 pass

Here is the caller graph for this function:

def test_Emboss.compare_alignments (   old_list,
  new_list 
)
Check two lists of Alignments agree, raises a ValueError if mismatch.

Definition at line 212 of file test_Emboss.py.

00212 
00213 def compare_alignments(old_list, new_list):
00214     """Check two lists of Alignments agree, raises a ValueError if mismatch."""
00215     if len(old_list) != len(new_list):
00216         raise ValueError("%i vs %i alignments" % (len(old_list), len(new_list)))
00217     for old, new in zip(old_list, new_list):
00218         if len(old) != len(new):
00219             raise ValueError("Alignment with %i vs %i records" \
00220                              % (len(old), len(new)))
00221         compare_records(old,new)
00222     return True

Here is the call graph for this function:

Here is the caller graph for this function:

def test_Emboss.compare_records (   old_list,
  new_list 
)
Check two lists of SeqRecords agree, raises a ValueError if mismatch.

Definition at line 181 of file test_Emboss.py.

00181 
00182 def compare_records(old_list, new_list):
00183     """Check two lists of SeqRecords agree, raises a ValueError if mismatch."""
00184     if len(old_list) != len(new_list):
00185         raise ValueError("%i vs %i records" % (len(old_list), len(new_list)))
00186     for old, new in zip(old_list, new_list):
00187         #Note the name matching is a bit fuzzy, e.g. truncation and
00188         #no spaces in PHYLIP files.
00189         if old.id != new.id and old.name != new.name \
00190         and (old.id not in new.id) and (new.id not in old.id) \
00191         and (old.id.replace(" ","_") != new.id.replace(" ","_")):
00192             raise ValueError("'%s' or '%s' vs '%s' or '%s' records" \
00193                              % (old.id, old.name, new.id, new.name))
00194         if len(old.seq) != len(new.seq):
00195             raise ValueError("%i vs %i" % (len(old.seq), len(new.seq)))
00196         if str(old.seq).upper() != str(new.seq).upper():
00197             if str(old.seq).replace("X","N")==str(new.seq) :
00198                 raise ValueError("X -> N (protein forced into nucleotide?)")
00199             if len(old.seq) < 200:
00200                 raise ValueError("'%s' vs '%s'" % (old.seq, new.seq))
00201             else:
00202                 raise ValueError("'%s...%s' vs '%s...%s'" \
00203                                  % (old.seq[:60], old.seq[-10:],
00204                                     new.seq[:60], new.seq[-10:]))
00205         if old.features and new.features \
00206         and len(old.features) != len(new.features):
00207             raise ValueError("%i vs %i features" \
00208                              % (len(old.features, len(new.features))))
00209         #TODO - check annotation
00210     return True
00211 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

def test_Emboss.emboss_convert (   filename,
  old_format,
  new_format 
)
Run seqret, returns handle.

Definition at line 96 of file test_Emboss.py.

00096 
00097 def emboss_convert(filename, old_format, new_format):
00098     """Run seqret, returns handle."""
00099     #Setup, this assumes for all the format names used
00100     #Biopython and EMBOSS names are consistent!
00101     cline = SeqretCommandline(exes["seqret"],
00102                               sequence = filename,
00103                               sformat = old_format,
00104                               osformat = new_format,
00105                               auto = True, #no prompting
00106                               stdout = True)
00107     #Run the tool,
00108     child = subprocess.Popen(str(cline),
00109                              stdin=subprocess.PIPE,
00110                              stdout=subprocess.PIPE,
00111                              stderr=subprocess.PIPE,
00112                              universal_newlines=True,
00113                              shell=(sys.platform!="win32"))
00114     child.stdin.close()
00115     child.stderr.close()
00116     return child.stdout
00117 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

def test_Emboss.emboss_piped_AlignIO_convert (   alignments,
  old_format,
  new_format 
)
Run seqret, returns alignments (as a generator).

Definition at line 144 of file test_Emboss.py.

00144 
00145 def emboss_piped_AlignIO_convert(alignments, old_format, new_format):
00146     """Run seqret, returns alignments (as a generator)."""
00147     #Setup, this assumes for all the format names used
00148     #Biopython and EMBOSS names are consistent!
00149     cline = SeqretCommandline(exes["seqret"],
00150                               sformat = old_format,
00151                               osformat = new_format,
00152                               auto = True, #no prompting
00153                               filter = True)
00154     #Run the tool,
00155     child = subprocess.Popen(str(cline),
00156                              stdin=subprocess.PIPE,
00157                              stdout=subprocess.PIPE,
00158                              stderr=subprocess.PIPE,
00159                              universal_newlines=True,
00160                              shell=(sys.platform!="win32"))
00161     try:
00162         AlignIO.write(alignments, child.stdin, old_format)
00163     except Exception, err:
00164         child.stdin.close()
00165         child.stderr.close()
00166         child.stdout.close()
00167         raise
00168     child.stdin.close()
00169     child.stderr.close()
00170     #TODO - Is there a nice way to return an interator AND
00171     #automatically close the handle? 
00172     try:
00173         aligns = list(AlignIO.parse(child.stdout, new_format))
00174     except Exception, err:
00175         child.stdout.close()
00176         raise
00177     child.stdout.close()
00178     return aligns
00179 
00180 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

def test_Emboss.emboss_piped_SeqIO_convert (   records,
  old_format,
  new_format 
)
Run seqret, returns records (as a generator).

Definition at line 118 of file test_Emboss.py.

00118 
00119 def emboss_piped_SeqIO_convert(records, old_format, new_format):
00120     """Run seqret, returns records (as a generator)."""
00121     #Setup, this assumes for all the format names used
00122     #Biopython and EMBOSS names are consistent!
00123     cline = SeqretCommandline(exes["seqret"],
00124                               sformat = old_format,
00125                               osformat = new_format,
00126                               auto = True, #no prompting
00127                               filter = True)
00128     #Run the tool,
00129     child = subprocess.Popen(str(cline),
00130                              stdin=subprocess.PIPE,
00131                              stdout=subprocess.PIPE,
00132                              stderr=subprocess.PIPE,
00133                              universal_newlines=True,
00134                              shell=(sys.platform!="win32"))
00135     SeqIO.write(records, child.stdin, old_format)
00136     child.stdin.close()
00137     child.stderr.close()
00138     #TODO - Is there a nice way to return an interator AND
00139     #automatically close the handle?
00140     records = list(SeqIO.parse(child.stdout, new_format))
00141     child.stdout.close()
00142     return records
00143 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

def test_Emboss.emboss_translate (   sequence,
  table = None,
  frame = None 
)
Call transeq, returns protein sequence as string.

Definition at line 748 of file test_Emboss.py.

00748 
00749 def emboss_translate(sequence, table=None, frame=None):
00750     """Call transeq, returns protein sequence as string."""
00751     #TODO - Support transeq in Bio.Emboss.Applications?
00752     #(doesn't seem worthwhile as Biopython can do translations)
00753 
00754     if not sequence:
00755         raise ValueError(sequence)
00756 
00757     #Setup,
00758     cline = exes["transeq"]
00759 
00760     if len(sequence) < 100:
00761         filename = None
00762         cline += " -sequence asis:%s" % sequence
00763     else:
00764         #There are limits on command line string lengths...
00765         #use a temp file instead.
00766         filename = "Emboss/temp_transeq.txt"
00767         SeqIO.write(SeqRecord(sequence, id="Test"), filename, "fasta")
00768         cline += " -sequence %s" % filename
00769 
00770     cline += " -auto" #no prompting
00771     cline += " -filter" #use stdout
00772     if table is not None:
00773         cline += " -table %s" % str(table)
00774     if frame is not None:
00775         cline += " -frame %s" % str(frame)
00776     #Run the tool,
00777     child = subprocess.Popen(str(cline),
00778                              stdin=subprocess.PIPE,
00779                              stdout=subprocess.PIPE,
00780                              stderr=subprocess.PIPE,
00781                              universal_newlines=True,
00782                              shell=(sys.platform!="win32"))
00783     out, err = child.communicate()
00784     #Check no error output:
00785     if err != "":
00786         raise ValueError(str(cline) + "\n" + err)
00787 
00788     #Check we could read it's output
00789     record = SeqIO.read(StringIO(out), "fasta")
00790 
00791     if 0 != child.wait():
00792         raise ValueError(str(cline))
00793     
00794     if filename:
00795         os.remove(filename)
00796         if not record.id.startswith("Test"):
00797             raise ValueError(str(cline))
00798     else:
00799         if not record.id.startswith("asis"):
00800             raise ValueError(str(cline))
00801     return str(record.seq)
00802 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

Returns a tuple of three ints, e.g. (6,1,0)

Definition at line 55 of file test_Emboss.py.

00055 
00056 def get_emboss_version():
00057     """Returns a tuple of three ints, e.g. (6,1,0)"""
00058     #Windows and Unix versions of EMBOSS seem to differ in
00059     #which lines go to stdout and stderr - so merge them.
00060     child = subprocess.Popen(exes["embossversion"],
00061                              stdout=subprocess.PIPE,
00062                              stderr=subprocess.STDOUT,
00063                              universal_newlines=True,
00064                              shell=(sys.platform!="win32"))
00065     stdout, stderr = child.communicate()
00066     child.stdout.close() #This is both stdout and stderr
00067     del child
00068     assert stderr is None #Send to stdout instead
00069     for line in stdout.split("\n"):
00070         if line.strip()=="Reports the current EMBOSS version number":
00071             pass
00072         elif line.startswith("Writes the current EMBOSS version number"):
00073             pass
00074         elif line.count(".")==2:
00075             return tuple(int(v) for v in line.strip().split("."))
00076         elif line.count(".")==3:
00077             #e.g. I installed mEMBOSS-6.2.0.1-setup.exe
00078             #which reports 6.2.0.1 - for this return (6,2,0)
00079             return tuple(int(v) for v in line.strip().split("."))[:3]
00080         else:
00081             #Either we can't understand the output, or this is really
00082             #an error message not caught earlier (e.g. not in English)
00083             raise MissingExternalDependencyError(\
00084                 "Install EMBOSS if you want to use Bio.Emboss (%s)." \
00085                 % line)
00086             
#To avoid confusing known errors from old versions of EMBOSS ...

Variable Documentation

Definition at line 87 of file test_Emboss.py.

tuple test_Emboss.exes = dict()

Definition at line 30 of file test_Emboss.py.

Initial value:
00001 ["water", "needle", "seqret", "transeq", "seqmatchall",
00002                "embossversion"]

Definition at line 28 of file test_Emboss.py.

tuple test_Emboss.output = commands.getoutput("%s -help" % name)

Definition at line 45 of file test_Emboss.py.

list test_Emboss.path = os.environ["EMBOSS_ROOT"]

Definition at line 35 of file test_Emboss.py.

tuple test_Emboss.runner = unittest.TextTestRunner(verbosity = 2)

Definition at line 909 of file test_Emboss.py.