def set_sister_species_sentence(dm: WBDataManager, conf_parser: GenedescConfigParser, sister_sp_fullname, sister_df: WBDataManager, species, organism, gene_desc: GeneDescription, gene: Gene): best_ortholog = dm.get_best_orthologs_for_gene( gene_desc.gene_id, orth_species_full_name=[sister_sp_fullname], sister_species_data_fetcher=sister_df, ecode_priority_list=[ "EXP", "IDA", "IPI", "IMP", "IGI", "IEP", "HTP", "HDA", "HMP", "HGI", "HEP" ])[0][0] if not best_ortholog[0].startswith("WB:"): best_ortholog[0] = "WB:" + best_ortholog[0] sister_sentences_generator = OntologySentenceGenerator( gene_id=best_ortholog[0], module=Module.GO, data_manager=sister_df, config=conf_parser, humans=sister_sp_fullname == "H**o sapiens", limit_to_group="EXPERIMENTAL") sister_sp_module_sentences = sister_sentences_generator.get_module_sentences( aspect='P', qualifier="involved_in", merge_groups_with_same_prefix=True, keep_only_best_group=True) if sister_sp_module_sentences.contains_sentences(): gene_desc.set_or_extend_module_description_and_final_stats( module=Module.SISTER_SP, description="in " + species[species[organism]["main_sister_species"]]["name"] + ", " + best_ortholog[1] + " " + sister_sp_module_sentences.get_description())
def test_expression_the_cell_renaming_to_widely(self): self.df.load_ontology_from_file( ontology_type=DataType.EXPR, ontology_url=self.df.expression_ontology_url, ontology_cache_path=self.df.expression_ontology_cache_path, config=self.conf_parser) self.df.load_associations_from_file( associations_type=DataType.EXPR, associations_url=self.df.expression_associations_url, associations_cache_path=self.df.expression_associations_cache_path, config=self.conf_parser) gene_desc = GeneDescription(gene_id="WB:WBGene00007352", gene_name="cdc-48.1", add_gene_name=False) expr_sentence_generator = OntologySentenceGenerator( gene_id=gene_desc.gene_id, module=Module.EXPRESSION, data_manager=self.df, config=self.conf_parser) expression_module_sentences = expr_sentence_generator.get_module_sentences( config=self.conf_parser, aspect='A', qualifier="Verified", merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=expression_module_sentences, module=Module.EXPRESSION) self.assertTrue("is expressed widely" in gene_desc.description)
def set_information_poor_sentence(orth_fullnames: List[str], selected_orthologs, ensembl_hgnc_ids_map, conf_parser: GenedescConfigParser, human_df_agr: DataManager, gene_desc: GeneDescription, dm: WBDataManager, gene: Gene): if len(orth_fullnames) == 1 and orth_fullnames[0] == "H**o sapiens": best_orth = get_best_human_ortholog_for_info_poor(selected_orthologs, ensembl_hgnc_ids_map, conf_parser.get_annotations_priority(module=Module.GO), human_df_agr, config=conf_parser) if best_orth: if not best_orth.startswith("RGD:"): best_orth = "RGD:" + best_orth human_go_sent_generator = OntologySentenceGenerator(gene_id=best_orth, module=Module.GO, data_manager=human_df_agr, config=conf_parser, humans=False, limit_to_group="EXPERIMENTAL") human_func_module_sentences = human_go_sent_generator.get_module_sentences( config=conf_parser, aspect='F', merge_groups_with_same_prefix=True, keep_only_best_group=True) human_func_sent = human_func_module_sentences.get_description() if human_func_sent: gene_desc.set_or_extend_module_description_and_final_stats( module=Module.INFO_POOR_HUMAN_FUNCTION, description="human " + human_df_agr.go_associations.subject_label_map[ best_orth] + " " + human_func_sent) protein_domains = dm.protein_domains[gene_desc.gene_id[3:]] if protein_domains: dom_word = "domain" if len(protein_domains) > 1: dom_word = "domains" gene_desc.set_or_extend_module_description_and_final_stats( module=Module.PROTEIN_DOMAIN, description="is predicted to encode a protein with the following " + dom_word + ": " + concatenate_words_with_oxford_comma([ptdom[1] if ptdom[1] != "" else ptdom[0] for ptdom in protein_domains]))
def set_expression_module(df: DataManager, conf_parser: GenedescConfigParser, gene_desc: GeneDescription, gene: Gene): expr_sentence_generator = OntologySentenceGenerator(gene_id=gene.id, module=Module.EXPRESSION, data_manager=df, config=conf_parser) expression_module_sentences = expr_sentence_generator.get_module_sentences( aspect='A', qualifier="Verified", merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats(module_sentences=expression_module_sentences, module=Module.EXPRESSION) gene_desc.set_or_update_initial_stats(module=Module.EXPRESSION, sent_generator=expr_sentence_generator, module_sentences=expression_module_sentences)
def set_orthology_sentence(dm: WBDataManager, orth_fullnames: List[str], gene_desc: GeneDescription, human_genes_props, api_manager): best_orthologs, selected_orth_name = dm.get_best_orthologs_for_gene(gene_desc.gene_id, orth_species_full_name=orth_fullnames) selected_orthologs = [] if best_orthologs: gene_desc.stats.set_best_orthologs = [orth[0] for orth in best_orthologs] if len(orth_fullnames) == 1 and orth_fullnames[0] == "H**o sapiens": sel_orthologs, orth_sent = generate_ortholog_sentence_wormbase_human(best_orthologs, human_genes_props) selected_orthologs = [orth for orth in best_orthologs if orth[1] in sel_orthologs] else: orth_sent = generate_ortholog_sentence_wormbase_non_c_elegans(best_orthologs, selected_orth_name, api_manager=api_manager) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.ORTHOLOGY, description=orth_sent) return selected_orthologs
def set_alliance_human_orthology_module(orthologs: List[List[str]], gene_desc: GeneDescription, config: GenedescConfigParser, excluded_orthologs: bool = False): """set orthology module for Alliance human orthologs Args: orthologs (List[List[str]]): list of human orthologs, containing gene_id, gene_symbol, and gene_name gene_desc (GeneDescription): the gene description object to update config (GenedescConfigParser): a gene descriptions configuration object excluded_orthologs (bool): whether some of the orthologs have been excluded from the final set. If true, the final sentence will include a prefix to specify that some orthologs have been omitted """ if len(orthologs) > 0: prefix = "human" orthologs_display = sorted(orthologs, key=lambda x: x[2]) if excluded_orthologs or len(orthologs) > 3: orthologs_display = orthologs_display[0:3] prefix = "several human genes including" sentence = "orthologous to " + prefix + " " + concatenate_words_with_oxford_comma( [orth[1] + " (" + orth[2] + ")" if orth[2] else orth[1] for orth in orthologs_display], separator=config.get_terms_delimiter()) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.ORTHOLOGY, description=sentence)
def get_generators(self, data_provider, gd_data_manager, gd_config, json_desc_writer): """Create generators.""" gene_prefix = "" if data_provider == "HUMAN": return_set = Neo4jHelper.run_single_parameter_query( self.get_all_genes_human_query, "RGD") gene_prefix = "RGD:" else: return_set = Neo4jHelper.run_single_parameter_query( self.get_all_genes_query, data_provider) descriptions = [] best_orthologs = self.get_best_orthologs_from_db( data_provider=data_provider) for record in return_set: gene = Gene(id=gene_prefix + record["g.primaryKey"], name=record["g.symbol"], dead=False, pseudo=False) gene_desc = GeneDescription(gene_id=record["g.primaryKey"], gene_name=gene.name, add_gene_name=False, config=gd_config) set_gene_ontology_module(dm=gd_data_manager, conf_parser=gd_config, gene_desc=gene_desc, gene=gene) set_expression_module(df=gd_data_manager, conf_parser=gd_config, gene_desc=gene_desc, gene=gene) set_disease_module(df=gd_data_manager, conf_parser=gd_config, gene_desc=gene_desc, gene=gene, human=data_provider == "HUMAN") if gene.id in best_orthologs: gene_desc.stats.set_best_orthologs = best_orthologs[gene.id][0] set_alliance_human_orthology_module( orthologs=best_orthologs[gene.id][0], excluded_orthologs=best_orthologs[gene.id][1], gene_desc=gene_desc, config=gd_config) if gene_desc.description: descriptions.append({ "genePrimaryKey": gene_desc.gene_id, "geneDescription": gene_desc.description }) json_desc_writer.add_gene_desc(gene_desc) yield [descriptions]
def test_set_or_extend_module_description_and_final_stats(self): gene_desc = GeneDescription(gene_id="FB:FBgn0027655", gene_name="Test gene", add_gene_name=False) go_sent_generator = OntologySentenceGenerator(gene_id="FB:FBgn0027655", module=Module.GO, data_manager=self.df, config=self.conf_parser) sentences = go_sent_generator.get_module_sentences(config=self.conf_parser, aspect='P', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.GO_PROCESS, module_sentences=sentences) self.assertTrue(gene_desc.description, "Is involved in several processes, including axo-dendritic transport, " "establishment of mitotic spindle orientation, and positive regulation " "of extent of heterochromatin assembly") gene_desc = GeneDescription(gene_id="FB:FBgn0027655", gene_name="Test gene", add_gene_name=True) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.GO_PROCESS, module_sentences=sentences) self.assertTrue(gene_desc.description, "Test gene is involved in several processes, including axo-dendritic " "transport, establishment of mitotic spindle orientation, and positive " "regulation of extent of heterochromatin assembly")
def test_trimming_lca(self): self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "ic" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "ic" gene = Gene(id="WB:WBGene00000018", name="abl-1", dead=False, pseudo=False) self.df.load_ontology_from_file(ontology_type=DataType.EXPR, ontology_url="file://" + os.path.join( self.this_dir, "data", "anatomy_ontology.WS274.obo"), ontology_cache_path=os.path.join(self.this_dir, "cache", "anatomy_ontology.WS274.obo"), config=self.conf_parser) logger.info("Loading expression associations from file") self.conf_parser.config["expression_sentences_options"]["max_num_terms"] = 5 self.conf_parser.config["expression_sentences_options"]["trim_min_distance_from_root"]["A"] = 4 self.conf_parser.config["expression_sentences_options"]["remove_children_if_parent_is_present"] = False associations = self.get_associations(gene.id, ["WBbt:0006796", "WBbt:0006759", "WBbt:0005300", "WBbt:0008598", "WBbt:0003681", "WBbt:0005829", "WBbt:0003927", "WBbt:0006751"], ["Verified"], "A", "IDA") self.df.expression_associations = AssociationSetFactory().create_from_assocs(assocs=associations, ontology=self.df.expression_ontology) self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "lca" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "lca" gene_desc_lca = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="abl-1", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_lca, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_lca, gene) gene_desc_lca.stats.calculate_stats(data_manager=self.df) self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "ic" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "ic" set_ic_ontology_struct(ontology=self.df.go_ontology, relations=self.df.go_relations) set_ic_ontology_struct(ontology=self.df.expression_ontology, relations=self.df.expr_relations) gene_desc_ic = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="abl-1", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_ic, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_ic, gene) gene_desc_ic.stats.calculate_stats(data_manager=self.df) self.assertTrue(gene_desc_lca.stats.coverage_percentage >= gene_desc_ic.stats.coverage_percentage, "1") self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "lca" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "lca" gene = Gene(id="WB:WBGene00000022", name="aat-1", dead=False, pseudo=False) associations = self.get_associations(gene.id, ["WBbt:0005828", "WBbt:0006751", "WBbt:0005439", "WBbt:0005788", "WBbt:0006749", "WBbt:0005300", "WBbt:0005735", "WBbt:0005747", "WBbt:0005772", "WBbt:0005776", "WBbt:0005812", "WBbt:0005741", "WBbt:0005799", "WBbt:0003681"], ["Verified"], "A", "IDA") self.df.expression_associations = AssociationSetFactory().create_from_assocs( assocs=associations, ontology=self.df.expression_ontology) gene_desc_lca = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="aat-1", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_lca, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_lca, gene) gene_desc_lca.stats.calculate_stats(data_manager=self.df) self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "ic" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "ic" gene_desc_ic = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="aat-1", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_ic, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_ic, gene) gene_desc_ic.stats.calculate_stats(data_manager=self.df) self.assertTrue(gene_desc_lca.stats.coverage_percentage >= gene_desc_ic.stats.coverage_percentage, "2") self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "lca" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "lca" gene = Gene(id="WB:WBGene00000044", name="acr-5", dead=False, pseudo=False) associations = self.get_associations(gene.id, ['WBbt:0003679', 'WBbt:0006759', 'WBbt:0005336', 'WBbt:0006751', 'WBbt:0005300', 'WBbt:0005274', 'WBbt:0005741', 'WBbt:0006749', 'WBbt:0005735'], ["Verified"], "A", "IDA") self.df.expression_associations = AssociationSetFactory().create_from_assocs( assocs=associations, ontology=self.df.expression_ontology) gene_desc_lca = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="acr-5", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_lca, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_lca, gene) gene_desc_lca.stats.calculate_stats(data_manager=self.df) self.conf_parser.config["go_sentences_options"]["trimming_algorithm"] = "ic" self.conf_parser.config["expression_sentences_options"]["trimming_algorithm"] = "ic" gene_desc_ic = GeneDescription(gene_id=gene.id, config=self.conf_parser, gene_name="acr-5", add_gene_name=False) set_gene_ontology_module(dm=self.df, conf_parser=self.conf_parser, gene_desc=gene_desc_ic, gene=gene) set_expression_module(self.df, self.conf_parser, gene_desc_ic, gene) gene_desc_ic.stats.calculate_stats(data_manager=self.df) self.assertTrue(gene_desc_lca.stats.coverage_percentage >= gene_desc_ic.stats.coverage_percentage, "3")
def main(): parser = argparse.ArgumentParser( description="Generate gene descriptions for wormbase") parser.add_argument("-c", "--config-file", metavar="config_file", dest="config_file", type=str, default="config.yml", help="configuration file. Default ./config.yaml") parser.add_argument( "-C", "--use-cache", dest="use_cache", action="store_true", default=False, help= "Use cached source files from cache_location specified in config file. Download them from " "raw_file_source (configured in config file) if not yet cached") parser.add_argument( "-l", "--log-file", metavar="log_file", dest="log_file", type=str, default=None, help="path to the log file to generate. Default ./genedescriptions.log" ) parser.add_argument( "-L", "--log-level", dest="log_level", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help="set the logging level") parser.add_argument("-t", "--textpressoapi-token", metavar="textpresso_token", dest="textpresso_token", type=str, help="Texpresso api token") parser.add_argument("-o", "--output-formats", metavar="output_formats", dest="output_formats", type=str, nargs="+", default=["ace", "txt", "json", "tsv"], help="file formats to generate. Accepted values " "are: ace, txt, json, tsv") args = parser.parse_args() conf_parser = GenedescConfigParser(args.config_file) logging.basicConfig(filename=args.log_file, level=args.log_level, format='%(asctime)s - %(name)s - %(levelname)s:' '%(message)s', force=True) logger = logging.getLogger("WB Gene Description Pipeline") organisms_list = conf_parser.get_wb_organisms_to_process() human_genes_props = DataManager.get_human_gene_props() api_manager = APIManager(textpresso_api_token=args.textpresso_token) for organism in organisms_list: logger.info("Processing organism " + organism) species = conf_parser.get_wb_organisms_info() dm, sister_df, df_agr = load_data(organism=organism, conf_parser=conf_parser) desc_writer = DescriptionsWriter() desc_writer.overall_properties.species = organism desc_writer.overall_properties.release_version = conf_parser.get_wb_release( )[0:-1] + str(int(conf_parser.get_wb_release()[-1]) + 1) desc_writer.overall_properties.date = datetime.date.today().strftime( "%B %d, %Y") for gene in dm.get_gene_data(): logger.debug("Generating description for gene " + gene.name) gene_desc = GeneDescription(gene_id=gene.id, config=conf_parser, gene_name=gene.name, add_gene_name=False) selected_orthologs, orth_sent = get_best_orthologs_and_sentence( dm=dm, orth_fullnames=dm.orth_fullnames, human_genes_props=human_genes_props, gene_desc=gene_desc, api_manager=api_manager, config=conf_parser) set_gene_ontology_module(dm=dm, conf_parser=conf_parser, gene_desc=gene_desc, gene=gene) set_tissue_expression_sentence(dm=dm, gene=gene, conf_parser=conf_parser, gene_desc=gene_desc) if not gene_desc.description: set_expression_cluster_sentence(dm=dm, conf_parser=conf_parser, gene_desc=gene_desc, gene=gene, api_manager=api_manager) set_disease_module(df=dm, conf_parser=conf_parser, gene=gene, gene_desc=gene_desc) if not gene_desc.go_description: set_information_poor_sentence( orth_fullnames=dm.orth_fullnames, selected_orthologs=selected_orthologs, conf_parser=conf_parser, human_df_agr=df_agr, gene_desc=gene_desc, dm=dm, gene=gene) gene_desc.set_or_extend_module_description_and_final_stats( module=Module.ORTHOLOGY, description=orth_sent) if "main_sister_species" in species[organism] and species[organism]["main_sister_species"] and \ dm.get_best_orthologs_for_gene(gene.id, orth_species_full_name=[dm.sister_sp_fullname], sister_species_data_fetcher=sister_df, ecode_priority_list=["EXP", "IDA", "IPI", "IMP", "IGI", "IEP", "HTP", "HDA", "HMP", "HGI", "HEP"])[0]: set_sister_species_sentence( dm=dm, sister_sp_fullname=dm.sister_sp_fullname, sister_df=sister_df, species=species, organism=organism, gene_desc=gene_desc, conf_parser=conf_parser, gene=gene) desc_writer.add_gene_desc(gene_desc) logger.info("All genes processed for " + organism) date_prefix = datetime.date.today().strftime("%Y%m%d") if "json" in args.output_formats: logger.info("Writing descriptions to json") desc_writer.write_json(os.path.join( conf_parser.get_out_dir(), date_prefix + "_" + organism + ".json"), include_single_gene_stats=True, data_manager=dm) if "txt" in args.output_formats: logger.info("Writing descriptions to txt") desc_writer.write_plain_text( os.path.join(conf_parser.get_out_dir(), date_prefix + "_" + organism + ".txt")) if "tsv" in args.output_formats: logger.info("Writing descriptions to tsv") desc_writer.write_tsv( os.path.join(conf_parser.get_out_dir(), date_prefix + "_" + organism + ".tsv")) if "ace" in args.output_formats: logger.info("Writing descriptions to ace") curators = ["WBPerson324", "WBPerson37462"] release_version = conf_parser.get_wb_release() desc_writer.write_ace( os.path.join(conf_parser.get_out_dir(), date_prefix + "_" + organism + ".ace"), curators, release_version)
def set_expression_cluster_sentence(dm: WBDataManager, conf_parser: GenedescConfigParser, gene_desc: GeneDescription, gene: Gene, api_manager: APIManager): expr_sentence_generator = OntologySentenceGenerator( gene_id=gene.id, module=Module.EXPRESSION, data_manager=dm, config=conf_parser) ec_gene_id = gene_desc.gene_id[3:] ec_anatomy_studies = dm.get_expression_cluster_feature( gene_id=ec_gene_id, expression_cluster_type=ExpressionClusterType.ANATOMY, feature=ExpressionClusterFeature.STUDIES) ec_anatomy_terms = dm.get_expression_cluster_feature( gene_id=ec_gene_id, feature=ExpressionClusterFeature.TERMS, expression_cluster_type=ExpressionClusterType.ANATOMY) if dm.expression_ontology is not None: expression_enriched_module_sentences = expr_sentence_generator.get_module_sentences( aspect='A', qualifier="Enriched", merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats( module=Module.EXPRESSION_CLUSTER_ANATOMY, description=expression_enriched_module_sentences.get_description(), additional_postfix_terms_list=ec_anatomy_studies, additional_postfix_final_word="studies", use_single_form=True) elif ec_anatomy_terms: gene_desc.set_or_extend_module_description_and_final_stats( module=Module.EXPRESSION_CLUSTER_ANATOMY, description="is enriched in " + concatenate_words_with_oxford_comma( ec_anatomy_terms, separator=conf_parser.get_terms_delimiter()) + " based on", additional_postfix_terms_list=ec_anatomy_studies, additional_postfix_final_word="studies", use_single_form=True) ec_molreg_terms = dm.get_expression_cluster_feature( gene_id=ec_gene_id, expression_cluster_type=ExpressionClusterType.MOLREG, feature=ExpressionClusterFeature.TERMS) ec_molreg_studies = dm.get_expression_cluster_feature( gene_id=ec_gene_id, feature=ExpressionClusterFeature.STUDIES, expression_cluster_type=ExpressionClusterType.MOLREG) ec_genereg_terms = dm.get_expression_cluster_feature( gene_id=ec_gene_id, expression_cluster_type=ExpressionClusterType.GENEREG, feature=ExpressionClusterFeature.TERMS) ec_genereg_studies = dm.get_expression_cluster_feature( gene_id=ec_gene_id, feature=ExpressionClusterFeature.STUDIES, expression_cluster_type=ExpressionClusterType.GENEREG) if ec_genereg_terms: several_word = "" if len(ec_genereg_terms) > 3: t_p = [ t_p for t_p in sorted( [[term, api_manager.get_textpresso_popularity(term)] for term in ec_genereg_terms], key=lambda x: (x[1], x[0][1]), reverse=True) ] ec_genereg_terms = [term for term, popularity in t_p[0:3]] several_word = "several genes including " gene_desc.set_or_extend_module_description_and_final_stats( module=Module.EXPRESSION_CLUSTER_GENE, description="is affected by " + several_word + concatenate_words_with_oxford_comma( ec_genereg_terms, separator=conf_parser.get_terms_delimiter()) + " based on", additional_postfix_terms_list=ec_genereg_studies, additional_postfix_final_word="studies", use_single_form=True) if ec_molreg_terms: several_word = "" if len(ec_molreg_terms) > 3: several_word = num2words( len(ec_molreg_terms)) + " chemicals including " gene_desc.set_or_extend_module_description_and_final_stats( module=Module.EXPRESSION_CLUSTER_MOLECULE, description="is affected by " + several_word + concatenate_words_with_oxford_comma( ec_molreg_terms[0:3], separator=conf_parser.get_terms_delimiter()) + " based on", additional_postfix_terms_list=ec_molreg_studies, additional_postfix_final_word="studies", use_single_form=True)
def set_disease_module(df: DataManager, conf_parser: GenedescConfigParser, gene_desc: GeneDescription, gene: Gene, human: bool = False): do_sentence_exp_generator = OntologySentenceGenerator(gene_id=gene.id, module=Module.DO_EXPERIMENTAL, data_manager=df, config=conf_parser, limit_to_group="EXPERIMENTAL", humans=human) disease_exp_module_sentences = do_sentence_exp_generator.get_module_sentences( aspect='D', merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.DO_EXPERIMENTAL, module_sentences=disease_exp_module_sentences) do_sentence_bio_generator = OntologySentenceGenerator(gene_id=gene.id, module=Module.DO_BIOMARKER, data_manager=df, config=conf_parser, limit_to_group="BIOMARKER", humans=human) disease_bio_module_sentences = do_sentence_bio_generator.get_module_sentences( aspect='D', merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.DO_BIOMARKER, module_sentences=disease_bio_module_sentences) do_via_orth_sentence_generator = OntologySentenceGenerator( gene_id=gene.id, module=Module.DO_ORTHOLOGY, data_manager=df, config=conf_parser, humans=human) disease_via_orth_module_sentences = do_via_orth_sentence_generator.get_module_sentences( aspect='D', merge_groups_with_same_prefix=True, keep_only_best_group=False) gene_desc.set_or_extend_module_description_and_final_stats(module=Module.DO_ORTHOLOGY, module_sentences=disease_via_orth_module_sentences) gene_desc.set_or_update_initial_stats(module=Module.DO_EXPERIMENTAL, sent_generator=do_sentence_exp_generator, module_sentences=disease_exp_module_sentences) gene_desc.set_or_update_initial_stats(module=Module.DO_BIOMARKER, sent_generator=do_sentence_bio_generator, module_sentences=disease_bio_module_sentences) gene_desc.set_or_update_initial_stats(module=Module.DO_ORTHOLOGY, sent_generator=do_via_orth_sentence_generator, module_sentences=disease_via_orth_module_sentences)
def set_gene_ontology_module(dm: DataManager, conf_parser: GenedescConfigParser, gene_desc: GeneDescription, gene: Gene): go_sent_generator_exp = OntologySentenceGenerator(gene_id=gene.id, module=Module.GO, data_manager=dm, config=conf_parser, limit_to_group="EXPERIMENTAL") go_sent_generator = OntologySentenceGenerator(gene_id=gene.id, module=Module.GO, data_manager=dm, config=conf_parser) # Generate sentences with experimental annotations only func_module_sentences_contributes_to = go_sent_generator_exp.get_module_sentences( aspect='F', qualifier='contributes_to', merge_groups_with_same_prefix=True, keep_only_best_group=True) func_module_sentences_noq = go_sent_generator_exp.get_module_sentences( aspect='F', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) func_module_sentences_enables = go_sent_generator_exp.get_module_sentences( aspect='F', qualifier='enables', merge_groups_with_same_prefix=True, keep_only_best_group=True) # If experimental sentences are all empty, generate sentences with all annotations if not func_module_sentences_contributes_to.contains_sentences() and \ not func_module_sentences_noq.contains_sentences() and \ not func_module_sentences_enables.contains_sentences(): func_module_sentences_contributes_to = go_sent_generator.get_module_sentences( aspect='F', qualifier='contributes_to', merge_groups_with_same_prefix=True, keep_only_best_group=True) func_module_sentences_noq = go_sent_generator.get_module_sentences( aspect='F', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) func_module_sentences_enables = go_sent_generator.get_module_sentences( aspect='F', qualifier='enables', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats(module_sentences=func_module_sentences_noq, module=Module.GO_FUNCTION) gene_desc.set_or_extend_module_description_and_final_stats(module_sentences=func_module_sentences_enables, module=Module.GO_FUNCTION) gene_desc.set_or_extend_module_description_and_final_stats(module_sentences=func_module_sentences_contributes_to, module=Module.GO_FUNCTION) proc_module_sentences_noq = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_inv = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='involved_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_pos = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='acts_upstream_of_positive_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_neg = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='acts_upstream_of_negative_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with_pos = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within_positive_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with_neg = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within_negative_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with = go_sent_generator_exp.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within', merge_groups_with_same_prefix=True, keep_only_best_group=True) if not proc_module_sentences_noq.contains_sentences() and \ not proc_module_sentences_inv.contains_sentences() and \ not proc_module_sentences_acts_pos.contains_sentences() and \ not proc_module_sentences_acts_neg.contains_sentences() and \ not proc_module_sentences_acts_with_pos.contains_sentences() and \ not proc_module_sentences_acts_with_neg.contains_sentences() and \ not proc_module_sentences_acts_with.contains_sentences(): proc_module_sentences_noq = go_sent_generator.get_module_sentences( aspect='P', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_inv = go_sent_generator.get_module_sentences( aspect='P', qualifier='involved_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_pos = go_sent_generator.get_module_sentences( aspect='P', qualifier='acts_upstream_of_positive_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_neg = go_sent_generator.get_module_sentences( aspect='P', qualifier='acts_upstream_of_negative_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with_pos = go_sent_generator.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within_positive_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with_neg = go_sent_generator.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within_negative_effect', merge_groups_with_same_prefix=True, keep_only_best_group=True) proc_module_sentences_acts_with = go_sent_generator.get_module_sentences( aspect='P', qualifier='acts_upstream_of_or_within', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_noq, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_inv, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_acts_pos, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_acts_neg, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_acts_with_pos, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_acts_with_neg, module=Module.GO_PROCESS) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences_acts_with, module=Module.GO_PROCESS) comp_module_sentence_colocalizes_with = go_sent_generator_exp.get_module_sentences( aspect='C', qualifier='colocalizes_with', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_noq = go_sent_generator_exp.get_module_sentences( aspect='C', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_located = go_sent_generator_exp.get_module_sentences( aspect='C', qualifier='located_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_part = go_sent_generator_exp.get_module_sentences( aspect='C', qualifier='part_of', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_active = go_sent_generator_exp.get_module_sentences( aspect='C', qualifier='is_active_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) if not comp_module_sentence_colocalizes_with.contains_sentences() and \ not comp_module_sentences_noq.contains_sentences() and \ not comp_module_sentences_located.contains_sentences() and \ not comp_module_sentences_part.contains_sentences() and \ not comp_module_sentences_active.contains_sentences(): comp_module_sentence_colocalizes_with = go_sent_generator.get_module_sentences( aspect='C', qualifier='colocalizes_with', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_noq = go_sent_generator.get_module_sentences( aspect='C', qualifier='', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_located = go_sent_generator.get_module_sentences( aspect='C', qualifier='located_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_part = go_sent_generator.get_module_sentences( aspect='C', qualifier='part_of', merge_groups_with_same_prefix=True, keep_only_best_group=True) comp_module_sentences_active = go_sent_generator.get_module_sentences( aspect='C', qualifier='is_active_in', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences_noq, module=Module.GO_COMPONENT) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences_located, module=Module.GO_COMPONENT) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences_part, module=Module.GO_COMPONENT) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences_active, module=Module.GO_COMPONENT) gene_desc.set_or_extend_module_description_and_final_stats(module_sentences=comp_module_sentence_colocalizes_with, module=Module.GO_COMPONENT) gene_desc.set_or_update_initial_stats(module=Module.GO_FUNCTION, sent_generator=go_sent_generator, module_sentences=func_module_sentences_contributes_to) gene_desc.set_or_update_initial_stats(module=Module.GO_FUNCTION, sent_generator=go_sent_generator, module_sentences=func_module_sentences_noq) gene_desc.set_or_update_initial_stats(module=Module.GO_FUNCTION, sent_generator=go_sent_generator, module_sentences=func_module_sentences_enables) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_noq) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_inv) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_acts_pos) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_acts_neg) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_acts_with_pos) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_acts_with_neg) gene_desc.set_or_update_initial_stats(module=Module.GO_PROCESS, sent_generator=go_sent_generator, module_sentences=proc_module_sentences_acts_with) gene_desc.set_or_update_initial_stats(module=Module.GO_COMPONENT, sent_generator=go_sent_generator, module_sentences=comp_module_sentence_colocalizes_with) gene_desc.set_or_update_initial_stats(module=Module.GO_COMPONENT, sent_generator=go_sent_generator, module_sentences=comp_module_sentences_noq) gene_desc.set_or_update_initial_stats(module=Module.GO_COMPONENT, sent_generator=go_sent_generator, module_sentences=comp_module_sentences_located) gene_desc.set_or_update_initial_stats(module=Module.GO_COMPONENT, sent_generator=go_sent_generator, module_sentences=comp_module_sentences_part) gene_desc.set_or_update_initial_stats(module=Module.GO_COMPONENT, sent_generator=go_sent_generator, module_sentences=comp_module_sentences_active)
def set_gene_ontology_module(dm: DataManager, conf_parser: GenedescConfigParser, gene_desc: GeneDescription, gene: Gene): go_sent_generator_exp = OntologySentenceGenerator( gene_id=gene.id, module=Module.GO, data_manager=dm, config=conf_parser, limit_to_group="EXPERIMENTAL") go_sent_generator = OntologySentenceGenerator(gene_id=gene.id, module=Module.GO, data_manager=dm, config=conf_parser) contributes_to_module_sentences = go_sent_generator.get_module_sentences( config=conf_parser, aspect='F', qualifier='contributes_to', merge_groups_with_same_prefix=True, keep_only_best_group=True) if contributes_to_module_sentences.contains_sentences(): func_module_sentences = go_sent_generator_exp.get_module_sentences( config=conf_parser, aspect='F', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=func_module_sentences, module=Module.GO_FUNCTION) else: func_module_sentences = go_sent_generator.get_module_sentences( config=conf_parser, aspect='F', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=func_module_sentences, module=Module.GO_FUNCTION) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=contributes_to_module_sentences, module=Module.GO_FUNCTION) proc_module_sentences = go_sent_generator.get_module_sentences( config=conf_parser, aspect='P', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=proc_module_sentences, module=Module.GO_PROCESS) colocalizes_with_module_sentences = go_sent_generator.get_module_sentences( config=conf_parser, aspect='C', qualifier='colocalizes_with', merge_groups_with_same_prefix=True, keep_only_best_group=True) if colocalizes_with_module_sentences.contains_sentences(): comp_module_sentences = go_sent_generator_exp.get_module_sentences( config=conf_parser, aspect='C', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences, module=Module.GO_COMPONENT) else: comp_module_sentences = go_sent_generator.get_module_sentences( config=conf_parser, aspect='C', merge_groups_with_same_prefix=True, keep_only_best_group=True) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=comp_module_sentences, module=Module.GO_COMPONENT) gene_desc.set_or_extend_module_description_and_final_stats( module_sentences=colocalizes_with_module_sentences, module=Module.GO_COMPONENT) gene_desc.set_initial_stats( module=Module.GO_FUNCTION, sentence_generator=go_sent_generator, sentence_generator_exp_only=go_sent_generator_exp) gene_desc.set_initial_stats( module=Module.GO_PROCESS, sentence_generator=go_sent_generator, sentence_generator_exp_only=go_sent_generator_exp) gene_desc.set_initial_stats( module=Module.GO_COMPONENT, sentence_generator=go_sent_generator, sentence_generator_exp_only=go_sent_generator_exp)