def get_observed_result(self, DnaSpecie): """ Find observed concentrations for the metabolite or similar metabolites NOTE: Currently there are no Gene objects in common schema models. When added this query will be updated to input models.Gene and output data_model.ProteinSpecie Args: specie (:obj:`data_model.DnaSpecie`): species to find data for Returns: :obj:`list` of :obj:`data_model.Observable`: list of observed_result """ proteins = self.get_protein_by_DNA_sequence(DnaSpecie.sequence) observed_result = [] for subunits in proteins: protein = data_model.ProteinSpecie(uniprot_id = subunits[0].uniprot_id,\ entrez_id = subunits[0].entrez_id, gene_name = subunits[0].gene_name,\ length = subunits[0].length, mass = subunits[0].mass) protein.cross_references = [] for doc in subunits[0]._metadata.resource: protein.cross_references.append( data_model.Resource(namespace='pubmed', id=doc._id)) interaction = data_model.Interaction(name = 'Transcription Factor DNA Binding Site', \ position = subunits[1], score = subunits[2]) observed_result.append( data_model.Observable(specie=protein, interaction=interaction)) return observed_result
def get_observable_subunits(self, protein_complex): """ Get known protein subunit that were observed for a given protein complex Args: protein_subunit (:obj:`models.ProteinComplex`): complex to find subunits for Returns: :obj:`list` of :obj:`data_model.ObservedSpecie`: list of Protein Subunits """ subunits = self.get_subunits_by_known_complex( protein_complex.complex_name).all() observed_specie = [] for item in subunits: metadata = self.metadata_dump(item) resource = data_model.Resource( namespace=item._metadata.resource[0].namespace, id=item._metadata.resource[0]._id) specie = data_model.ProteinSpecie(name=item.subunit_name, uniprot_id=item.uniprot_id, sequence=item.canonical_sequence, entrez_id=item.entrez_id, gene_name=item.gene_name, length=item.length, mass=item.mass, cross_references=[resource]) observed_specie.append( data_model.ObservedSpecie(specie=specie, metadata=metadata)) return observed_specie
def get_observed_result(self, protein): """ Find the observed values for protein abundance Args: protein (:obj:`models.ProteinSubunit`): Protein Subunit to find data for Returns: :obj:`list` of :obj:`data_model.ObservedValue`: list of relevant observed values """ abundances = self.get_abundance_by_uniprot(protein.uniprot_id) observed_vals = [] for abundance in abundances: metadata = self.metadata_dump(abundance.dataset) observable = data_model.Observable(specie=data_model.ProteinSpecie( name=protein.subunit_name, uniprot_id=protein.uniprot_id, entrez_id=protein.entrez_id, gene_name=protein.gene_name, length=protein.length, mass=protein.mass, sequence=protein.canonical_sequence)) observable.specie.cross_references = [ data_model.Resource(namespace='publication', id=abundance.dataset.file_name), data_model.Resource( namespace='url', id=abundance.dataset._metadata.resource[0]._id) ] observed_vals.append( data_model.ObservedValue( metadata=metadata, observable=observable, value=abundance.abundance, error=0, units='PPM', )) return observed_vals
def test_init(self): xr = data_model.Resource( namespace='src', id='identifier', relevance=2., assignment_method=data_model.ResourceAssignmentMethod.manual) self.assertEqual(xr.namespace, 'src') self.assertEqual(xr.id, 'identifier') self.assertEqual(xr.relevance, 2.) self.assertEqual(xr.assignment_method, data_model.ResourceAssignmentMethod.manual)
def get_reaction(pi_structure=pi_structure, ec='1.1.1.1'): return data_model.Reaction( participants=[ data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=atp_structure)), data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=h2o_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=adp_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=pi_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=h_structure)), ], cross_references=[ data_model.Resource(namespace='ec-code', id=ec) ])
def get_observed_result(self, protein): """ Find the DNA binding motif for a given protein Args: protein (:obj:`models.ProteinSubunit`): protein subunit to find data for Returns: :obj:`list` of :obj:`data_model.Observable`: list of observables """ versions = self.get_DNA_by_protein(protein) index = 0 observed_result = [] for motif in versions: binding_matrix = [] for position in motif.all(): binding_matrix.append([ position.frequency_a, position.frequency_c, position.frequency_g, position.frequency_t ]) binding_matrix = map(list, zip(*binding_matrix)) self.cache_dirname = tempfile.mkdtemp() with open(self.cache_dirname + '/data.pfm', 'w') as pfm: for items in binding_matrix: writer = csv.writer(pfm, delimiter='\t') writer.writerow(items) m = motifs.read(open(self.cache_dirname + '/data.pfm'), 'pfm') dna_specie = data_model.DnaSpecie(binding_matrix=m.counts, sequence=str(m.counts.consensus)) metadata = self.metadata_dump(motif.all()[0].dataset) observed_result.append( data_model.ObservedSpecie(specie=dna_specie, metadata=metadata)) for position in motif.all(): observed_result[index].specie.cross_references = data_model.Resource(namespace ='pubmed',\ id = position.dataset._metadata.resource[0]._id), break shutil.rmtree(self.cache_dirname) index += 1 return observed_result
def _port(self, reaction_list): """ Converts SQL model reaction into a Obj Model based data_model reaction Args: reaction_list :obj:`list` of :obj:`models.Reaction`:): list of reaction participants Returns: :obj:`data_model.Reaction`: a cohesive reaction data object """ references = [] participants = [] for rxn_part in reaction_list: if rxn_part._is_reactant: coef = -1 elif rxn_part._is_product: coef = 1 elif rxn_part._is_modifier: coef = 0 part = data_model.ReactionParticipant(specie=data_model.Specie( name=rxn_part.metabolite.metabolite_name, structure=rxn_part.metabolite.structure._value_inchi if rxn_part.metabolite.structure else None), coefficient=coef) participants.append(part) if len(references) < 1: for item in rxn_part.kinetic_law._metadata.resource: references.append( data_model.Resource(namespace=item.namespace, id=item._id, assignment_method=data_model. ResourceAssignmentMethod.manual)) rxn = data_model.Reaction( participants=participants, cross_references=references, kinetic_law_id=reaction_list[0].kinetic_law_id) rxn.name = rxn.stringify() return rxn
def _port(self, complex): resource = [ data_model.Resource(namespace=resource.namespace, id=resource._id) for resource in complex._metadata.resource ] return data_model.ProteinComplexSpecie( name=complex.complex_name, go_id=complex.go_id, go_dsc=complex.go_dsc, funcat_id=complex.funcat_id, funcat_dsc=complex.funcat_dsc, su_cmt=complex.su_cmt, complex_cmt=complex.complex_cmt, disease_cmt=complex.disease_cmt, class_name=complex.class_name, family_name=complex.family_name, molecular_weight=complex.molecular_weight, cross_references=resource)
def get_observed_result(self, metabolite): """ Find observed concentrations for the metabolite or similar metabolites Args: metabolite (:obj:`models.Metabolite`): metabolite to find data for Returns: :obj:`list` of :obj:`data_model.ObservedValue`: list of relevant observations """ concentrations = self.get_concentration_by_structure( metabolite.structure._value_inchi, only_formula_and_connectivity=False).all() observed_values = [] references = [ data_model.Resource(namespace=item.namespace, id=item._id) for item in metabolite._metadata.resource ] for c in concentrations: metadata = self.metadata_dump(c) observable = data_model.Observable( specie=data_model.Specie( name=metabolite.metabolite_name, cross_references=references, structure=metabolite.structure._value_inchi), compartment=data_model.Compartment( name=c._metadata.cell_compartment[0].name)) observed_values.append( data_model.ObservedValue(metadata=metadata, observable=observable, value=c.value, error=c.error, units=c.units)) return observed_values
def get_observable_complex(self, protein_subunit): """ Get known protein complex that were observed for a given subunit Args: protein_subunit (:obj:`models.ProteinSubunit`): subunit to find complex for Returns: :obj:`list` of :obj:`data_model.ObservedSpecie`: list of Protein Complexes """ observed_specie = [] complex_ = self.get_known_complex_by_subunit( protein_subunit.uniprot_id) for item in complex_: metadata = self.metadata_dump(item) resource = data_model.Resource( namespace=item._metadata.resource[0].namespace, id=item._metadata.resource[0]._id) complex = data_model.ProteinComplexSpecie( name=item.complex_name, go_id=item.go_id, go_dsc=item.go_dsc, funcat_id=item.funcat_id, funcat_dsc=item.funcat_dsc, su_cmt=item.su_cmt, complex_cmt=item.complex_cmt, disease_cmt=item.disease_cmt, class_name=item.class_name, family_name=item.family_name, molecular_weight=item.molecular_weight, cross_references=[resource]) observed_specie.append( data_model.ObservedSpecie(specie=complex, metadata=metadata)) return observed_specie
def metadata_dump(self, component): """ Calculate a consensus statistical representation of the one or more observed values Args: component (:obj:`models.Observation`): model component dump data for Returns: :obj:`list` of :obj:`data_model.ObservedResultMetadata`: data model metadata object """ genetics = None environment = None cross_references = [] method = None synonym = [] meta = component._metadata taxon = meta.taxon[0].name if meta.taxon else None variation = meta.cell_line[0].name if meta.cell_line else None genetics = data_model.Genetics(taxon=taxon, variation=variation) temperature = meta.conditions[ 0].temperature if meta.conditions else None ph = meta.conditions[0].ph if meta.conditions else None media = meta.conditions[0].media if meta.conditions else None growth_status = meta.conditions[ 0].growth_status if meta.conditions else None growth_system = meta.conditions[ 0].growth_system if meta.conditions else None environment = data_model.Environment(temperature=temperature, ph=ph, media=media, growth_status=growth_status, growth_system=growth_system) name = meta.method[0].name if meta.method else None description = meta.method[0].comments if meta.method else None performer = meta.method[0].performer if meta.method else None hardware = meta.method[0].hardware if meta.method else None software = meta.method[0].software if meta.method else None method = data_model.Method(name=name, description=description, performer=performer, hardware=hardware, software=software) if meta.resource: for item in meta.resource: cross_references.append( data_model.Resource(namespace=item.namespace, id=item._id)) else: cross_references.append( data_model.Resource(namespace=None, id=None)) if meta.synonym: for item in meta.synonym: synonym.append(data_model.Synonym(name=item.name)) else: synonym.append(data_model.Synonym(name=None)) metadata_result = data_model.ObservedResultMetadata( genetics=genetics, environment=environment, cross_references=cross_references, method=method, synonym=synonym) return metadata_result
def get_observed_result(self, reaction): """ Find observed kinetics for the reaction or similar reactions TODO: Add compartment infomrmation 1. Find kinetics observed for the reaction a. Find the metabolite(s) of each participant b. Find the reaction(s) which contain all of these metabolites c. Find the kinetic laws associated with these reactions 2. Find kinetics observed for similar reactions a. Find kinetics observed for the assigned EC number(s) b. Find kinetics observed for EC number(s) predicted by tools such as E-zyme Args: reaction (:obj:`data_model.Reaction`): reaction to find data for Returns: :obj:`list` of :obj:`data_model.ObservedValue`: list of relevant observed values """ q_law = self.get_kinetic_laws_by_reaction(reaction) observed_vals = [] for law in q_law: common_schema_reaction_id = next(xr._id for xr in law._metadata.resource if xr.namespace == 'sabiork.reaction') reaction = data_model.Reaction( cross_references=[ data_model.Resource(namespace='common_schema.kinetic_law_id', id=str(law.kinetic_law_id)), data_model.Resource(namespace='sabiork.reaction', id=common_schema_reaction_id), ], ) species = {} compartments = {} cs_rxn = self.data_source.session.query(models.Reaction).filter_by(kinetic_law_id = law.kinetic_law_id) reactants = cs_rxn.filter_by(_is_reactant = True).all() products = cs_rxn.filter_by(_is_product = True).all() modifiers = cs_rxn.filter_by(_is_modifier = True).all() for reactant in reactants: part = data_model.ReactionParticipant(coefficient=-1) if reactant.metabolite_id not in species: species[reactant.metabolite_id] = data_model.Specie(name=reactant.metabolite.metabolite_name) part.specie = species[reactant.metabolite_id] if reactant.metabolite.structure_id: part.specie.structure = reactant.metabolite.structure._value_inchi if reactant.compartment_id: if reactant.compartment.name not in compartments: compartments[reactant.compartment.name] = data_model.Compartment(name=reactant.compartment.name) part.compartment = compartments[reactant.compartment.name] reaction.participants.append(part) for product in products: part = data_model.ReactionParticipant(coefficient=1) if product.metabolite_id not in species: species[product.metabolite_id] = data_model.Specie(name=product.metabolite.metabolite_name) part.specie = species[product.metabolite_id] if product.metabolite.structure_id: part.specie.structure = product.metabolite.structure._value_inchi if product.compartment_id: if product.compartment.name not in compartments: compartments[product.compartment.name] = data_model.Compartment(name=product.compartment.name) part.compartment = compartments[product.compartment.name] reaction.participants.append(part) for modifier in modifiers: part = data_model.ReactionParticipant(coefficient=0) if modifier.metabolite_id not in species: species[modifier.metabolite_id] = data_model.Specie(name=modifier.metabolite.metabolite_name) part.specie = species[modifier.metabolite_id] if modifier.metabolite.structure_id: part.specie.structure = modifier.metabolite.structure._value_inchi if modifier.compartment_id: if modifier.compartment.name not in compartments: compartments[modifier.compartment.name] = data_model.Compartment(name=modifier.compartment.name) part.compartment = compartments[modifier.compartment.name] reaction.participants.append(part) metadata = self.metadata_dump(law) for parameter in law.parameter: if parameter.value is None: continue observable = data_model.Observable( interaction=reaction, property=parameter.observed_name, ) if parameter.metabolite_id: observable.specie = species[parameter.metabolite_id] # if parameter.compartment: # observable.compartment = data_model.Compartment( # id=parameter.compartment.name, # ) observed_vals.append(data_model.ObservedValue( metadata=metadata, observable=observable, value=parameter.value, error=parameter.error, units=parameter.units, )) return observed_vals
def get_observable_interactions(self, protein_subunit): """ Get known protein interactions that were observed for a given subunit Args: protein_subunit (:obj:`models.ProteinSubunit`): subunit to find interactions for Returns: :obj:`list` of :obj:`data_model.ObservedInteraction`: list of Observed Protein Interactions """ interact = self.get_interaction_by_subunit( protein_subunit.uniprot_id).all() observed_interaction = [] for item in interact: participants = [] for participant, protein in [(item.type_a, item.protein_a), (item.type_b, item.protein_b)]: if participant == None: specie = None if participant == 'protein': prot = self.data_source.session.query( models.ProteinSubunit).filter_by( uniprot_id=protein).first() if prot: specie = data_model.ProteinSpecie( name=prot.uniprot_id, uniprot_id=prot.uniprot_id, entrez_id=prot.entrez_id, gene_name=prot.gene_name, length=prot.length, mass=prot.mass, sequence=prot.canonical_sequence) elif participant == 'peptide': specie = data_model.PolymerSpecie(name=protein, sequence=protein) participants.append(specie) metadata = self.metadata_dump(item) resource = [ data_model.Resource(namespace=source.namespace, id=source._id) for source in item._metadata.resource ] interaction = data_model.SpecieInteraction( specie_a=participants[0], specie_b=participants[1], stoichiometry_a=item.stoich_a, stoichiometry_b=item.stoich_b, loc_a=item.loc_a, loc_b=item.loc_b, cross_references=resource, name=item.name, confidence=item.confidence, type_a=item.type_a, type_b=item.type_b, interaction_type=item.interaction_type) observed_interaction.append( data_model.ObservedInteraction(interaction=interaction, metadata=metadata)) return observed_interaction
def test_ReactionSimilarityFilter(self): atp_structure = ( 'InChI=1S/C10H16N5O13P3/c11-8-5-9(13-2-12-8)15(3-14-5)10-7(17)6(16)4(26-10)1-25-30(21,22)28-31(23,24)27-29(18,19)20' '/h2-4,6-7,10,16-17H,1H2,(H,21,22)(H,23,24)(H2,11,12,13)(H2,18,19,20)/p-4/t4-,6-,7-,10-/m1/s1' ) h2o_structure = 'InChI=1S/H2O/h1H2' adp_structure = ( 'InChI=1S/C10H15N5O10P2/c11-8-5-9(13-2-12-8)15(3-14-5)10-7(17)6(16)4(24-10)1-23-27(21,22)25-26(18,19)20' '/h2-4,6-7,10,16-17H,1H2,(H,21,22)(H2,11,12,13)(H2,18,19,20)/p-3/t4-,6-,7-,10-/m1/s1' ) pi_structure = 'InChI=1S/H3O4P/c1-5(2,3)4/h(H3,1,2,3,4)/p-2' h_structure = 'InChI=1S/p+1/i/hH' def get_reaction(pi_structure=pi_structure, ec='1.1.1.1'): return data_model.Reaction( participants=[ data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=atp_structure)), data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=h2o_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=adp_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=pi_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=h_structure)), ], cross_references=[ data_model.Resource(namespace='ec-code', id=ec) ]) rxn = get_reaction() f = data_query.ReactionSimilarityFilter(min_ec_level=3, scale=1) # same participants ov = data_model.ObservedValue(observable=data_model.Observable(interaction=get_reaction())) numpy.testing.assert_almost_equal(f.score(rxn, ov), 1, decimal=3) # similiar participants ov = data_model.ObservedValue(observable=data_model.Observable(interaction=get_reaction(pi_structure='InChI=1S/H3O4P/c1-5(2,3)4'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), 1, decimal=3) # different participants, same 4-digit EC ov = data_model.ObservedValue(observable=data_model.Observable(interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), math.exp(-1), decimal=3) # different participants, same 3-digit EC ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1.2'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), math.exp(-2), decimal=3) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), math.exp(-2), decimal=3) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1.'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), math.exp(-2), decimal=3) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1.-'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), math.exp(-2), decimal=3) # different participants, same 2-digit EC ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.2.1'))) numpy.testing.assert_almost_equal(f.score(rxn, ov), -1, decimal=3) # target reaction only has 3 digits rxn_1_1_1 = get_reaction(ec='1.1.1') rxn_1_1_1_1 = get_reaction(ec='1.1.1.1') f1 = data_query.ReactionSimilarityFilter(min_ec_level=3, scale=1) f2 = data_query.ReactionSimilarityFilter(min_ec_level=3, scale=1) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1'))) numpy.testing.assert_almost_equal(f1.score(rxn_1_1_1, ov), math.exp(-2), decimal=3) numpy.testing.assert_almost_equal(f2.score(rxn_1_1_1_1, ov), math.exp(-2), decimal=3) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.1.1'))) numpy.testing.assert_almost_equal(f1.score(rxn_1_1_1, ov), math.exp(-2), decimal=3) numpy.testing.assert_almost_equal(f2.score(rxn_1_1_1_1, ov), math.exp(-1), decimal=3) ov = data_model.ObservedValue(observable=data_model.Observable( interaction=get_reaction(pi_structure='InChI=1S/H4O4P/c1-5(2,3)4', ec='1.1.2.1'))) numpy.testing.assert_almost_equal(f1.score(rxn_1_1_1, ov), -1, decimal=3) numpy.testing.assert_almost_equal(f2.score(rxn_1_1_1_1, ov), -1, decimal=3) # reverse direction, different numbers of reactants/products f = data_query.ReactionSimilarityFilter(min_ec_level=3, scale=1) for_rxn = get_reaction() rev_rxn = get_reaction() for part in rev_rxn.participants: part.coefficient = -1 * part.coefficient ov = data_model.ObservedValue(observable=data_model.Observable(interaction=for_rxn)) self.assertEqual(f.score(for_rxn, ov), 1.) ov = data_model.ObservedValue(observable=data_model.Observable(interaction=rev_rxn)) self.assertEqual(f.score(for_rxn, ov), -1.) # reverse direction, same numbers of reactants/products for_rxn = data_model.Reaction( participants=[ data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=atp_structure)), data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=adp_structure)), ], cross_references=[ data_model.Resource(namespace='ec-code', id='1.1.1.1') ]) rev_rxn = data_model.Reaction( participants=[ data_model.ReactionParticipant(coefficient=1, specie=data_model.Specie(structure=atp_structure)), data_model.ReactionParticipant(coefficient=-1, specie=data_model.Specie(structure=adp_structure)), ], cross_references=[ data_model.Resource(namespace='ec-code', id='1.1.1.1') ]) ov = data_model.ObservedValue(observable=data_model.Observable(interaction=for_rxn)) self.assertEqual(f.score(for_rxn, ov), 1.) ov = data_model.ObservedValue(observable=data_model.Observable(interaction=rev_rxn)) self.assertEqual(f.score(for_rxn, ov), -1.)
def _port(self, metabolite): structure = metabolite.structure._value_inchi if metabolite.structure else None references = [data_model.Resource(namespace=item.namespace, id=item._id) for item in metabolite._metadata.resource] return data_model.Specie(id=metabolite.metabolite_id, name=metabolite.metabolite_name, structure = structure, cross_references = references)
def test_get_ec_number(self): rxn = data_model.Reaction(cross_references=[ data_model.Resource(namespace='xx', id='yy', relevance=20., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource(namespace='ec-code', id='1.1.1.1', relevance=20., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource(namespace='ec-code', id='1.1.1.2', relevance=30., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource(namespace='ec-code', id='1.1.1.3', relevance=10., assignment_method=data_model. ResourceAssignmentMethod.predicted), ]) self.assertEqual(rxn.get_ec_number(), '1.1.1.2') self.assertEqual(rxn.get_ec_numbers(), rxn.cross_references[1:]) self.assertEqual(rxn.get_manual_ec_numbers(), []) self.assertEqual(rxn.get_predicted_ec_numbers(), rxn.cross_references[1:]) rxn = data_model.Reaction(cross_references=[ data_model.Resource( namespace='ec-code', id='1.1.1.1', relevance=20., assignment_method=data_model.ResourceAssignmentMethod.manual), data_model.Resource(namespace='ec-code', id='1.1.1.2', relevance=30., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource(namespace='ec-code', id='1.1.1.3', relevance=10., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource(namespace='xx', id='yy', relevance=20., assignment_method=data_model. ResourceAssignmentMethod.predicted), ]) self.assertEqual(rxn.get_ec_number(), '1.1.1.1') self.assertEqual(rxn.get_ec_numbers(), rxn.cross_references[0:-1]) self.assertEqual(rxn.get_manual_ec_numbers(), rxn.cross_references[0:1]) self.assertEqual(rxn.get_predicted_ec_numbers(), rxn.cross_references[1:3]) rxn = data_model.Reaction(cross_references=[ data_model.Resource( namespace='ec-code', id='1.1.1.1', relevance=20., assignment_method=data_model.ResourceAssignmentMethod.manual), data_model.Resource(namespace='ec-code', id='1.1.1.2', relevance=30., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource( namespace='ec-code', id='1.1.1.3', relevance=10., assignment_method=data_model.ResourceAssignmentMethod.manual), ]) self.assertRaises(ValueError, rxn.get_ec_number) rxn = data_model.Reaction(cross_references=[ data_model.Resource( namespace='ec2', id='1.1.1.1', relevance=20., assignment_method=data_model.ResourceAssignmentMethod.manual), data_model.Resource(namespace='ec-code', id='1.1.1.2', relevance=30., assignment_method=data_model. ResourceAssignmentMethod.predicted), data_model.Resource( namespace='ec2', id='1.1.1.3', relevance=10., assignment_method=data_model.ResourceAssignmentMethod.manual), ]) self.assertEqual(rxn.get_ec_number(), '1.1.1.2') rxn = data_model.Reaction(cross_references=[]) self.assertEqual(rxn.get_ec_number(), '')