def test_graph_filtration(get_input_and_gate): input_file = get_input_and_gate gc = parse_sbol_xml_tree(input_file) gn = NetworkGeneticCircuit(sbol_input=gc) ogn = gn.filter_graph("bound") assert len(ogn) == 6 # 3 sets of 2 elements = 6 # All nodes in the primary graph have a regular edge assert len(gn.get_nodes()) == 18
def test_graph_construction(get_input_and_gate): input_file = get_input_and_gate gc = parse_sbol_xml_tree(input_file) gn = NetworkGeneticCircuit(sbol_input=gc) promoter_parts = gn.get_nodes_by_part("Promoter") assert len(promoter_parts) == 5 bound_nodes = gn.get_bound_nodes() assert len(bound_nodes) == 3
def test_scoring_and_requirements_interface(get_input_and_gate): """ If a scoring module does not implement the baseline features, it raises a TypeError. """ input_file = get_input_and_gate gc = parse_sbol_xml_tree(input_file) gn = NetworkGeneticCircuit(sbol_input=gc) req = GoodRequirements() GoodScoring(gn, req) with pytest.raises(TypeError): BadScoring(gn, req) with pytest.raises(TypeError): BaseRequirement()
def test_gc_calculation(get_input_and_gate): input_file = get_input_and_gate gc = parse_sbol_xml_tree(input_file) gn = NetworkGeneticCircuit(sbol_input=gc) # Should be approximately 48% GC Content assert round(gn.calculate_gc_content_percentage(), 2) == 0.48
def score( requested_solvers: List[str] = typer.Argument( ..., help="The Input Solvers", ), sbol_filepath: str = typer.Option( os.path.join(os.getcwd(), "tests", "test_cello", "example_and_gate.xml"), help="Filepath: location of the SBOL file that constitutes the genetic " "circuit", ), parameter_filepath: str = typer.Option( os.path.join(os.getcwd(), "input.yml"), help="Filepath: location of the SBOL file that constitutes the genetic " "circuit", ), out_filepath: str = typer.Option( "output", help="Filepath: location to write the output of the solved function"), ): """ Takes an SBOL file, evaluates the quality of a genetic circuit, and then outputs performance metrics. """ # We take in our input values and normalize them. requested_solvers = [solver.lower() for solver in requested_solvers] available_solvers = get_available_scorers() for solver in requested_solvers: if solver not in available_solvers: raise RuntimeError( f"Unable to find a scorer with the name {solver}, please " f"investigate.") # We then ensure that our filepaths are correct so we're not breaking down # the line. if not os.path.isfile(parameter_filepath): raise RuntimeError( f"Unable to locate input file {parameter_filepath}. Please Investigate." ) # We assume that we'll have multiple forms of output, so what we're doing is # validating the output is just an extant directory. If not, we try to # generate one. if not os.path.isdir(out_filepath): os.mkdir(out_filepath) # We now need to ensure that our files, while extant, contain the information # required to compute the score. Individual errors are propagated via the # function. if not validate_input_file( input_fp=parameter_filepath, requested_scorers=requested_solvers, ): raise RuntimeError(f"Input File failed to pass validation. Exiting.") # We should now be good to go so we just move forward with parsing the input # data and sending it off to the requested solvers. gc = parse_sbol_xml_tree(sbol_filepath) network = NetworkGeneticCircuit(gc) requested_requirements = generate_requirement_classes( parameter_filepath, requested_solvers) scoring_map = get_scorer_map() for solver, requirement in zip(requested_solvers, requested_requirements): solver_class = scoring_map[solver] try: solver_obj = solver_class(network, requirement) except TypeError: solver_obj = solver_class(requirement) solver_obj.score() solver_obj.report()
def test_ingress_module(get_input_and_gate): input_file = get_input_and_gate gc = parse_sbol_xml_tree(input_file) gc_dict = gc.as_dict()