Back to index

python-biopython  1.60
Public Member Functions
test_PhyloXML.TreeTests Class Reference

List of all members.

Public Member Functions

def test_Phyloxml
def test_Other
def test_Phylogeny
def test_Clade
def test_Annotation
def test_BinaryCharacters
def test_CladeRelation
def test_Confidence
def test_Date
def test_Distribution
def test_DomainArchitecture
def test_Events
def test_Polygon
def test_Property
def test_Reference
def test_Sequence
def test_SequenceRelation
def test_Taxonomy
def test_Uri

Detailed Description

Tests for instantiation and attributes of each complex type.

Definition at line 162 of file test_PhyloXML.py.


Member Function Documentation

Instantiation of Annotation objects.

Definition at line 219 of file test_PhyloXML.py.

00219 
00220     def test_Annotation(self):
00221         """Instantiation of Annotation objects."""
00222         tree = list(PhyloXMLIO.parse(EX_PHYLO))[3]
00223         ann = tree.clade[1].sequences[0].annotations[0]
00224         self.assertTrue(isinstance(ann, PX.Annotation))
00225         self.assertEqual(ann.desc, 'alcohol dehydrogenase')
00226         self.assertAlmostEqual(ann.confidence.value, 0.67)
00227         self.assertEqual(ann.confidence.type, 'probability')

Instantiation of BinaryCharacters objects.

Definition at line 228 of file test_PhyloXML.py.

00228 
00229     def test_BinaryCharacters(self):
00230         """Instantiation of BinaryCharacters objects."""
00231         #Because we short circult interation, must close handle explicitly
00232         #to avoid a ResourceWarning
00233         handle = open(EX_DOLLO)
00234         tree = PhyloXMLIO.parse(handle).next()
00235         handle.close()
00236         bchars = tree.clade[0,0].binary_characters
00237         self.assertTrue(isinstance(bchars, PX.BinaryCharacters))
00238         self.assertEqual(bchars.type, 'parsimony inferred')
00239         for name, count, value in (
00240                 ('gained',  2, ['Cofilin_ADF', 'Gelsolin']),
00241                 ('lost',    0, []),
00242                 ('present', 2, ['Cofilin_ADF', 'Gelsolin']),
00243                 ('absent',  None, []),
00244                 ):
00245             self.assertEqual(getattr(bchars, name+'_count'), count)
00246             self.assertEqual(getattr(bchars, name), value)

Here is the call graph for this function:

Instantiation of Clade objects.

Definition at line 204 of file test_PhyloXML.py.

00204 
00205     def test_Clade(self):
00206         """Instantiation of Clade objects."""
00207         tree = list(PhyloXMLIO.parse(EX_PHYLO))[6]
00208         clade_ab, clade_c = tree.clade.clades
00209         clade_a, clade_b = clade_ab.clades
00210         for clade, id_source, name, blen in zip(
00211                 (clade_ab, clade_a, clade_b, clade_c),
00212                 ('ab', 'a', 'b', 'c'),
00213                 ('AB', 'A', 'B', 'C'),
00214                 (0.06, 0.102, 0.23, 0.4)):
00215             self.assertTrue(isinstance(clade, PX.Clade))
00216             self.assertEqual(clade.id_source, id_source)
00217             self.assertEqual(clade.name, name)
00218             self.assertAlmostEqual(clade.branch_length, blen)

Instantiation of CladeRelation objects.

Definition at line 249 of file test_PhyloXML.py.

00249 
00250     def test_CladeRelation(self):
00251         """Instantiation of CladeRelation objects."""
00252         tree = list(PhyloXMLIO.parse(EX_PHYLO))[6]
00253         crel = tree.clade_relations[0]
00254         self.assertTrue(isinstance(crel, PX.CladeRelation))
00255         self.assertEqual(crel.id_ref_0, 'b')
00256         self.assertEqual(crel.id_ref_1, 'c')
00257         self.assertEqual(crel.type, 'network_connection')

Instantiation of Confidence objects.

Definition at line 258 of file test_PhyloXML.py.

00258 
00259     def test_Confidence(self):
00260         """Instantiation of Confidence objects."""
00261         #Because we short circult interation, must close handle explicitly
00262         handle = open(EX_MADE)
00263         tree = PhyloXMLIO.parse(handle).next()
00264         handle.close()
00265         self.assertEqual(tree.name, 'testing confidence')
00266         for conf, type, val in zip(tree.confidences,
00267                 ('bootstrap', 'probability'),
00268                 (89.0, 0.71)):
00269             self.assertTrue(isinstance(conf, PX.Confidence))
00270             self.assertEqual(conf.type, type)
00271             self.assertAlmostEqual(conf.value, val)
00272         self.assertEqual(tree.clade.name, 'b')
00273         self.assertAlmostEqual(tree.clade.width, 0.2)
00274         for conf, val in zip(tree.clade[0].confidences,
00275                 (0.9, 0.71)):
00276             self.assertTrue(isinstance(conf, PX.Confidence))
00277             self.assertEqual(conf.type, 'probability')
00278             self.assertAlmostEqual(conf.value, val)

Here is the call graph for this function:

Instantiation of Date objects.

Definition at line 279 of file test_PhyloXML.py.

00279 
00280     def test_Date(self):
00281         """Instantiation of Date objects."""
00282         tree = list(PhyloXMLIO.parse(EX_PHYLO))[11]
00283         silurian = tree.clade[0,0].date
00284         devonian = tree.clade[0,1].date
00285         ediacaran = tree.clade[1].date
00286         for date, desc, val in zip(
00287                 (silurian, devonian, ediacaran),
00288                 # (10, 20, 30), # range is deprecated
00289                 ('Silurian', 'Devonian', 'Ediacaran'),
00290                 (425, 320, 600)):
00291             self.assertTrue(isinstance(date, PX.Date))
00292             self.assertEqual(date.unit, 'mya')
00293             # self.assertAlmostEqual(date.range, rang)
00294             self.assertEqual(date.desc, desc)
00295             self.assertAlmostEqual(date.value, val)

Instantiation of Distribution objects.

Also checks Point type and safe Unicode handling (?).

Definition at line 296 of file test_PhyloXML.py.

00296 
00297     def test_Distribution(self):
00298         """Instantiation of Distribution objects.
00299 
00300         Also checks Point type and safe Unicode handling (?).
00301         """
00302         tree = list(PhyloXMLIO.parse(EX_PHYLO))[10]
00303         hirschweg = tree.clade[0,0].distributions[0]
00304         nagoya = tree.clade[0,1].distributions[0]
00305         eth_zurich = tree.clade[0,2].distributions[0]
00306         san_diego = tree.clade[1].distributions[0]
00307         for dist, desc, lati, longi, alti in zip(
00308                 (hirschweg, nagoya, eth_zurich, san_diego),
00309                 ('Hirschweg, Winterthur, Switzerland',
00310                     'Nagoya, Aichi, Japan',
00311                     u'ETH Z\xfcrich',
00312                     'San Diego'),
00313                 (47.481277, 35.155904, 47.376334, 32.880933),
00314                 (8.769303, 136.915863, 8.548108, -117.217543),
00315                 (472, 10, 452, 104)):
00316             self.assertTrue(isinstance(dist, PX.Distribution))
00317             self.assertEqual(dist.desc, desc)
00318             point = dist.points[0]
00319             self.assertTrue(isinstance(point, PX.Point))
00320             self.assertEqual(point.geodetic_datum, 'WGS84')
00321             self.assertEqual(point.lat, lati)
00322             self.assertEqual(point.long, longi)
00323             self.assertEqual(point.alt, alti)

Instantiation of DomainArchitecture objects.

Also checks ProteinDomain type.

Definition at line 324 of file test_PhyloXML.py.

00324 
00325     def test_DomainArchitecture(self):
00326         """Instantiation of DomainArchitecture objects.
00327 
00328         Also checks ProteinDomain type.
00329         """
00330         #Because we short circult interation, must close handle explicitly
00331         handle = open(EX_APAF)
00332         tree = PhyloXMLIO.parse(handle).next()
00333         handle.close()
00334         clade = tree.clade[0,0,0,0,0,0,0,0,0,0]
00335         darch = clade.sequences[0].domain_architecture
00336         self.assertTrue(isinstance(darch, PX.DomainArchitecture))
00337         self.assertEqual(darch.length, 1249)
00338         for domain, start, end, conf, value in zip(darch.domains,
00339                 (6, 109, 605, 647, 689, 733, 872, 993, 1075, 1117, 1168),
00340                 (90, 414, 643, 685, 729, 771, 910, 1031, 1113, 1155, 1204),
00341                 (7.0e-26, 7.2e-117, 2.4e-6, 1.1e-12, 2.4e-7, 4.7e-14, 2.5e-8,
00342                     4.6e-6, 6.3e-7, 1.4e-7, 0.3),
00343                 ('CARD', 'NB-ARC', 'WD40', 'WD40', 'WD40', 'WD40', 'WD40',
00344                     'WD40', 'WD40', 'WD40', 'WD40')):
00345             self.assertTrue(isinstance(domain, PX.ProteinDomain))
00346             self.assertEqual(domain.start + 1, start)
00347             self.assertEqual(domain.end, end)
00348             self.assertAlmostEqual(domain.confidence, conf)
00349             self.assertEqual(domain.value, value)

Here is the call graph for this function:

Instantiation of Events objects.

Definition at line 350 of file test_PhyloXML.py.

00350 
00351     def test_Events(self):
00352         """Instantiation of Events objects."""
00353         tree = list(PhyloXMLIO.parse(EX_PHYLO))[4]
00354         event_s = tree.clade.events
00355         self.assertTrue(isinstance(event_s, PX.Events))
00356         self.assertEqual(event_s.speciations, 1)
00357         event_d = tree.clade[0].events
00358         self.assertTrue(isinstance(event_d, PX.Events))
00359         self.assertEqual(event_d.duplications, 1)

Instantiation of Other objects.

Definition at line 175 of file test_PhyloXML.py.

00175 
00176     def test_Other(self):
00177         """Instantiation of Other objects."""
00178         phx = PhyloXMLIO.read(EX_PHYLO)
00179         otr = phx.other[0]
00180         self.assertTrue(isinstance(otr, PX.Other))
00181         self.assertEqual(otr.tag, 'alignment')
00182         self.assertEqual(otr.namespace, 'http://example.org/align')
00183         self.assertEqual(len(otr.children), 3)
00184         for child, name, value in zip(otr, ('A', 'B', 'C'), (
00185             'acgtcgcggcccgtggaagtcctctcct', 'aggtcgcggcctgtggaagtcctctcct',
00186             'taaatcgc--cccgtgg-agtccc-cct')):
00187             self.assertEqual(child.tag, 'seq')
00188             self.assertEqual(child.attributes['name'], name)
00189             self.assertEqual(child.value, value)

Instantiation of Phylogeny objects.

Definition at line 190 of file test_PhyloXML.py.

00190 
00191     def test_Phylogeny(self):
00192         """Instantiation of Phylogeny objects."""
00193         trees = list(PhyloXMLIO.parse(EX_PHYLO))
00194         # Monitor lizards
00195         self.assertEqual(trees[9].name, 'monitor lizards')
00196         self.assertEqual(trees[9].description,
00197                 'a pylogeny of some monitor lizards')
00198         self.assertEqual(trees[9].rooted, True)
00199         # Network (unrooted)
00200         tree6 = trees[6]
00201         self.assertEqual(trees[6].name,
00202                 'network, node B is connected to TWO nodes: AB and C')
00203         self.assertEqual(trees[6].rooted, False)

Instantiation of Phyloxml objects.

Definition at line 166 of file test_PhyloXML.py.

00166 
00167     def test_Phyloxml(self):
00168         """Instantiation of Phyloxml objects."""
00169         phx = PhyloXMLIO.read(EX_PHYLO)
00170         self.assertTrue(isinstance(phx, PX.Phyloxml))
00171         for tree in phx:
00172             self.assertTrue(isinstance(tree, PX.Phylogeny))
00173         for otr in phx.other:
00174             self.assertTrue(isinstance(otr, PX.Other))

Instantiation of Polygon objects.

Definition at line 360 of file test_PhyloXML.py.

00360 
00361     def test_Polygon(self):
00362         """Instantiation of Polygon objects."""
00363         tree = PhyloXMLIO.read(EX_MADE).phylogenies[1]
00364         self.assertEqual(tree.name, 'testing polygon')
00365         dist = tree.clade[0].distributions[0]
00366         for poly in dist.polygons:
00367             self.assertTrue(isinstance(poly, PX.Polygon))
00368             self.assertEqual(len(poly.points), 3)
00369         self.assertEqual(dist.polygons[0].points[0].alt_unit, 'm')
00370         for point, lati, longi, alti in zip(
00371                 chain(dist.polygons[0].points, dist.polygons[1].points),
00372                 (47.481277, 35.155904, 47.376334, 40.481277, 25.155904,
00373                     47.376334),
00374                 (8.769303, 136.915863, 8.548108, 8.769303, 136.915863,
00375                     7.548108),
00376                 (472, 10, 452, 42, 10, 452),
00377                 ):
00378             self.assertTrue(isinstance(point, PX.Point))
00379             self.assertEqual(point.geodetic_datum, 'WGS84')
00380             self.assertEqual(point.lat, lati)
00381             self.assertEqual(point.long, longi)
00382             self.assertEqual(point.alt, alti)

Instantiation of Property objects.

Definition at line 383 of file test_PhyloXML.py.

00383 
00384     def test_Property(self):
00385         """Instantiation of Property objects."""
00386         tree = list(PhyloXMLIO.parse(EX_PHYLO))[8]
00387         for prop, id_ref, value in zip(
00388                 tree.properties,
00389                 ('id_a', 'id_b', 'id_c'),
00390                 ('1200', '2300', '200')):
00391             self.assertTrue(isinstance(prop, PX.Property))
00392             self.assertEqual(prop.id_ref, id_ref)
00393             self.assertEqual(prop.datatype, "xsd:integer")
00394             self.assertEqual(prop.ref, "NOAA:depth")
00395             self.assertEqual(prop.applies_to, "node")
00396             self.assertEqual(prop.unit, "METRIC:m" )
00397             self.assertEqual(prop.value, value)

Instantiation of Reference objects.

Definition at line 398 of file test_PhyloXML.py.

00398 
00399     def test_Reference(self):
00400         """Instantiation of Reference objects."""
00401         #Because we short circult interation, must close handle explicitly
00402         #to avoid a ResourceWarning
00403         handle = open(EX_DOLLO)
00404         tree = PhyloXMLIO.parse(handle).next()
00405         handle.close()
00406         reference = tree.clade[0,0,0,0,0,0].references[0]
00407         self.assertTrue(isinstance(reference, PX.Reference))
00408         self.assertEqual(reference.doi, '10.1038/nature06614')
00409         self.assertEqual(reference.desc, None)

Here is the call graph for this function:

Instantiation of Sequence objects.

Also checks Accession and Annotation types.

Definition at line 410 of file test_PhyloXML.py.

00410 
00411     def test_Sequence(self):
00412         """Instantiation of Sequence objects.
00413 
00414         Also checks Accession and Annotation types.
00415         """
00416         trees = list(PhyloXMLIO.parse(EX_PHYLO))
00417         # Simple element with id_source
00418         seq0 = trees[4].clade[1].sequences[0]
00419         self.assertTrue(isinstance(seq0, PX.Sequence))
00420         self.assertEqual(seq0.id_source, 'z')
00421         self.assertEqual(seq0.symbol, 'ADHX')
00422         self.assertEqual(seq0.accession.source, 'ncbi')
00423         self.assertEqual(seq0.accession.value, 'Q17335')
00424         self.assertEqual(seq0.name, 'alcohol dehydrogenase')
00425         self.assertEqual(seq0.annotations[0].ref, 'InterPro:IPR002085')
00426         # More complete elements
00427         seq1 = trees[5].clade[0,0].sequences[0]
00428         seq2 = trees[5].clade[0,1].sequences[0]
00429         seq3 = trees[5].clade[1].sequences[0]
00430         for seq, sym, acc, name, mol_seq, ann_refs in zip(
00431                 (seq1, seq2, seq3),
00432                 ('ADHX', 'RT4I1', 'ADHB'),
00433                 ('P81431', 'Q54II4', 'Q04945'),
00434                 ('Alcohol dehydrogenase class-3',
00435                  'Reticulon-4-interacting protein 1 homolog, ' \
00436                          'mitochondrial precursor',
00437                  'NADH-dependent butanol dehydrogenase B'),
00438                 ('TDATGKPIKCMAAIAWEAKKPLSIEEVEVAPPKSGEVRIKILHSGVCHTD',
00439                  'MKGILLNGYGESLDLLEYKTDLPVPKPIKSQVLIKIHSTSINPLDNVMRK',
00440                  'MVDFEYSIPTRIFFGKDKINVLGRELKKYGSKVLIVYGGGSIKRNGIYDK'),
00441                 (("EC:1.1.1.1", "GO:0004022"),
00442                  ("GO:0008270", "GO:0016491"),
00443                  ("GO:0046872", "KEGG:Tetrachloroethene degradation")),
00444                 ):
00445             self.assertTrue(isinstance(seq, PX.Sequence))
00446             self.assertEqual(seq.symbol, sym)
00447             self.assertEqual(seq.accession.source, 'UniProtKB')
00448             self.assertEqual(seq.accession.value, acc)
00449             self.assertEqual(seq.name, name)
00450             self.assertEqual(seq.mol_seq.value, mol_seq)
00451             self.assertEqual(seq.annotations[0].ref, ann_refs[0])
00452             self.assertEqual(seq.annotations[1].ref, ann_refs[1])

Instantiation of SequenceRelation objects.

Definition at line 453 of file test_PhyloXML.py.

00453 
00454     def test_SequenceRelation(self):
00455         """Instantiation of SequenceRelation objects."""
00456         tree = list(PhyloXMLIO.parse(EX_PHYLO))[4]
00457         for seqrel, id_ref_0, id_ref_1, type in zip(
00458                 tree.sequence_relations,
00459                 ('x', 'x', 'y'), ('y', 'z', 'z'),
00460                 ('paralogy', 'orthology', 'orthology')):
00461             self.assertTrue(isinstance(seqrel, PX.SequenceRelation))
00462             self.assertEqual(seqrel.id_ref_0, id_ref_0)
00463             self.assertEqual(seqrel.id_ref_1, id_ref_1)
00464             self.assertEqual(seqrel.type, type)

Instantiation of Taxonomy objects.

Also checks Id type.

Definition at line 465 of file test_PhyloXML.py.

00465 
00466     def test_Taxonomy(self):
00467         """Instantiation of Taxonomy objects.
00468 
00469         Also checks Id type.
00470         """
00471         trees = list(PhyloXMLIO.parse(EX_PHYLO))
00472         # Octopus
00473         tax5 = trees[5].clade[0,0].taxonomies[0]
00474         self.assertTrue(isinstance(tax5, PX.Taxonomy))
00475         self.assertEqual(tax5.id.value, '6645')
00476         self.assertEqual(tax5.id.provider, 'NCBI')
00477         self.assertEqual(tax5.code, 'OCTVU')
00478         self.assertEqual(tax5.scientific_name, 'Octopus vulgaris')
00479         # Nile monitor
00480         tax9 = trees[9].clade[0].taxonomies[0]
00481         self.assertTrue(isinstance(tax9, PX.Taxonomy))
00482         self.assertEqual(tax9.id.value, '62046')
00483         self.assertEqual(tax9.id.provider, 'NCBI')
00484         self.assertEqual(tax9.scientific_name, 'Varanus niloticus')
00485         self.assertEqual(tax9.common_names[0], 'Nile monitor')
00486         self.assertEqual(tax9.rank, 'species')

Instantiation of Uri objects.

Definition at line 487 of file test_PhyloXML.py.

00487 
00488     def test_Uri(self):
00489         """Instantiation of Uri objects."""
00490         tree = list(PhyloXMLIO.parse(EX_PHYLO))[9]
00491         uri = tree.clade.taxonomies[0].uri
00492         self.assertTrue(isinstance(uri, PX.Uri))
00493         self.assertEqual(uri.desc, 'EMBL REPTILE DATABASE')
00494         self.assertEqual(uri.value,
00495                 'http://www.embl-heidelberg.de/~uetz/families/Varanidae.html')
00496 
00497 
00498 # ---------------------------------------------------------
00499 # Serialization tests


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