def f(session): log_it('validate_genes', 'BEGIN') all_gene_names = set() for task in tasks: all_gene_names.update([gene_name.upper() for gene_name in task.gene_names]) genes = validate_genes(all_gene_names, session) log_it('validate_genes', 'SUCCESS') log_it('move_reftemp_to_ref', 'BEGIN') #If some of the gene names are aliases or are just not gene names, throw an exception. if len(genes['aliases']) > 0 or len(genes['not_genes']) > 0: raise GeneNamesNotFountException(genes['alias_message'], genes['not_genes_message']) #Move reftemp to ref table. Raise an exception if something goes wrong. moved = move_reftemp_to_ref(pmid, session) if not moved: raise ReferenceNotMovedException(pmid) log_it('move_reftemp_to_ref', 'SUCCESS') log_it('associate', 'BEGIN') #Associate reference with LitGuide and RefCuration objects. Raise an exception if something goes wrong. associated = associate(pmid, genes['features'], tasks, session) if not associated: raise AssociateException(pmid) return True log_it('associate', 'SUCCESS')
def test_validate_genes(self): gene_names = ['YAL002W', 'CEN1', 'SPO7', 'YAL016C-B', 'YAL009W'] feature_ids = [6102, 2899, 6347, 7398, 6347] name_to_feature = self.model.execute(validate_genes(gene_names)) self.assertEqual(len(gene_names), len(name_to_feature)) for i in range(0, len(gene_names)): self.assertEqual(name_to_feature[gene_names[i]].id, feature_ids[i])
def f(session): pubmed_id = 23105524 gene_names = ['ACT1', 'CEN1', 'SPO7', 'YAL016C-B', 'YAL009W'] from model_old_schema.reference import Reference move_reftemp_to_ref(pubmed_id, session=session) name_to_feature = self.model.execute(validate_genes(gene_names)) tasks = [Task(TaskType.HIGH_PRIORITY, None, "Comment"), Task(TaskType.DELAY, None, "Comment"), Task(TaskType.HTP_PHENOTYPE_DATA, None, "Comment"), Task(TaskType.OTHER_HTP_DATA, None, "Comment"), Task(TaskType.CLASSICAL_PHENOTYPE_INFORMATION, ['ACT1'], "Comment"), Task(TaskType.GO_INFORMATION, ['ACT1'], "Comment"), Task(TaskType.HEADLINE_INFORMATION, ['YAL009W', 'YAL016C-B'], "Comment"), Task(TaskType.ADDITIONAL_LITERATURE, None, "Comment"), Task(TaskType.REVIEWS, None, "Comment") ] result = associate(pubmed_id, name_to_feature, tasks, session=session) self.assertTrue(result) curations = get_first(Reference, session=session, pubmed_id=pubmed_id).curations lit_guides = get_first(Reference, session=session, pubmed_id=pubmed_id).litGuides self.assertEqual(len(curations), 9) for curation in curations: self.assertTrue(curation.comment is not None) if curation.task == 'Gene Link': self.assertTrue(False, 'The two Tasks with name Gene Link: ADD_TO_DATABASE and REVIEWS have no genes. They should not have curaitons.') self.assertEqual(len(lit_guides), 6) for lit_guide in lit_guides: if curation.task == 'Reviews': self.assertEqual(len(lit_guide.features), 0)
def f(session): all_gene_names = set() for task in tasks: all_gene_names.update(task.gene_names) name_to_feature = validate_genes(all_gene_names, session) #If we don't get back as many features as we have gene names, find the bad ones and raise an exception. if len(name_to_feature) < len(all_gene_names): bad_gene_names = set(all_gene_names) - set(name_to_feature.keys()) raise GeneNamesNotFountException(bad_gene_names) #Move reftemp to ref table. Raise an exception if something goes wrong. moved = move_reftemp_to_ref(pmid, session) if not moved: raise ReferenceNotMovedException(pmid) #Associate reference with LitGuide and RefCuration objects. Raise an exception if something goes wrong. associated = associate(pmid, name_to_feature, tasks, session) if not associated: raise AssociateException(pmid) return True