Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_PhyloXML.MethodTests Class Reference

List of all members.

Public Member Functions

def setUp
def test_clade_to_phylogeny
def test_phylogeny_to_phyloxml
def test_sequence_conversion
def test_to_alignment
def test_clade_getitem
def test_phyloxml_getitem
def test_events
def test_singlular
def test_color_hex

Public Attributes

 phyloxml

Detailed Description

Tests for methods on specific classes/objects.

Definition at line 600 of file test_PhyloXML.py.


Member Function Documentation

Definition at line 602 of file test_PhyloXML.py.

00602 
00603     def setUp(self):
00604         self.phyloxml = PhyloXMLIO.read(EX_PHYLO)

Clade.__getitem__: get sub-clades by extended indexing.

Definition at line 667 of file test_PhyloXML.py.

00667 
00668     def test_clade_getitem(self):
00669         """Clade.__getitem__: get sub-clades by extended indexing."""
00670         tree = self.phyloxml.phylogenies[3]
00671         self.assertEqual(tree.clade[0,0], tree.clade.clades[0].clades[0])
00672         self.assertEqual(tree.clade[0,1], tree.clade.clades[0].clades[1])
00673         self.assertEqual(tree.clade[1], tree.clade.clades[1])
00674         self.assertEqual(len(tree.clade[:]), len(tree.clade.clades))
00675         self.assertEqual(len(tree.clade[0,:]),
00676                          len(tree.clade.clades[0].clades))

Convert a Clade object to a new Phylogeny.

Definition at line 607 of file test_PhyloXML.py.

00607 
00608     def test_clade_to_phylogeny(self):
00609         """Convert a Clade object to a new Phylogeny."""
00610         clade = self.phyloxml.phylogenies[0].clade[0]
00611         tree = clade.to_phylogeny(rooted=True)
00612         self.assertTrue(isinstance(tree, PX.Phylogeny))

BranchColor: to_hex() method.

Definition at line 733 of file test_PhyloXML.py.

00733 
00734     def test_color_hex(self):
00735         """BranchColor: to_hex() method."""
00736         black = PX.BranchColor(0, 0, 0)
00737         self.assertEqual(black.to_hex(), '#000000')
00738         white = PX.BranchColor(255, 255, 255)
00739         self.assertEqual(white.to_hex(), '#ffffff')
00740         green = PX.BranchColor(14, 192, 113)
00741         self.assertEqual(green.to_hex(), '#0ec071')
00742 
00743 # ---------------------------------------------------------

Events: Mapping-type behavior.

Definition at line 683 of file test_PhyloXML.py.

00683 
00684     def test_events(self):
00685         """Events: Mapping-type behavior."""
00686         evts = self.phyloxml.phylogenies[4].clade.events
00687         # Container behavior: __len__, __contains__
00688         self.assertEqual(len(evts), 1)
00689         self.assertEqual('speciations' in evts, True)
00690         self.assertEqual('duplications' in evts, False)
00691         # Attribute access: __get/set/delitem__
00692         self.assertEqual(evts['speciations'], 1)
00693         self.assertRaises(KeyError, lambda k: evts[k], 'duplications')
00694         evts['duplications'] = 3
00695         self.assertEqual(evts.duplications, 3)
00696         self.assertEqual(len(evts), 2)
00697         del evts['speciations']
00698         self.assertEqual(evts.speciations, None)
00699         self.assertEqual(len(evts), 1)
00700         # Iteration: __iter__, keys, values, items
00701         self.assertEqual(list(iter(evts)), ['duplications'])
00702         self.assertEqual(list(evts.keys()), ['duplications'])
00703         self.assertEqual(list(evts.values()), [3])
00704         self.assertEqual(list(evts.items()), [('duplications', 3)])

Convert a Phylogeny object to a new Phyloxml.

Definition at line 613 of file test_PhyloXML.py.

00613 
00614     def test_phylogeny_to_phyloxml(self):
00615         """Convert a Phylogeny object to a new Phyloxml."""
00616         tree = self.phyloxml.phylogenies[0]
00617         doc = tree.to_phyloxml_container()
00618         self.assertTrue(isinstance(doc, PX.Phyloxml))

Phyloxml.__getitem__: get phylogenies by name or index.

Definition at line 677 of file test_PhyloXML.py.

00677 
00678     def test_phyloxml_getitem(self):
00679         """Phyloxml.__getitem__: get phylogenies by name or index."""
00680         self.assertTrue(self.phyloxml.phylogenies[9] is self.phyloxml[9])
00681         self.assertTrue(self.phyloxml['monitor lizards'] is self.phyloxml[9])
00682         self.assertEqual(len(self.phyloxml[:]), len(self.phyloxml))

Definition at line 619 of file test_PhyloXML.py.

00619 
00620     def test_sequence_conversion(self):
00621         pseq = PX.Sequence(
00622             type='protein',
00623             # id_ref=None,
00624             # id_source=None,
00625             symbol='ADHX',
00626             accession=PX.Accession('P81431', source='UniProtKB'),
00627             name='Alcohol dehydrogenase class-3',
00628             # location=None,
00629             mol_seq=PX.MolSeq(
00630                 'TDATGKPIKCMAAIAWEAKKPLSIEEVEVAPPKSGEVRIKILHSGVCHTD'),
00631             uri=None,
00632             annotations=[PX.Annotation(ref='EC:1.1.1.1'),
00633                          PX.Annotation(ref='GO:0004022')],
00634             domain_architecture=PX.DomainArchitecture(
00635                 length=50,
00636                 domains=[PX.ProteinDomain(*args) for args in (
00637                     # value,   start,   end,    confidence
00638                     ('FOO',     0,      5,      7.0e-26),
00639                     ('BAR',     8,      13,     7.2e-117),
00640                     ('A-OK',    21,     34,     2.4e-06),
00641                     ('WD40',    40,     50,     0.3))],
00642                 ))
00643         srec = pseq.to_seqrecord()
00644         # TODO: check seqrec-specific traits (see args)
00645         #   Seq(letters, alphabet), id, name, description, features
00646         pseq2 = PX.Sequence.from_seqrecord(srec)
00647         # TODO: check the round-tripped attributes again

Clade, Phylogeny: Singular properties for plural attributes.

Definition at line 705 of file test_PhyloXML.py.

00705 
00706     def test_singlular(self):
00707         """Clade, Phylogeny: Singular properties for plural attributes."""
00708         conf = PX.Confidence(0.9, 'bootstrap')
00709         taxo = PX.Taxonomy(rank='genus')
00710         # Clade.taxonomy, Clade.confidence
00711         clade = PX.Clade(confidences=[conf], taxonomies=[taxo])
00712         self.assertEqual(clade.confidence.type, 'bootstrap')
00713         self.assertEqual(clade.taxonomy.rank, 'genus')
00714         # raise if len > 1
00715         clade.confidences.append(conf)
00716         self.assertRaises(AttributeError, getattr, clade, 'confidence')
00717         clade.taxonomies.append(taxo)
00718         self.assertRaises(AttributeError, getattr, clade, 'taxonomy')
00719         # None if []
00720         clade.confidences = []
00721         self.assertEqual(clade.confidence, None)
00722         clade.taxonomies = []
00723         self.assertEqual(clade.taxonomy, None)
00724         # Phylogeny.confidence
00725         tree = PX.Phylogeny(True, confidences=[conf])
00726         self.assertEqual(tree.confidence.type, 'bootstrap')
00727         tree.confidences.append(conf)
00728         self.assertRaises(AttributeError, getattr, tree, 'confidence')
00729         tree.confidences = []
00730         self.assertEqual(tree.confidence, None)

Definition at line 648 of file test_PhyloXML.py.

00648 
00649     def test_to_alignment(self):
00650         tree = self.phyloxml.phylogenies[0]
00651         aln = tree.to_alignment()
00652         self.assertTrue(isinstance(aln, MultipleSeqAlignment))
00653         self.assertEqual(len(aln), 0)
00654         # Add sequences to the terminals
00655         alphabet = Alphabet.Gapped(Alphabet.generic_dna)
00656         for tip, seqstr in zip(tree.get_terminals(),
00657                 ('AA--TTA', 'AA--TTG', 'AACCTTC')):
00658             tip.sequences.append(PX.Sequence.from_seqrecord(
00659                 SeqRecord(Seq(seqstr, alphabet), id=str(tip))))
00660         # Check the alignment
00661         aln = tree.to_alignment()
00662         self.assertTrue(isinstance(aln, MultipleSeqAlignment))
00663         self.assertEqual(len(aln), 3)
00664         self.assertEqual(aln.get_alignment_length(), 7)


Member Data Documentation

Definition at line 603 of file test_PhyloXML.py.


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