def testCanConvert(self):
     inp = pathmap.nexson_obj('merge/merge-input.v1.2.json')
     expected = pathmap.nexson_obj('merge/merge-expected.v1.2.json')
     expected = sort_arbitrarily_ordered_nexson(expected)
     inp = sort_arbitrarily_ordered_nexson(inp)
     self.assertNotEqual(inp, expected)
     merge_otus_and_trees(inp)
     equal_blob_check(self, '', inp, expected)
 def testCanConvert(self):
     inp = pathmap.nexson_obj('merge/merge-input.v1.2.json')
     expected = pathmap.nexson_obj('merge/merge-expected.v1.2.json')
     expected = sort_arbitrarily_ordered_nexson(expected)
     inp = sort_arbitrarily_ordered_nexson(inp)
     self.assertNotEqual(inp, expected)
     merge_otus_and_trees(inp)
     equal_blob_check(self, '', inp, expected)
Example #3
0
def _get_pair(par, f, s):
    bf = os.path.join(par, f)
    hbf = os.path.join(par, s)
    fp, sp = pathmap.nexson_source_path(bf), pathmap.nexson_source_path(hbf)
    if not os.path.exists(fp):
        _LOG.warn('\nTest skipped because {s} does not exist'.format(s=fp))
        return None, None
    if not os.path.exists(sp):
        _LOG.warn('\nTest skipped because {s} does not exist'.format(s=sp))
        return None, None
    return pathmap.nexson_obj(bf), pathmap.nexson_obj(hbf)
Example #4
0
def _get_pair(par, f, s):
    bf = os.path.join(par, f)
    hbf = os.path.join(par, s)
    fp, sp = pathmap.nexson_source_path(bf), pathmap.nexson_source_path(hbf)
    if not os.path.exists(fp):
        _LOG.warn('\nTest skipped because {s} does not exist'.format(s=fp))
        return None, None
    if not os.path.exists(sp):
        _LOG.warn('\nTest skipped because {s} does not exist'.format(s=sp))
        return None, None
    return pathmap.nexson_obj(bf), pathmap.nexson_obj(hbf)
 def testSubTreesConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick',
                      content='subtree',
                      content_id=('tree3', 'node508'),
                      version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('('))  # pylint: disable=E1103
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick',
                      content='subtree',
                      content_id=('tree3', 'ingroup'),
                      version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('('))  # pylint: disable=E1103
Example #6
0
 def testSubTreesConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick',
                      content='subtree',
                      content_id=('tree3', 'node508'),
                      version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('('))  # pylint: disable=E1103
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick',
                      content='subtree',
                      content_id=('tree3', 'ingroup'),
                      version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('('))  # pylint: disable=E1103
Example #7
0
 def testNewickExport(self):
     n = pathmap.nexson_obj('10/pg_10.json')
     newick = extract_tree(
         n, 'tree3',
         PhyloSchema('newick',
                     tip_label='ot:ottTaxonName',
                     bracket_ingroup=True))
     self.assertTrue('[pre-ingroup-marker' in newick)
     self.assertTrue('[post-ingroup-marker' in newick)
     self.assertTrue(newick.startswith('('))
     self.assertTrue('*tip #1 not mapped' in newick)
     self.assertTrue('*tip #2 not mapped' in newick)
     self.assertTrue('*tip #3 not mapped' not in newick)
     newick = extract_tree(
         n, 'tree3', PhyloSchema('newick', tip_label='ot:ottTaxonName'))
     self.assertTrue('[pre-ingroup-marker' not in newick)
     self.assertTrue('[post-ingroup-marker' not in newick)
     self.assertTrue('*tip #1 not mapped' in newick)
     self.assertTrue('*tip #2 not mapped' in newick)
     self.assertTrue('*tip #3 not mapped' not in newick)
     self.assertTrue(newick.startswith('('))
     newick = extract_tree(
         n, 'tree3', PhyloSchema('newick', tip_label='ot:originallabel'))
     self.assertTrue('[pre-ingroup-marker' not in newick)
     self.assertTrue('[post-ingroup-marker' not in newick)
     self.assertTrue('*tip #' not in newick)
Example #8
0
 def testTreeBaseImport(self):
     fp = pathmap.nexml_source_path('S15515.xml')
     n = get_ot_study_info_from_treebase_nexml(src=fp,
                                               merge_blocks=True,
                                               sort_arbitrary=True)
     expected = pathmap.nexson_obj('S15515.json')
     equal_blob_check(self, 'S15515', n, expected)
     self.assertTrue(expected == n)
 def testTreeBaseImport(self):
     fp = pathmap.nexml_source_path('S15515.xml')
     n = get_ot_study_info_from_treebase_nexml(src=fp,
                                               merge_blocks=True,
                                               sort_arbitrary=True)
     expected = pathmap.nexson_obj('S15515.json')
     equal_blob_check(self, 'S15515', n, expected)
     self.assertTrue(expected == n)
Example #10
0
 def testOtuConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexson',
                      content='otu',
                      content_id='otu190',
                      version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('{'))  # pylint: disable=E1103
Example #11
0
 def testNexusConvByExtViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(None,
                      type_ext='.nex',
                      content='tree',
                      content_id='tree3')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
Example #12
0
 def testMimicPhylesystemExport(self):
     study_nexson = pathmap.nexson_obj('10/pg_10.json')
     src_schema = PhyloSchema('nexson', version='1.2.1')
     out_schema = PhyloSchema(schema='newick', content='tree', content_id='bogusID here')
     result_data = out_schema.convert(study_nexson, serialize=True, src_schema=src_schema)
     self.assertFalse(bool(result_data))
     out_schema = PhyloSchema(schema='nexus', content='tree', content_id='bogusID here')
     result_data = out_schema.convert(study_nexson, serialize=True, src_schema=src_schema)
     self.assertFalse(bool(result_data))
Example #13
0
 def testNewickExport(self):
     n = pathmap.nexson_obj('10/pg_10.json')
     newick = extract_tree(n, 'tree3', PhyloSchema('newick', tip_label='ot:ottTaxonName', bracket_ingroup=True))
     self.assertTrue('[pre-ingroup-marker' in newick)
     self.assertTrue('[post-ingroup-marker' in newick)
     self.assertTrue(newick.startswith('('))
     newick = extract_tree(n, 'tree3', PhyloSchema('newick', tip_label='ot:ottTaxonName'))
     self.assertTrue('[pre-ingroup-marker' not in newick)
     self.assertTrue('[post-ingroup-marker' not in newick)
     self.assertTrue(newick.startswith('('))
Example #14
0
 def testIterTree(self):
     id_order_list = []
     f_list = ['expected', 'input']
     for v in ['1.0', '1.2']:
         for f in f_list:
             inp = pathmap.nexson_obj('merge/merge-{f}.v{v}.json'.format(v=v, f=f))
             id_order = []
             for t_tuple in iter_trees(inp):
                 ti = t_tuple[1]
                 id_order.append(ti)
             id_order_list.append(id_order)
     for i in range(1, 4):
         self.assertEqual(id_order_list[0], id_order_list[i])
 def testTreeBaseImport(self):
     fp = pathmap.nexml_source_path('S15515.xml')
     n = get_ot_study_info_from_treebase_nexml(src=fp,
                                               merge_blocks=True,
                                               sort_arbitrary=True)
     # did we successfully coerce its DOI to the required URL form?
     self.assertTrue('@href' in n['nexml']['^ot:studyPublication'])
     test_doi = n['nexml']['^ot:studyPublication']['@href']
     self.assertTrue(test_doi == doi2url(test_doi))
     # furthermore, the output should exactly match our test file
     expected = pathmap.nexson_obj('S15515.json')
     equal_blob_check(self, 'S15515', n, expected)
     self.assertTrue(expected == n)
 def testTreesCulledNonmatcingConvViaPS(self):
     o = pathmap.nexson_obj('9/v1.2.json')
     self.assertEqual(len(extract_tree_nexson(o, tree_id=None)), 2)
     ps = PhyloSchema('nexson', content='tree', content_id='tree2', version='1.2.1', cull_nonmatching='true')
     x = ps.serialize(o)
     etn = extract_tree_nexson(o, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
     self.assertTrue(x.startswith('{'))  # pylint: disable=E1103
     rx = json.loads(x)
     etn = extract_tree_nexson(rx, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
Example #17
0
 def testTreesCulledNonmatcingConvViaPS(self):
     o = pathmap.nexson_obj('9/v1.2.json')
     self.assertEqual(len(extract_tree_nexson(o, tree_id=None)), 2)
     ps = PhyloSchema('nexson', content='tree', content_id='tree2', version='1.2.1', cull_nonmatching='true')
     x = ps.serialize(o)
     etn = extract_tree_nexson(o, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
     self.assertTrue(x.startswith('{')) #pylint: disable=E1103
     rx = json.loads(x)
     etn = extract_tree_nexson(rx, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
Example #18
0
 def testTreeBaseImport(self):
     fp = pathmap.nexml_source_path('S15515.xml')
     n = get_ot_study_info_from_treebase_nexml(src=fp,
                                               merge_blocks=True,
                                               sort_arbitrary=True)
     # did we successfully coerce its DOI to the required URL form?
     self.assertTrue('@href' in n['nexml']['^ot:studyPublication'])
     test_doi = n['nexml']['^ot:studyPublication']['@href']
     self.assertTrue(test_doi == doi2url(test_doi))
     # furthermore, the output should exactly match our test file
     expected = pathmap.nexson_obj('S15515.json')
     equal_blob_check(self, 'S15515', n, expected)
     self.assertTrue(expected == n)
Example #19
0
 def testTreesCulledNonmatcingConvViaPSV0(self):
     '''Verify that the culling does not break the conversion to other forms of NexSON'''
     o = pathmap.nexson_obj('9/v1.2.json')
     self.assertEqual(len(extract_tree_nexson(o, tree_id=None)), 2)
     ps = PhyloSchema('nexson', content='tree', content_id='tree2', version='0.0.0', cull_nonmatching='true')
     x = ps.serialize(o)
     etn = extract_tree_nexson(o, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
     self.assertTrue(x.startswith('{')) #pylint: disable=E1103
     rx = json.loads(x)
     self.assertEqual(detect_nexson_version(rx), '0.0.0')
     etn = extract_tree_nexson(rx, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
 def testTreesCulledNonmatcingConvViaPSV0(self):
     """Verify that the culling does not break the conversion to other forms of NexSON"""
     o = pathmap.nexson_obj('9/v1.2.json')
     self.assertEqual(len(extract_tree_nexson(o, tree_id=None)), 2)
     ps = PhyloSchema('nexson', content='tree', content_id='tree2', version='0.0.0', cull_nonmatching='true')
     x = ps.serialize(o)
     etn = extract_tree_nexson(o, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
     self.assertTrue(x.startswith('{'))  # pylint: disable=E1103
     rx = json.loads(x)
     self.assertEqual(detect_nexson_version(rx), '0.0.0')
     etn = extract_tree_nexson(rx, tree_id=None)
     self.assertEqual(len(etn), 1)
     self.assertEqual(etn[0][0], 'tree2')
Example #21
0
 def testValidFilesPass(self):
     format_list = ['1.2']
     msg = ''
     for d in VALID_NEXSON_DIRS:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             aa = validate_nexson(nexson)
             annot = aa[0]
             for e in annot.errors:
                 _LOG.debug('unexpected error from {f}: {m}'.format(f=frag, m=UNICODE(e)))
             if len(annot.errors) > 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "File failed to validate cleanly. See {o}".format(o=ofn)
             self.assertEqual(len(annot.errors), 0, msg)
Example #22
0
 def testValidFilesPass(self):
     format_list = ['1.2']
     msg = ''
     for d in VALID_NEXSON_DIRS:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             aa = validate_nexson(nexson)
             annot = aa[0]
             for e in annot.errors:
                 _LOG.debug('unexpected error from {f}: {m}'.format(
                     f=frag, m=UNICODE(e)))
             if len(annot.errors) > 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "File failed to validate cleanly. See {o}".format(
                     o=ofn)
             self.assertEqual(len(annot.errors), 0, msg)
Example #23
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                                  nf,
                                                  allow_invalid=True,
                                                  max_num_trees_per_study=1)
             annotation = bundle[1]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
Example #24
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                              nf,
                                              allow_invalid=True,
                                              max_num_trees_per_study=1)
             nexson, annotation, validation_log, nexson_adaptor = bundle
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
 def testNexmlConvByExtViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(type_ext='.nexml', otu_label='otttaxonname')
     nex = ps.serialize(o, src_schema=PhyloSchema('nexson', version='1.2.1'))
     self.assertTrue(nex.startswith('<'))  # pylint: disable=E1103
Example #26
0
 def setUp(self):
     self.nexson = pathmap.nexson_obj('pg_329/pg_329.json')
     self.np = NexsonProxy(nexson=self.nexson)
Example #27
0
 def testCanCountTrees(self):
     for v in ['0.0', '1.0', '1.2']:
         inp = pathmap.nexson_obj('otu/v{v}.json'.format(v=v))
         self.assertEqual(1, count_num_trees(inp, v))
Example #28
0
 def testNexusConvStudyViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(type_ext='.nex')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
Example #29
0
 def testNexmlConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexml')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('<'))  # pylint: disable=E1103
Example #30
0
 def setUp(self):
     self.nexson = pathmap.nexson_obj('pg_329/pg_329.json')
     self.np = NexsonProxy(nexson=self.nexson)
Example #31
0
 def setUp(self):
     blob = pathmap.nexson_obj('9/v1.2.json')
     self.np = NexsonProxy(nexson=blob)
Example #32
0
 def testTreeExport(self):
     n = pathmap.nexson_obj('10/pg_10.json')
     newick = extract_tree(
         n, 'tree3', PhyloSchema('nexus', tip_label='ot:ottTaxonName'))
     self.assertTrue(newick.startswith('#'))
Example #33
0
 def setUp(self):
     blob = pathmap.nexson_obj('9/v1.2.json')
     self.np = NexsonProxy(nexson=blob)
Example #34
0
 def testDetectVersion(self):
     o = pathmap.nexson_obj('invalid/bad_version.json.input')
     v = detect_nexson_version(o)
     self.assertEqual(v, '1.3.1')
 def testOtuMapConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexson', content='otumap', version='1.2.1')
     x = ps.serialize(o)
     self.assertTrue(x.startswith('{'))  # pylint: disable=E1103
 def testNexmlConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexml')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('<'))  # pylint: disable=E1103
 def testNexusConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexus', content='tree', content_id='tree3')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
Example #38
0
 def testNexmlConvByExtViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(type_ext='.nexml', otu_label='otttaxonname')
     nex = ps.serialize(o,
                        src_schema=PhyloSchema('nexson', version='1.2.1'))
     self.assertTrue(nex.startswith('<'))  # pylint: disable=E1103
 def testNexusConvStudyViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(type_ext='.nex')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
Example #40
0
 def testDetectVersion(self):
     o = pathmap.nexson_obj('invalid/bad_version.json.input')
     v = detect_nexson_version(o)
     self.assertEqual(v, '1.3.1')
 def testNewickConvStudyViaPS(self):
     o = pathmap.nexson_obj('9/v1.2.json')
     ps = PhyloSchema(type_ext='.tre')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('('))  # pylint: disable=E1103
Example #42
0
 def testNexusConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('nexus', content='tree', content_id='tree3')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
 def testNexusConvByExtViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema(None, type_ext='.nex', content='tree', content_id='tree3')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('#'))  # pylint: disable=E1103
Example #44
0
 def testNewickConvStudyViaPS(self):
     o = pathmap.nexson_obj('9/v1.2.json')
     ps = PhyloSchema(type_ext='.tre')
     nex = ps.convert(o, serialize=True)
     self.assertTrue(nex.startswith('('))  # pylint: disable=E1103
 def testNewickConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick', content='tree', content_id='tree3')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('('))  # pylint: disable=E1103
Example #46
0
 def testNewickConvViaPS(self):
     o = pathmap.nexson_obj('10/pg_10.json')
     ps = PhyloSchema('newick', content='tree', content_id='tree3')
     nex = ps.serialize(o)
     self.assertTrue(nex.startswith('('))  # pylint: disable=E1103
Example #47
0
 def testTreeExport(self):
     n = pathmap.nexson_obj('10/pg_10.json')
     newick = extract_tree(n, 'tree3', PhyloSchema('nexus', tip_label='ot:ottTaxonName'))
     self.assertTrue(newick.startswith('#'))