예제 #1
0
    def test_level_2_2(self):
        '''
        Test that runs with GrandParent - Child Relationship
        Expect: Two trees (Two Component Definitions) with two relationships
                This is a component that is a child of one of the CDS with a SequenceAnnotation and a child Location.
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_level_2_2.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),3)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)

        # Bespoke tests that can only be done by knowledge of the graph.
        # The tree has two roots
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,3)
        self.assertEqual(child_count,5)
        self.assertEqual(children["http://sbol_prefix.org/cd1/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/cd2/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/moduledef_1/1"],5)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,2)
        self.assertEqual(depths["http://sbol_prefix.org/cd1/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/cd2/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/moduledef_1/1"],2)
예제 #2
0
    def test_level_1(self):
        '''
        Test that runs with a single parent-child relationship
        Expect: Two trees (Two Component Definitions) but with a relationship triplepack
                This is a component that is a child of one of the CDS
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_level_1.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),2)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)

        # Bespoke tests that can only be done by knowledge of the graph.
        # The tree has two roots
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,2)
        self.assertEqual(child_count,1)
        self.assertEqual(children["http://sbol_prefix.org/pTetR/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/tetRInverter/1"],1)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,1)
        self.assertEqual(depths["http://sbol_prefix.org/pTetR/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/tetRInverter/1"],1)
예제 #3
0
    def test_large_script_2(self):
        '''
        Tests a large script as almost like a user-test scenario.
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_large_script_2.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),4)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)
        # Bespoke tests that can only be done by knowledge of the graph.
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,4)
        self.assertEqual(child_count,13)
        self.assertEqual(children["http://sbol_prefix.org/LacI_inverter/1"],8)
        self.assertEqual(children["http://sbol_prefix.org/TetR_inverter/1"],5)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,2)
        self.assertEqual(depths["http://sbol_prefix.org/LacI_inverter/1"],2)
        self.assertEqual(depths["http://sbol_prefix.org/TetR_inverter/1"],2)
예제 #4
0
    def test_sequence(self):
        '''
        Test Sequences with CD's to ensure that Sequences ARENT identified as children
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_sequence.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),2)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)

        # Bespoke tests that can only be done by knowledge of the graph.
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,2)
        self.assertEqual(child_count,0)
        self.assertEqual(children["http://sbol_prefix.org/seq_1/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/pTetR/1"],0)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,0)
        self.assertEqual(depths["http://sbol_prefix.org/seq_1/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/pTetR/1"],0)
예제 #5
0
def produce_sbol(fn, output):
    try:
        return_code = shortbol_script_runner.parse_from_file(
            fn, "sbolxml", [templates], output, [])
    except Exception as e:
        return e
    return return_code
예제 #6
0
def produce_sbol(fn, output, version):
    try:
        return_code = shortbol_script_runner.parse_from_file(
            fn,
            "sbolxml", [templates],
            output, [],
            no_validation=False,
            version=version)
    except Exception as e:
        return e
    return return_code
예제 #7
0
    def test_regression_by_examples(self):
        failure_exceptions = []
        sbol_validation_errors = []
        for path, subdirs, files in os.walk(test_files):
            for name in files:
                if name == "temporary_runner.shb":
                    continue
                if name.endswith(".shb") or name.endswith(".rdfsh"):
                    if "sbol_3" in path:
                        version = "sbol_3"
                    else:
                        version = "sbol_2"
                    file_to_run = os.path.join(path, name)
                    short_fn = file_to_run.split("\\")
                    short_fn = "/".join(short_fn[len(short_fn) - 2:])
                    print("Running with file: " + str(short_fn))
                    return_code = "Error Thrown."
                    try:
                        return_code = run.parse_from_file(file_to_run,
                                                          "sbolxml",
                                                          [templates],
                                                          output_fn, [],
                                                          version=version)
                    except Exception as e:
                        failure_exceptions.append({file_to_run: e})
                    if return_code != {"SBOL validator success.": []}:
                        sbol_validation_errors.append({short_fn: return_code})

        print("--------------------Report--------------------\n")
        print(
            f"Number of failures by exception: {str(len(failure_exceptions))}")
        print(
            f"Number of failures by validation: {str(len(sbol_validation_errors))}"
        )

        if len(failure_exceptions) > 0:
            for exception in failure_exceptions:
                for k, v in exception.items():
                    print("Failure by Exception on:" + k + ", Exception: " +
                          str(v))

        if len(sbol_validation_errors) > 0:
            for validation_error in sbol_validation_errors:
                for k, v in validation_error.items():
                    print("Failure by SBOL Validation on: " + str(k) +
                          "\nvalidation errors: " + str(v) + "\n")

        if len(failure_exceptions) > 0 or len(sbol_validation_errors) > 0:
            self.fail("Atleast One Test Failed")

        print("\n--------------------------------------------")
예제 #8
0
    def test_level_0(self):
        '''
        Simplest Test only one triplepack with no children.
        Expect: Single tree, cd as root with only a single layer that only contains the properties
                of the CD no children references.
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_level_0.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),1)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)

        # Bespoke tests that can only be done by knowledge of the graph.
        single_cd = heirachy_tree[str(list(roots)[0][0])]
        expected_type = (rdflib.URIRef('http://sbol_prefix.org/n/1') , rdflib.URIRef('http://sbols.org/v2#type'), rdflib.URIRef('http://www.biopax.org/release/biopax-level3.owl#Dna'))
        expected_name = (rdflib.URIRef('http://sbol_prefix.org/n/1') , rdflib.URIRef('http://purl.org/dc/terms/title'), rdflib.term.Literal('LacI CDS'))
        expected_description = (rdflib.URIRef('http://sbol_prefix.org/n/1') , rdflib.URIRef('http://purl.org/dc/terms/description'), rdflib.term.Literal('Coding Region for LacI protein'))
        expected_role = (rdflib.URIRef('http://sbol_prefix.org/n/1') , rdflib.URIRef('http://sbols.org/v2#role'), rdflib.URIRef('http://identifiers.org/so/SO:0000316'))
        self.assertEqual(len(heirachy_tree),1)
        self.assertTrue(expected_type in single_cd)
        self.assertTrue(expected_name in single_cd)
        self.assertTrue(expected_description in single_cd)
        self.assertTrue(expected_role in single_cd)

        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,1)
        self.assertEqual(child_count,0)
        self.assertEqual(children["http://sbol_prefix.org/n/1"],0)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,0)
        self.assertEqual(depths["http://sbol_prefix.org/n/1"],0)
예제 #9
0
    def test_large_script(self):
        '''
        Tests a large script as almost like a user-test scenario.
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_large_script.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),30)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)
        # Bespoke tests that can only be done by knowledge of the graph.
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,30)
        self.assertEqual(child_count,76)
        self.assertEqual(children["http://sbol_prefix.org/Gal4VP16_gene/1"],3)
        self.assertEqual(children["http://sbol_prefix.org/EYFP_gene/1"],3)
        self.assertEqual(children["http://sbol_prefix.org/gRNA_b_gene/1"],5)   
        self.assertEqual(children["http://sbol_prefix.org/mKate_gene/1"],3)   
        self.assertEqual(children["http://sbol_prefix.org/cas9m_BFP_gene/1"],3)   
        self.assertEqual(children["http://sbol_prefix.org/CRISPR_Template/1"],15)   
        self.assertEqual(children["http://sbol_prefix.org/CRPb_characterization_Circuit/1"],44)   

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,2)
        self.assertEqual(depths["http://sbol_prefix.org/Gal4VP16_gene/1"],1)
        self.assertEqual(depths["http://sbol_prefix.org/EYFP_gene/1"],1)
        self.assertEqual(depths["http://sbol_prefix.org/gRNA_b_gene/1"],1)   
        self.assertEqual(depths["http://sbol_prefix.org/mKate_gene/1"],1)   
        self.assertEqual(depths["http://sbol_prefix.org/cas9m_BFP_gene/1"],1)   
        self.assertEqual(depths["http://sbol_prefix.org/CRISPR_Template/1"],2)   
        self.assertEqual(depths["http://sbol_prefix.org/CRPb_characterization_Circuit/1"],2)  
예제 #10
0
    def test_many_trees_many_relationships(self):
        '''
        Test that runs many top-level objects AND with many relationships but all depth-2 level relationships.
        Expect: Each Top-Level objects are connected by non-top-level object, parent-child relationships.
        '''
        # Create SBOL from ShortBOL
        test_fn = "test_many_trees_many_relationships.shb"
        return_code = shortbol_script_runner.parse_from_file(test_fn,optpaths=[lib_path],out=output_fn)
        self.assertEqual(list(return_code.keys())[0], "SBOL validator success.")
        test_graph = load_graph(output_fn)
        # Run GetRoots
        roots = SBOL2ShortBOL.find_graph_roots(test_graph)
        self.assertEqual(len(roots),5)
        # Test get_tree
        heirachy_tree = generate_tree(roots,test_graph)
        SBOL2ShortBOL.tree_dump(heirachy_tree, os.path.join(output_dir,test_fn.split(".")[0] + ".txt"))

        self.common_tests(heirachy_tree,roots)

        # Bespoke tests that can only be done by knowledge of the graph.
        # The tree has two roots
        top_level_count,children = count_objects(heirachy_tree)
        child_count = sum(list(children.values()))
        self.assertEqual(top_level_count,5)
        self.assertEqual(child_count,6)
        self.assertEqual(children["http://sbol_prefix.org/seq_1/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/cd_1/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/cd_2/1"],4)
        self.assertEqual(children["http://sbol_prefix.org/model_1/1"],0)
        self.assertEqual(children["http://sbol_prefix.org/mod_def_1/1"],2)

        max_depth,depths = get_depth(heirachy_tree)
        self.assertEqual(max_depth,1)
        self.assertEqual(depths["http://sbol_prefix.org/seq_1/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/cd_1/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/cd_2/1"],1)
        self.assertEqual(depths["http://sbol_prefix.org/model_1/1"],0)
        self.assertEqual(depths["http://sbol_prefix.org/mod_def_1/1"],1)
예제 #11
0
def run_shortbol(filename):
    return_code_shortbol = run.parse_from_file(filename, "sbolxml",
                                               [templates], shortbol_output_fn,
                                               [])
    return return_code_shortbol