Back to index

python-biopython  1.60
Public Member Functions
test_Emboss.PairwiseAlignmentTests Class Reference

List of all members.

Public Member Functions

def tearDown
def pairwise_alignment_check
def run_water
def test_water_file
def test_water_piped
def test_needle_file
def test_needle_piped
def test_water_file2
def test_water_file3
def test_water_file4
def test_needle_piped2
def test_water_needs_output
def test_needle_needs_output
def test_seqtmatchall_piped

Detailed Description

Run pairwise alignments with water and needle, and parse them.

Definition at line 421 of file test_Emboss.py.


Member Function Documentation

def test_Emboss.PairwiseAlignmentTests.pairwise_alignment_check (   self,
  query_seq,
  targets,
  alignments,
  local = True 
)
Check pairwise alignment data is sane.

Definition at line 429 of file test_Emboss.py.

00429 
00430                                  local=True):
00431         """Check pairwise alignment data is sane."""
00432         #The datasets should be small, so making iterators into lists is OK
00433         targets = list(targets)
00434         alignments = list(alignments)
00435         self.assertEqual(len(targets), len(alignments))
00436         for target, alignment in zip(targets, alignments):
00437             self.assertEqual(len(alignment), 2)
00438             #self.assertEqual(target.id, alignment[1].id) #too strict
00439             if alignment[1].id not in target.id \
00440             and alignment[1].id not in target.name:
00441                 raise AssertionError("%s vs %s or %s" \
00442                                      % (alignment[1].id , target.id, target.name))
00443             if local:
00444                 #Local alignment
00445                 self.assertTrue(str(alignment[0].seq).replace("-","") \
00446                              in query_seq)
00447                 self.assertTrue(str(alignment[1].seq).replace("-","").upper() \
00448                              in str(target.seq).upper())
00449             else:
00450                 #Global alignment
00451                 self.assertEqual(str(query_seq), str(alignment[0].seq).replace("-",""))
00452                 self.assertEqual(str(target.seq).upper(), \
00453                                  str(alignment[1].seq).replace("-","").upper())
00454         return True

Here is the caller graph for this function:

def test_Emboss.PairwiseAlignmentTests.run_water (   self,
  cline 
)

Definition at line 455 of file test_Emboss.py.

00455 
00456     def run_water(self, cline):
00457         #Run the tool,
00458         stdout, stderr = cline()
00459         self.assertTrue(stderr.strip().startswith("Smith-Waterman local alignment"),
00460                         stderr)
00461         if cline.outfile:
00462             self.assertEqual(stdout.strip(), "")
00463             self.assertTrue(os.path.isfile(cline.outfile))
00464         else :
00465             #Don't use this yet... could return stdout handle instead?
00466             return stdout

Here is the caller graph for this function:

Definition at line 424 of file test_Emboss.py.

00424 
00425     def tearDown(self):
00426         clean_up()
        

Here is the call graph for this function:

needle with the asis trick, output to a file.

Definition at line 520 of file test_Emboss.py.

00520 
00521     def test_needle_file(self):
00522         """needle with the asis trick, output to a file."""
00523         #Setup,
00524         cline = NeedleCommandline(cmd=exes["needle"])
00525         cline.set_parameter("-asequence", "asis:ACCCGGGCGCGGT")
00526         cline.set_parameter("-bsequence", "asis:ACCCGAGCGCGGT")
00527         cline.set_parameter("-gapopen", "10")
00528         cline.set_parameter("-gapextend", "0.5")
00529         #EMBOSS would guess this, but let's be explicit:
00530         cline.set_parameter("-snucleotide", "True")
00531         cline.set_parameter("-outfile", "Emboss/temp with space.needle")
00532         self.assertEqual(str(eval(repr(cline))), str(cline))
00533         #Run the tool,
00534         stdout, stderr = cline()
00535         #Check it worked,
00536         self.assertTrue(stderr.strip().startswith("Needleman-Wunsch global alignment"), stderr)
00537         self.assertEqual(stdout.strip(), "")
00538         filename = cline.outfile
00539         self.assertTrue(os.path.isfile(filename))
00540         #Check we can parse the output...
00541         align = AlignIO.read(filename,"emboss")
00542         self.assertEqual(len(align), 2)
00543         self.assertEqual(str(align[0].seq), "ACCCGGGCGCGGT")
00544         self.assertEqual(str(align[1].seq), "ACCCGAGCGCGGT")
00545         #Clean up,
00546         os.remove(filename)

needle without output file or stdout/filter should give error.

Definition at line 705 of file test_Emboss.py.

00705 
00706     def test_needle_needs_output(self):
00707         """needle without output file or stdout/filter should give error."""
00708         cline = NeedleCommandline(cmd=exes["needle"],
00709                                  asequence="asis:ACCCGGGCGCGGT",
00710                                  bsequence="asis:ACCCGAGCGCGGT",
00711                                  gapopen=10,
00712                                  gapextend=0.5,
00713                                  auto=True)
00714         self.assertTrue(cline.auto)
00715         self.assertTrue(not cline.stdout)
00716         self.assertTrue(not cline.filter)
00717         self.assertEqual(cline.outfile, None)
00718         self.assertRaises(ValueError, str, cline)
   
needle with asis trick, output piped to stdout.

Definition at line 547 of file test_Emboss.py.

00547 
00548     def test_needle_piped(self):
00549         """needle with asis trick, output piped to stdout."""
00550         cline = NeedleCommandline(cmd=exes["needle"],
00551                                  asequence="asis:ACCCGGGCGCGGT",
00552                                  bsequence="asis:ACCCGAGCGCGGT",
00553                                  gapopen=10,
00554                                  gapextend=0.5,
00555                                  auto=True, filter=True)
00556         self.assertEqual(str(cline),
00557                          exes["needle"] + " -auto -filter" \
00558                          + " -asequence=asis:ACCCGGGCGCGGT" \
00559                          + " -bsequence=asis:ACCCGAGCGCGGT" \
00560                          + " -gapopen=10 -gapextend=0.5")
00561         #Run the tool,
00562         child = subprocess.Popen(str(cline),
00563                                  stdin=subprocess.PIPE,
00564                                  stdout=subprocess.PIPE,
00565                                  stderr=subprocess.PIPE,
00566                                  universal_newlines=True,
00567                                  shell=(sys.platform!="win32"))
00568         child.stdin.close()
00569         #Check we could read it's output
00570         align = AlignIO.read(child.stdout, "emboss")
00571         self.assertEqual(len(align), 2)
00572         self.assertEqual(str(align[0].seq), "ACCCGGGCGCGGT")
00573         self.assertEqual(str(align[1].seq), "ACCCGAGCGCGGT")
00574         #Check no error output:
00575         self.assertEqual(child.stderr.read(), "")
00576         self.assertEqual(0, child.wait())
00577         child.stdout.close()
00578         child.stderr.close()

needle with asis trick, and nucleotide FASTA file, output piped to stdout.

Definition at line 661 of file test_Emboss.py.

00661 
00662     def test_needle_piped2(self):
00663         """needle with asis trick, and nucleotide FASTA file, output piped to stdout."""
00664         #TODO - Support needle in Bio.Emboss.Applications
00665         #(ideally with the -auto and -filter arguments)
00666         #Setup,
00667         query = "ACACACTCACACACACTTGGTCAGAGATGCTGTGCTTCTTGGAA"
00668         cline = exes["needle"]
00669         cline += " -asequence asis:" + query
00670         cline += " -bsequence Fasta/f002"
00671         cline += " -auto" #no prompting
00672         cline += " -filter" #use stdout
00673         #Run the tool,
00674         child = subprocess.Popen(str(cline),
00675                                  stdin=subprocess.PIPE,
00676                                  stdout=subprocess.PIPE,
00677                                  stderr=subprocess.PIPE,
00678                                  universal_newlines=True,
00679                                  shell=(sys.platform!="win32"))
00680         child.stdin.close()
00681         #Check we can parse the output and it is sensible...
00682         self.pairwise_alignment_check(query,
00683                                       SeqIO.parse("Fasta/f002","fasta"),
00684                                       AlignIO.parse(child.stdout,"emboss"),
00685                                       local=False)
00686         #Check no error output:
00687         self.assertEqual(child.stderr.read(), "")
00688         self.assertEqual(0, child.wait())
00689         child.stdout.close()
00690         child.stderr.close()

Here is the call graph for this function:

seqmatchall with pair output piped to stdout.

Definition at line 719 of file test_Emboss.py.

00719 
00720     def test_seqtmatchall_piped(self):
00721         """seqmatchall with pair output piped to stdout."""
00722         cline = SeqmatchallCommandline(cmd=exes["seqmatchall"],
00723                                        sequence="Fasta/f002",
00724                                        aformat="pair", wordsize=9,
00725                                        auto=True, stdout=True)
00726         self.assertEqual(str(cline),
00727                          exes["seqmatchall"] + " -auto -stdout" \
00728                          + " -sequence=Fasta/f002"
00729                          + " -wordsize=9 -aformat=pair")
00730         #Run the tool,
00731         child = subprocess.Popen(str(cline),
00732                                  stdin=subprocess.PIPE,
00733                                  stdout=subprocess.PIPE,
00734                                  stderr=subprocess.PIPE,
00735                                  universal_newlines=True,
00736                                  shell=(sys.platform!="win32"))
00737         child.stdin.close()
00738         #Check we could read it's output
00739         for align in AlignIO.parse(child.stdout, "emboss") :
00740             self.assertEqual(len(align), 2)
00741             self.assertEqual(align.get_alignment_length(), 9)
00742         #Check no error output:
00743         self.assertEqual(child.stderr.read(), "")
00744         self.assertEqual(0, child.wait())
00745         child.stdout.close()
00746         child.stderr.close()
00747         
#Top level function as this makes it easier to use for debugging:
water with the asis trick, output to a file.

Definition at line 467 of file test_Emboss.py.

00467 
00468     def test_water_file(self):
00469         """water with the asis trick, output to a file."""
00470         #Setup, try a mixture of keyword arguments and later additions:
00471         cline = WaterCommandline(cmd=exes["water"],
00472                                  gapopen="10", gapextend="0.5")
00473         #Try using both human readable names, and the literal ones:
00474         cline.set_parameter("asequence", "asis:ACCCGGGCGCGGT")
00475         cline.set_parameter("-bsequence", "asis:ACCCGAGCGCGGT")
00476         #Try using a property set here:
00477         cline.outfile = "Emboss/temp with space.water"
00478         self.assertEqual(str(eval(repr(cline))), str(cline))
00479         #Run the tool,
00480         self.run_water(cline)
00481         #Check we can parse the output...
00482         align = AlignIO.read(cline.outfile,"emboss")
00483         self.assertEqual(len(align), 2)
00484         self.assertEqual(str(align[0].seq), "ACCCGGGCGCGGT")
00485         self.assertEqual(str(align[1].seq), "ACCCGAGCGCGGT")
00486         #Clean up,
00487         os.remove(cline.outfile)            
        

Here is the call graph for this function:

water with the asis trick and nucleotide FASTA file, output to a file.

Definition at line 579 of file test_Emboss.py.

00579 
00580     def test_water_file2(self):
00581         """water with the asis trick and nucleotide FASTA file, output to a file."""
00582         #Setup,
00583         query = "ACACACTCACACACACTTGGTCAGAGATGCTGTGCTTCTTGGAAGCAAGGNCTCAAAGGCAAGGTGCACGCAGAGGGACGTTTGAGTCTGGGATGAAGCATGTNCGTATTATTTATATGATGGAATTTCACGTTTTTATG"
00584         out_file = "Emboss/temp_test2.water"
00585         in_file = "Fasta/f002"
00586         self.assertTrue(os.path.isfile(in_file))
00587         if os.path.isfile(out_file):
00588             os.remove(out_file)
00589         cline = WaterCommandline(cmd=exes["water"])
00590         cline.set_parameter("-asequence", "asis:%s" % query)
00591         cline.set_parameter("-bsequence", in_file)
00592         cline.set_parameter("-gapopen", "10")
00593         cline.set_parameter("-gapextend", "0.5")
00594         cline.set_parameter("-outfile", out_file)
00595         self.assertEqual(str(eval(repr(cline))), str(cline))
00596         #Run the tool,
00597         self.run_water(cline)
00598         #Check we can parse the output and it is sensible...
00599         self.pairwise_alignment_check(query,
00600                                       SeqIO.parse(in_file,"fasta"),
00601                                       AlignIO.parse(out_file,"emboss"),
00602                                       local=True)
00603         #Clean up,
00604         os.remove(out_file)

Here is the call graph for this function:

water with the asis trick and GenBank file, output to a file.

Definition at line 605 of file test_Emboss.py.

00605 
00606     def test_water_file3(self):
00607         """water with the asis trick and GenBank file, output to a file."""
00608         #Setup,
00609         query = "TGTTGTAATGTTTTAATGTTTCTTCTCCCTTTAGATGTACTACGTTTGGA"
00610         out_file = "Emboss/temp_test3.water"
00611         in_file = "GenBank/cor6_6.gb"
00612         self.assertTrue(os.path.isfile(in_file))
00613         if os.path.isfile(out_file):
00614             os.remove(out_file)
00615         cline = WaterCommandline(cmd=exes["water"])
00616         cline.set_parameter("asequence", "asis:%s" % query)
00617         cline.set_parameter("bsequence", in_file)
00618         #TODO - Tell water this is a GenBank file!
00619         cline.set_parameter("gapopen", "1")
00620         cline.set_parameter("gapextend", "0.5")
00621         cline.set_parameter("outfile", out_file)
00622         self.assertEqual(str(eval(repr(cline))), str(cline))
00623         #Run the tool,
00624         self.run_water(cline)
00625         #Check we can parse the output and it is sensible...
00626         self.pairwise_alignment_check(query,
00627                                       SeqIO.parse(in_file,"genbank"),
00628                                       AlignIO.parse(out_file,"emboss"),
00629                                       local=True)
00630         #Clean up,
00631         os.remove(out_file)

Here is the call graph for this function:

water with the asis trick and SwissProt file, output to a file.

Definition at line 632 of file test_Emboss.py.

00632 
00633     def test_water_file4(self):
00634         """water with the asis trick and SwissProt file, output to a file."""
00635         #Setup,
00636         query = "DVCTGKALCDPVTQNIKTYPVKIENLRVMI"
00637         out_file = "Emboss/temp_test4.water"
00638         in_file = "SwissProt/sp004"
00639         self.assertTrue(os.path.isfile(in_file))
00640         if os.path.isfile(out_file):
00641             os.remove(out_file)
00642         cline = WaterCommandline(cmd=exes["water"])
00643         cline.set_parameter("-asequence", "asis:%s" % query)
00644         cline.set_parameter("-bsequence", in_file)
00645         #EMBOSS should work this out, but let's be explicit:
00646         cline.set_parameter("-sprotein", True)
00647         #TODO - Tell water this is a SwissProt file!
00648         cline.set_parameter("-gapopen", "20")
00649         cline.set_parameter("-gapextend", "5")
00650         cline.set_parameter("-outfile", out_file)
00651         self.assertEqual(str(eval(repr(cline))), str(cline))
00652         #Run the tool,
00653         self.run_water(cline)
00654         #Check we can parse the output and it is sensible...
00655         self.pairwise_alignment_check(query,
00656                                       SeqIO.parse(in_file,"swiss"),
00657                                       AlignIO.parse(out_file,"emboss"),
00658                                       local=True)
00659         #Clean up,
00660         os.remove(out_file)
        

Here is the call graph for this function:

water without output file or stdout/filter should give error.

Definition at line 691 of file test_Emboss.py.

00691 
00692     def test_water_needs_output(self):
00693         """water without output file or stdout/filter should give error."""
00694         cline = WaterCommandline(cmd=exes["water"],
00695                                  asequence="asis:ACCCGGGCGCGGT",
00696                                  bsequence="asis:ACCCGAGCGCGGT",
00697                                  gapopen=10,
00698                                  gapextend=0.5,
00699                                  auto=True)
00700         self.assertTrue(cline.auto)
00701         self.assertTrue(not cline.stdout)
00702         self.assertTrue(not cline.filter)
00703         self.assertEqual(cline.outfile, None)
00704         self.assertRaises(ValueError, str, cline)

water with asis trick, output piped to stdout.

Definition at line 488 of file test_Emboss.py.

00488 
00489     def test_water_piped(self):
00490         """water with asis trick, output piped to stdout."""
00491         cline = WaterCommandline(cmd=exes["water"],
00492                                  asequence="asis:ACCCGGGCGCGGT",
00493                                  bsequence="asis:ACCCGAGCGCGGT",
00494                                  gapopen=10,
00495                                  gapextend=0.5,
00496                                  auto=True, filter=True)
00497         self.assertEqual(str(cline),
00498                          exes["water"] + " -auto -filter" \
00499                          + " -asequence=asis:ACCCGGGCGCGGT" \
00500                          + " -bsequence=asis:ACCCGAGCGCGGT" \
00501                          + " -gapopen=10 -gapextend=0.5")
00502         #Run the tool,
00503         child = subprocess.Popen(str(cline),
00504                                  stdin=subprocess.PIPE,
00505                                  stdout=subprocess.PIPE,
00506                                  stderr=subprocess.PIPE,
00507                                  universal_newlines=True,
00508                                  shell=(sys.platform!="win32"))
00509         child.stdin.close()
00510         #Check we could read it's output
00511         align = AlignIO.read(child.stdout, "emboss")
00512         self.assertEqual(len(align), 2)
00513         self.assertEqual(str(align[0].seq), "ACCCGGGCGCGGT")
00514         self.assertEqual(str(align[1].seq), "ACCCGAGCGCGGT")
00515         #Check no error output:
00516         self.assertEqual(child.stderr.read(), "")
00517         self.assertEqual(0, child.wait())
00518         child.stdout.close()
00519         child.stderr.close()


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