Back to index

python-biopython  1.60
Public Member Functions
test_Muscle_tool.SimpleAlignTest Class Reference

List of all members.

Public Member Functions

def test_simple_clustal
def test_simple_clustal_strict
def test_long
def test_using_stdin
def test_with_multiple_output_formats

Detailed Description

Simple MUSCLE tests
#FASTA output seems broken on Muscle 3.6 (on the Mac).
def test_simple_fasta(self):
    input_file = "Fasta/f002"
    self.assertTrue(os.path.isfile(input_file))
    records = list(SeqIO.parse(input_file,"fasta"))
    #Prepare the command...
    cmdline = MuscleCommandline(muscle_exe)
    cmdline.set_parameter("in", input_file)
    #Preserve input record order (makes checking output easier)
    cmdline.set_parameter("stable")
    #Set some others options just to test them
    cmdline.set_parameter("maxiters", 2)
    self.assertEqual(str(cmdline).rstrip(), "muscle -in Fasta/f002 -maxiters 2 -stable")
    result, out_handle, err_handle = generic_run(cmdline)
    #NOTE: generic_run has been removed from Biopython
    print err_handle.read()
    print out_handle.read()
    align = AlignIO.read(out_handle, "fasta")
    self.assertEqual(len(records),len(align))
    for old, new in zip(records, align):
        self.assertEqual(old.id, new.id)
        self.assertEqual(str(new.seq).replace("-",""), str(old.seq))

Definition at line 150 of file test_Muscle_tool.py.


Member Function Documentation

Simple muscle call using long file

Definition at line 241 of file test_Muscle_tool.py.

00241 
00242     def test_long(self):
00243         """Simple muscle call using long file"""
00244         #Create a large input file by converting some of another example file
00245         temp_large_fasta_file = "temp_cw_prot.fasta"
00246         records = list(SeqIO.parse("NBRF/Cw_prot.pir", "pir"))[:40]
00247         SeqIO.write(records, temp_large_fasta_file, "fasta")
00248         #Prepare the command...
00249         cmdline = MuscleCommandline(muscle_exe)
00250         cmdline.set_parameter("in", temp_large_fasta_file)
00251         #Use fast options
00252         cmdline.set_parameter("maxiters", 1)
00253         cmdline.set_parameter("diags", True) #Default None treated as False!
00254         #Use clustal output
00255         cmdline.set_parameter("clwstrict", True) #Default None treated as False!
00256         #Shoudn't need this, but just to make sure it is accepted
00257         cmdline.set_parameter("maxhours", 0.1)
00258         #No progress reports to stderr
00259         cmdline.set_parameter("quiet", True) #Default None treated as False!
00260         self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
00261                          " -in temp_cw_prot.fasta -diags -maxhours 0.1" + \
00262                          " -maxiters 1 -clwstrict -quiet")
00263         self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
00264         child = subprocess.Popen(str(cmdline),
00265                                  stdout=subprocess.PIPE,
00266                                  stderr=subprocess.PIPE,
00267                                  universal_newlines=True,
00268                                  shell=(sys.platform!="win32"))
00269         align = AlignIO.read(child.stdout, "clustal")
00270         align.sort()
00271         records.sort(key = lambda rec: rec.id)
00272         self.assertEqual(len(records), len(align))
00273         for old, new in zip(records, align):
00274             self.assertEqual(old.id, new.id)
00275             self.assertEqual(str(new.seq).replace("-",""), str(old.seq))
00276         os.remove(temp_large_fasta_file)
00277         #See if quiet worked:
00278         self.assertEqual("", child.stderr.read().strip())
00279         return_code = child.wait()
00280         self.assertEqual(return_code, 0)
00281         child.stdout.close()
00282         child.stderr.close()
00283         del child

Simple muscle call using Clustal output with a MUSCLE header

Definition at line 178 of file test_Muscle_tool.py.

00178 
00179     def test_simple_clustal(self):
00180         """Simple muscle call using Clustal output with a MUSCLE header"""
00181         input_file = "Fasta/f002"
00182         self.assertTrue(os.path.isfile(input_file))
00183         records = list(SeqIO.parse(input_file,"fasta"))
00184         records.sort(key = lambda rec: rec.id)
00185         #Prepare the command... use Clustal output (with a MUSCLE header)
00186         cmdline = MuscleCommandline(muscle_exe, input=input_file, clw = True)
00187         self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
00188                          " -in Fasta/f002 -clw")
00189         self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
00190         child = subprocess.Popen(str(cmdline),
00191                                  stdout=subprocess.PIPE,
00192                                  stderr=subprocess.PIPE,
00193                                  universal_newlines=True,
00194                                  shell=(sys.platform!="win32"))
00195         #Didn't use -quiet so there should be progress reports on stderr,
00196         align = AlignIO.read(child.stdout, "clustal")
00197         align.sort() #by record.id
00198         self.assertTrue(child.stderr.read().strip().startswith("MUSCLE"))
00199         return_code = child.wait()
00200         self.assertEqual(return_code, 0)
00201         child.stdout.close()
00202         child.stderr.close()
00203         del child
00204         self.assertEqual(len(records),len(align))
00205         for old, new in zip(records, align):
00206             self.assertEqual(old.id, new.id)
00207             self.assertEqual(str(new.seq).replace("-",""), str(old.seq))

Simple muscle call using strict Clustal output

Definition at line 208 of file test_Muscle_tool.py.

00208 
00209     def test_simple_clustal_strict(self):
00210         """Simple muscle call using strict Clustal output"""
00211         input_file = "Fasta/f002"
00212         self.assertTrue(os.path.isfile(input_file))
00213         records = list(SeqIO.parse(input_file,"fasta"))
00214         records.sort(key = lambda rec: rec.id)
00215         #Prepare the command...
00216         cmdline = MuscleCommandline(muscle_exe)
00217         cmdline.set_parameter("in", input_file)
00218         #Use clustal output (with a CLUSTAL header)
00219         cmdline.set_parameter("clwstrict", True) #Default None treated as False!
00220         self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
00221                          " -in Fasta/f002 -clwstrict")
00222         self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
00223         child = subprocess.Popen(str(cmdline),
00224                                  stdout=subprocess.PIPE,
00225                                  stderr=subprocess.PIPE,
00226                                  universal_newlines=True,
00227                                  shell=(sys.platform!="win32"))
00228         #Didn't use -quiet so there should be progress reports on stderr,
00229         align = AlignIO.read(child.stdout, "clustal")
00230         align.sort()
00231         self.assertTrue(child.stderr.read().strip().startswith("MUSCLE"))
00232         self.assertEqual(len(records),len(align))
00233         for old, new in zip(records, align):
00234             self.assertEqual(old.id, new.id)
00235             self.assertEqual(str(new.seq).replace("-",""), str(old.seq))
00236         return_code = child.wait()
00237         self.assertEqual(return_code, 0)
00238         child.stdout.close()
00239         child.stderr.close()
00240         del child

Simple alignment using stdin

Definition at line 284 of file test_Muscle_tool.py.

00284 
00285     def test_using_stdin(self):
00286         """Simple alignment using stdin"""
00287         input_file = "Fasta/f002"
00288         self.assertTrue(os.path.isfile(input_file))
00289         records = list(SeqIO.parse(input_file,"fasta"))
00290         #Prepare the command... use Clustal output (with a MUSCLE header)
00291         cline = MuscleCommandline(muscle_exe, clw=True)
00292         self.assertEqual(str(cline).rstrip(), muscle_exe + " -clw")
00293         self.assertEqual(str(eval(repr(cline))), str(cline))
00294         child = subprocess.Popen(str(cline),
00295                                  stdin=subprocess.PIPE,
00296                                  stdout=subprocess.PIPE,
00297                                  stderr=subprocess.PIPE,
00298                                  universal_newlines=True,
00299                                  shell=(sys.platform!="win32"))
00300         SeqIO.write(records, child.stdin, "fasta")
00301         child.stdin.close()
00302         #Alignment will now run...
00303         align = AlignIO.read(child.stdout, "clustal")
00304         align.sort()
00305         records.sort(key = lambda rec: rec.id)
00306         self.assertEqual(len(records),len(align))
00307         for old, new in zip(records, align):
00308             self.assertEqual(old.id, new.id)
00309             self.assertEqual(str(new.seq).replace("-",""), str(old.seq))
00310         self.assertEqual(0, child.wait())
00311         child.stdout.close()
00312         child.stderr.close()
00313         del child

Simple muscle call with multiple output formats

Definition at line 314 of file test_Muscle_tool.py.

00314 
00315     def test_with_multiple_output_formats(self):
00316         """Simple muscle call with multiple output formats"""
00317         input_file = "Fasta/f002"
00318         output_html = "temp_f002.html"
00319         output_clwstrict = "temp_f002.clw"
00320         self.assertTrue(os.path.isfile(input_file))
00321         records = list(SeqIO.parse(input_file,"fasta"))
00322         records.sort(key = lambda rec: rec.id)
00323         #Prepare the command... use Clustal output (with a MUSCLE header)
00324         cmdline = MuscleCommandline(muscle_exe, input=input_file,
00325                                     clw=True, htmlout = output_html,
00326                                     clwstrictout = output_clwstrict)
00327         self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
00328                          " -in Fasta/f002 -clw -htmlout temp_f002.html" +\
00329                          " -clwstrictout temp_f002.clw")
00330         self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
00331         child = subprocess.Popen(str(cmdline),
00332                                  stdout=subprocess.PIPE,
00333                                  stderr=subprocess.PIPE,
00334                                  universal_newlines=True,
00335                                  shell=(sys.platform!="win32"))
00336         #Clustalw on stdout:
00337         align = AlignIO.read(child.stdout, "clustal")
00338         align.sort()
00339         #Didn't use -quiet so there should be progress reports on stderr,
00340         self.assertTrue(child.stderr.read().strip().startswith("MUSCLE"))
00341         return_code = child.wait()
00342         self.assertEqual(return_code, 0)
00343         self.assertEqual(len(records),len(align))
00344         for old, new in zip(records, align):
00345             self.assertEqual(old.id, new.id)
00346         child.stdout.close()
00347         child.stderr.close()
00348         del child
00349         handle = open(output_html,"rU")
00350         html = handle.read().strip().upper()
00351         handle.close()
00352         self.assertTrue(html.startswith("<HTML"))
00353         self.assertTrue(html.endswith("</HTML>"))
00354         #ClustalW strict:
00355         align = AlignIO.read(output_clwstrict, "clustal")
00356         align.sort()
00357         self.assertEqual(len(records),len(align))
00358         for old, new in zip(records, align):
00359             self.assertEqual(old.id, new.id)
00360         os.remove(output_html)
00361         os.remove(output_clwstrict)

Here is the call graph for this function:


The documentation for this class was generated from the following file: