Ejemplo n.º 1
0
 def test_simple_clustal_strict(self):
     """Simple muscle call using strict Clustal output"""
     input_file = "Fasta/f002"
     self.assertTrue(os.path.isfile(input_file))
     records = list(SeqIO.parse(input_file,"fasta"))
     records.sort(key = lambda rec: rec.id)
     #Prepare the command...
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("in", input_file)
     #Use clustal output (with a CLUSTAL header)
     cmdline.set_parameter("clwstrict", True)  # Default None treated as False!
     self.assertEqual(str(cmdline).rstrip(), _escape_filename(muscle_exe) +
                      " -in Fasta/f002 -clwstrict")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(str(cmdline),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              universal_newlines=True,
                              shell=(sys.platform!="win32"))
     #Didn't use -quiet so there should be progress reports on stderr,
     align = AlignIO.read(child.stdout, "clustal")
     align.sort()
     self.assertTrue(child.stderr.read().strip().startswith("MUSCLE"))
     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))
     return_code = child.wait()
     self.assertEqual(return_code, 0)
     child.stdout.close()
     child.stderr.close()
     del child
Ejemplo n.º 2
0
 def test_simple_clustal_strict(self):
     """Simple muscle call using strict Clustal output"""
     input_file = "Fasta/f002"
     self.assertTrue(os.path.isfile(input_file))
     records = list(SeqIO.parse(input_file, "fasta"))
     records.sort(key=lambda rec: rec.id)
     #Prepare the command...
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("in", input_file)
     #Use clustal output (with a CLUSTAL header)
     cmdline.set_parameter("clwstrict",
                           True)  # Default None treated as False!
     self.assertEqual(
         str(cmdline).rstrip(),
         _escape_filename(muscle_exe) + " -in Fasta/f002 -clwstrict")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(str(cmdline),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              universal_newlines=True,
                              shell=(sys.platform != "win32"))
     #Didn't use -quiet so there should be progress reports on stderr,
     align = AlignIO.read(child.stdout, "clustal")
     align.sort()
     self.assertTrue(child.stderr.read().strip().startswith("MUSCLE"))
     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))
     return_code = child.wait()
     self.assertEqual(return_code, 0)
     child.stdout.close()
     child.stderr.close()
     del child
Ejemplo n.º 3
0
 def test_long(self):
     """Simple muscle call using long file."""
     # Create a large input file by converting some of another example file
     temp_large_fasta_file = "temp_cw_prot.fasta"
     records = list(SeqIO.parse("NBRF/Cw_prot.pir", "pir"))[:40]
     SeqIO.write(records, temp_large_fasta_file, "fasta")
     # Prepare the command...
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("in", temp_large_fasta_file)
     # Use fast options
     cmdline.set_parameter("maxiters", 1)
     cmdline.set_parameter("diags", True)  # Default None treated as False!
     # Use clustal output
     cmdline.set_parameter("clwstrict",
                           True)  # Default None treated as False!
     # Shoudn't need this, but just to make sure it is accepted
     cmdline.set_parameter("maxhours", 0.1)
     # No progress reports to stderr
     cmdline.set_parameter("quiet", True)  # Default None treated as False!
     self.assertEqual(
         str(cmdline).rstrip(),
         _escape_filename(muscle_exe) +
         " -in temp_cw_prot.fasta -diags -maxhours 0.1" +
         " -maxiters 1 -clwstrict -quiet",
     )
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(
         str(cmdline),
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
         universal_newlines=True,
         shell=(sys.platform != "win32"),
     )
     align = AlignIO.read(child.stdout, "clustal")
     align.sort()
     records.sort(key=lambda rec: rec.id)  # noqa: E731
     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))
     # See if quiet worked:
     self.assertEqual("", child.stderr.read().strip())
     return_code = child.wait()
     self.assertEqual(return_code, 0)
     child.stdout.close()
     child.stderr.close()
     del child
     os.remove(temp_large_fasta_file)
Ejemplo n.º 4
0
 def test_Muscle_with_options(self):
     """Round-trip through app with a switch and valued option"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("input", self.infile1)  # "input" is alias for "in"
     cmdline.set_parameter("out", self.outfile2)
     #Use property:
     cmdline.objscore = "sp"
     cmdline.noanchors = True
     self.assertEqual(str(cmdline), _escape_filename(muscle_exe) +
                      " -in Fasta/f002" +
                      " -out Fasta/temp_align_out2.fa" +
                      " -objscore sp -noanchors")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     output, error = cmdline()
     self.assertEqual(output, "")
     self.assertTrue("ERROR" not in error)
     self.assertTrue(error.strip().startswith("MUSCLE"), output)
Ejemplo n.º 5
0
 def test_Muscle_with_options(self):
     """Round-trip through app with a switch and valued option"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("input",
                           self.infile1)  #"input" is alias for "in"
     cmdline.set_parameter("out", self.outfile2)
     #Use property:
     cmdline.objscore = "sp"
     cmdline.noanchors = True
     self.assertEqual(
         str(cmdline), muscle_exe + " -in Fasta/f002" +
         " -out Fasta/temp_align_out2.fa" + " -objscore sp -noanchors")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     output, error = cmdline()
     self.assertEqual(output, "")
     self.assertTrue("ERROR" not in error)
     self.assertTrue(error.strip().startswith("MUSCLE"), output)
Ejemplo n.º 6
0
 def test_Muscle_with_options(self):
     """Round-trip through app with a switch and valued option."""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("input", self.infile1) #"input" is alias for "in"
     cmdline.set_parameter("out", self.outfile2)
     #Use property:
     cmdline.objscore = "sp"
     cmdline.noanchors = True
     self.assertEqual(str(cmdline), muscle_exe +\
                      " -in Fasta/f002" + \
                      " -out Fasta/temp_align_out2.fa" + \
                      " -objscore sp -noanchors")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     stdin, stdout, stderr = generic_run(cmdline)
     self.assertEqual(stdin.return_code, 0)
     self.assertEqual(stdout.read(), "")
     self.assert_("ERROR" not in stderr.read())
     self.assertEqual(str(stdin._cl), str(cmdline))
Ejemplo n.º 7
0
 def test_long(self):
     """Simple muscle call using long file"""
     #Create a large input file by converting some of another example file
     temp_large_fasta_file = "temp_cw_prot.fasta"
     records = list(SeqIO.parse("NBRF/Cw_prot.pir", "pir"))[:40]
     SeqIO.write(records, temp_large_fasta_file, "fasta")
     #Prepare the command...
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("in", temp_large_fasta_file)
     #Use fast options
     cmdline.set_parameter("maxiters", 1)
     cmdline.set_parameter("diags", True)  # Default None treated as False!
     #Use clustal output
     cmdline.set_parameter("clwstrict", True)  # Default None treated as False!
     #Shoudn't need this, but just to make sure it is accepted
     cmdline.set_parameter("maxhours", 0.1)
     #No progress reports to stderr
     cmdline.set_parameter("quiet", True)  # Default None treated as False!
     self.assertEqual(str(cmdline).rstrip(), _escape_filename(muscle_exe) +
                      " -in temp_cw_prot.fasta -diags -maxhours 0.1" +
                      " -maxiters 1 -clwstrict -quiet")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(str(cmdline),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              universal_newlines=True,
                              shell=(sys.platform!="win32"))
     align = AlignIO.read(child.stdout, "clustal")
     align.sort()
     records.sort(key = lambda rec: rec.id)
     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))
     #See if quiet worked:
     self.assertEqual("", child.stderr.read().strip())
     return_code = child.wait()
     self.assertEqual(return_code, 0)
     child.stdout.close()
     child.stderr.close()
     del child
     os.remove(temp_large_fasta_file)
Ejemplo n.º 8
0
 def test_Muscle_with_options(self):
     """Round-trip through app with a switch and valued option"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("input", self.infile1) #"input" is alias for "in"
     cmdline.set_parameter("out", self.outfile2)
     #Use property:
     cmdline.objscore = "sp"
     cmdline.noanchors = True
     self.assertEqual(str(cmdline), muscle_exe +\
                      " -in Fasta/f002" + \
                      " -out Fasta/temp_align_out2.fa" + \
                      " -objscore sp -noanchors")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(str(cmdline),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              shell=(sys.platform!="win32"))
     output, error = child.communicate()
     self.assertEqual(child.returncode, 0)
     self.assertEqual(output, "")
     self.assert_("ERROR" not in error)
     del child
Ejemplo n.º 9
0
 def test_Muscle_profile_simple(self):
     """Simple round-trip through app doing a profile alignment"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("out", self.outfile3)
     cmdline.set_parameter("profile", True)
     cmdline.set_parameter("in1", self.infile2)
     cmdline.set_parameter("in2", self.infile3)
     self.assertEqual(str(cmdline), _escape_filename(muscle_exe) +
                      " -out Fasta/temp_align_out3.fa" +
                      " -profile -in1 Fasta/fa01 -in2 Fasta/f001")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     output, error = cmdline()
     self.assertEqual(output, "")
     self.assertTrue("ERROR" not in error)
     self.assertTrue(error.strip().startswith("MUSCLE"), output)
Ejemplo n.º 10
0
 def test_Muscle_profile_simple(self):
     """Simple round-trip through app doing a profile alignment"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("out", self.outfile3)
     cmdline.set_parameter("profile", True)
     cmdline.set_parameter("in1", self.infile2)
     cmdline.set_parameter("in2", self.infile3)
     self.assertEqual(
         str(cmdline), muscle_exe + " -out Fasta/temp_align_out3.fa" +
         " -profile -in1 Fasta/fa01 -in2 Fasta/f001")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     output, error = cmdline()
     self.assertEqual(output, "")
     self.assertTrue("ERROR" not in error)
     self.assertTrue(error.strip().startswith("MUSCLE"), output)
Ejemplo n.º 11
0
 def test_Muscle_profile_simple(self):
     """Simple round-trip through app doing a profile alignment."""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("out", self.outfile3)
     cmdline.set_parameter("profile", True)
     cmdline.set_parameter("in1", self.infile2)
     cmdline.set_parameter("in2", self.infile3)
     self.assertEqual(str(cmdline), muscle_exe + \
                      " -out Fasta/temp_align_out3.fa" + \
                      " -profile -in1 Fasta/fa01 -in2 Fasta/f001")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     stdin, stdout, stderr = generic_run(cmdline)
     self.assertEqual(stdin.return_code, 0)
     self.assertEqual(stdout.read(), "")
     self.assert_("ERROR" not in stderr.read())
     self.assertEqual(str(stdin._cl), str(cmdline))
Ejemplo n.º 12
0
 def test_Muscle_profile_simple(self):
     """Simple round-trip through app doing a profile alignment"""
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("out", self.outfile3)
     cmdline.set_parameter("profile", True)
     cmdline.set_parameter("in1", self.infile2)
     cmdline.set_parameter("in2", self.infile3)
     self.assertEqual(str(cmdline), muscle_exe + \
                      " -out Fasta/temp_align_out3.fa" + \
                      " -profile -in1 Fasta/fa01 -in2 Fasta/f001")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     child = subprocess.Popen(str(cmdline),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              shell=(sys.platform!="win32"))
     output, error = child.communicate()
     self.assertEqual(child.returncode, 0)
     self.assertEqual(output, "")
     self.assert_("ERROR" not in error)
     del child
Ejemplo n.º 13
0
 def test_simple_clustal_strict(self):
     """Simple muscle call using strict Clustal output."""
     input_file = "Fasta/f002"
     self.assert_(os.path.isfile(input_file))
     records = list(SeqIO.parse(open(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", True) #Default None treated as False!
     #Use clustal output (with a CLUSTAL header)
     cmdline.set_parameter("clwstrict", True) #Default None treated as False!
     self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
                      " -in Fasta/f002 -clwstrict -stable")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     result, out_handle, err_handle = generic_run(cmdline)
     align = AlignIO.read(out_handle, "clustal")
     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))
     #Didn't use -quiet so there should be progress reports on stderr,
     self.assert_(err_handle.read().strip().startswith("MUSCLE"))
Ejemplo n.º 14
0
 def test_long(self) :
     """Simple muscle call using long file."""
     #Create a large input file by converting some of another example file
     temp_large_fasta_file = "temp_cw_prot.fasta"
     handle = open(temp_large_fasta_file, "w")
     records = list(SeqIO.parse(open("NBRF/Cw_prot.pir", "rU"), "pir"))[:40]
     SeqIO.write(records, handle, "fasta")
     handle.close()
     #Prepare the command...
     cmdline = MuscleCommandline(muscle_exe)
     cmdline.set_parameter("in", temp_large_fasta_file)
     #Preserve input record order
     cmdline.set_parameter("stable", True) #Default None treated as False!
     #Use fast options
     cmdline.set_parameter("maxiters", 1)
     cmdline.set_parameter("diags", True) #Default None treated as False!
     #Use clustal output
     cmdline.set_parameter("clwstrict", True) #Default None treated as False!
     #Shoudn't need this, but just to make sure it is accepted
     cmdline.set_parameter("maxhours", 0.1)
     #No progress reports to stderr
     cmdline.set_parameter("quiet", True) #Default None treated as False!
     #TODO - Fix the trailing space!
     self.assertEqual(str(cmdline).rstrip(), muscle_exe + \
                      " -in temp_cw_prot.fasta -diags -maxhours 0.1" + \
                      " -maxiters 1 -clwstrict -stable -quiet")
     self.assertEqual(str(eval(repr(cmdline))), str(cmdline))
     result, out_handle, err_handle = generic_run(cmdline)
     align = AlignIO.read(out_handle, "clustal")
     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))
     os.remove(temp_large_fasta_file)
     #See if quiet worked:
     self.assertEqual("", err_handle.read().strip())