@@ -51,8 +51,8 @@ def aliasesBySymbolsFromEnsembl(in_aliases):
5151 aliases_by_symbol = {}
5252 with HashedSVIO (in_aliases ) as reader :
5353 for record in reader :
54- name = record ["Gene name" ]
55- alias = record ["Gene Synonym" ]
54+ name = record ["Gene name" ]. upper ()
55+ alias = record ["Gene Synonym" ]. upper ()
5656 if name not in aliases_by_symbol :
5757 aliases_by_symbol [name ] = [name , alias ]
5858 else :
@@ -76,8 +76,8 @@ def aliasesBySymbolsFromNCBI(in_aliases):
7676 aliases_by_symbol = {}
7777 with HashedSVIO (in_aliases ) as reader :
7878 for record in reader :
79- name = record ["Symbol" ]
80- aliases = record ["Synonyms" ].split ("|" )
79+ name = record ["Symbol" ]. upper ()
80+ aliases = [ elt . upper () for elt in record ["Synonyms" ].split ("|" )]
8181 if name not in aliases_by_symbol :
8282 aliases_by_symbol [name ] = [name ] + aliases
8383 else :
@@ -96,16 +96,18 @@ def annotSymbols(in_annotations):
9696
9797 :param in_annotations: Path to the genes annotations file.
9898 :type in_annotations: str
99- :return: List of genes names used in genes annotations file.
100- :rtype: set
99+ :return: By upper gene name the gene name used in genes annotations file.
100+ :rtype: dict
101101 """
102- annotation_symbols = set ()
102+ annotation_symbols = dict ()
103103 with GTFIO (in_annotations ) as reader :
104104 for record in reader :
105105 if "gene_name" in record .annot :
106- annotation_symbols .add (record .annot ["gene_name" ])
106+ name = record .annot ["gene_name" ]
107+ annotation_symbols [name .upper ()] = name
107108 elif "gene" in record .annot :
108- annotation_symbols .add (record .annot ["gene" ])
109+ name = record .annot ["gene" ]
110+ annotation_symbols [name .upper ()] = name
109111 return annotation_symbols
110112
111113
@@ -115,27 +117,23 @@ def selectAnnotSymbol(gene_symbol, annotation_symbols, aliases_by_symbol):
115117
116118 :param gene_symbol: Gene name.
117119 :type gene_symbol: str
118- :param annotation_symbols: List of genes names known in genes annotations file.
119- :type annotation_symbols: set
120+ :param annotation_symbols: By upper gene name the gene name used in genes annotations file.
121+ :type annotation_symbols: dict
120122 :param aliases_by_symbol: Gene name aliases by symbol.
121123 :type aliases_by_symbol: dict
122124 :return: Alias of the gene symbol used in genes annotations file.
123125 :rtype: str
124126 """
125127 retained_name = None
126- if gene_symbol not in aliases_by_symbol :
127- if gene_symbol .upper () in aliases_by_symbol :
128- gene_symbol = gene_symbol .upper ()
129- elif gene_symbol .replace ("ORF" , "orf" ) in aliases_by_symbol :
130- gene_symbol = gene_symbol .replace ("ORF" , "orf" )
131- aliases = [gene_symbol ]
132- if gene_symbol in aliases_by_symbol :
133- aliases = aliases_by_symbol [gene_symbol ]
128+ uc_symbol = gene_symbol .upper ()
129+ aliases = [uc_symbol ]
130+ if uc_symbol in aliases_by_symbol :
131+ aliases = aliases_by_symbol [uc_symbol ]
134132 for curr_name in aliases :
135133 if curr_name in annotation_symbols :
136- retained_name = curr_name
134+ retained_name = annotation_symbols [ curr_name ]
137135 if retained_name is None :
138- raise Exception ("The gene with aliases {} cannot be found in genes annotations." . format ( aliases ) )
136+ raise Exception (f "The gene with aliases { aliases } cannot be found in genes annotations." )
139137 return retained_name
140138
141139
@@ -195,7 +193,7 @@ def loadChimerdb(db_path, db_version, fusions_by_partners, aliases_by_symbol, an
195193 :param annotation_symbols: List of genes names known in genes annotations file.
196194 :type annotation_symbols: set
197195 """
198- # id Source webSource Fusion_pair H_gene H_chr H_position H_strand T_gene T_chr T_position T_strand Breakpoint_Type Genome_Build_Version PMID Disease Validation Kinase Oncogene Tumor_suppressor Receptor Transcription_Factor ChimerPub ChimerSeq
196+ # id ChimerDB_Type Source webSource Fusion_pair 5Gene_Junction 3Gene_Junction H_gene H_chr H_position H_strand T_gene T_chr T_position T_strand Genomic_breakpoint Exonic_breakpoint Breakpoint_Type Genome_Build_Version PMID Disease Validation Frame Chr_info Kinase Oncogene Tumor_suppressor Receptor Transcription_FactorChimerPub ChimerSeq ChimerSeq+
199197 with HashedSVIO (db_path ) as reader :
200198 for record in reader :
201199 up_gene = None
@@ -239,18 +237,14 @@ def loadCosmic(db_path, db_version, fusions_by_partners, aliases_by_symbol, anno
239237 :param annotation_symbols: List of genes names known in genes annotations file.
240238 :type annotation_symbols: set
241239 """
242- # Sample ID Sample name Primary site Site subtype 1 Site subtype 2 Site subtype 3 Primary histology Histology subtype 1 Histology subtype 2 Histology subtype 3 Fusion ID Translocation Name 5'_CHROMOSOME 5'_GENOME_START_FROM 5'_GENOME_START_TO 5'_GENOME_STOP_FROM 5'_GENOME_STOP_TO 5' _STRAND 3'_CHROMOSOME 3' _GENOME_START_FROM 3'_GENOME_START_TO 3'_GENOME_STOP_FROM 3'_GENOME_STOP_TO 3'_STRAND Fusion type Pubmed_PMID
240+ # SAMPLE_ID SAMPLE_NAME PRIMARY_SITE SITE_SUBTYPE_1 SITE_SUBTYPE_2 SITE_SUBTYPE_3 PRIMARY_HISTOLOGY HISTOLOGY_SUBTYPE_1 HISTOLOGY_SUBTYPE_2 HISTOLOGY_SUBTYPE_3 FUSION_ID TRANSLOCATION_NAME 5'_CHROMOSOME 5'_STRAND 5'_GENE_ID 5'_GENE_NAME 5'_LAST_OBSERVED_EXON 5'_GENOME_START_FROM 5'_GENOME_START_TO 5'_GENOME_STOP_FROM 5'_GENOME_STOP_TO 3'_CHROMOSOME3' _STRAND 3'_GENE_ID 3'_GENE_NAME 3'_FIRST_OBSERVED_EXON 3' _GENOME_START_FROM 3'_GENOME_START_TO 3'_GENOME_STOP_FROM 3'_GENOME_STOP_TO FUSION_TYPE PUBMED_PMID
243241 with HashedSVIO (db_path ) as reader :
244- reader .titles = [elt .upper ().replace (" " , "_" ) for elt in reader .titles ]
245242 for record in reader :
246243 if record ["TRANSLOCATION_NAME" ] != "" :
247244 matches = re .fullmatch (r"ENS.+\((.+)\):.+_ENS.+\((.+)\):.+" , record ["TRANSLOCATION_NAME" ]) # ENST00000324093.4(PLXND1):r.1_2864_ENST00000393238.3(TMCC1):r.918_5992
248245 if matches is None :
249246 log .warning (
250- "Error to parse gene names {} from cosmic (PMID: {})." .format (
251- record ["TRANSLOCATION_NAME" ],
252- record ["PUBMED_PMID" ]
253- )
247+ f"Error to parse gene names { record ['TRANSLOCATION_NAME' ]} from cosmic (PMID: { record ['PUBMED_PMID' ]} )."
254248 )
255249 else :
256250 up_gene , down_gene = matches .groups ()
@@ -333,10 +327,12 @@ def loadMitelman(db_path, db_version, fusions_by_partners, aliases_by_symbol, an
333327 if "," in db_path :
334328 mbca_path , ref_path = db_path .split ("," )
335329 pubmed_by_fusion = pubmedByFusion (ref_path )
336- # MolClin RefNo InvNo Morph Topo Immunology GeneLength GeneShort GeneLong KaryLength KaryShort KaryLong
330+ # MolClin RefNo InvNo Morph Topo Immunology GeneLength GeneShort GeneLong KaryLength KaryShort KaryLong
337331 with HashedSVIO (mbca_path ) as reader :
338- for record in reader :
339- if record ["GeneShort" ] != "" :
332+ for row_idx , record in enumerate (reader ):
333+ if "GeneShort" not in record :
334+ log .warning (f"Invalid record line { row_idx } in { mbca_path } ." )
335+ elif record ["GeneShort" ] != "" :
340336 for fusion in record ["GeneShort" ].split ("," ):
341337 if "/" in fusion :
342338 genes = fusion .replace ("+" , "" ).split ("/" ) # PDRG1/ARF3/RUNX1 => fusion between 3 genes
@@ -348,9 +344,7 @@ def loadMitelman(db_path, db_version, fusions_by_partners, aliases_by_symbol, an
348344 found = True
349345 except Exception :
350346 log .warning (
351- "Error to parse gene names [{}, {}] from Mitelman (PMID: {})." .format (
352- up_gene , down_gene , record ["RefNo" ]
353- )
347+ f"Error to parse gene names [{ up_gene } , { down_gene } ] from Mitelman (PMID: { record ['RefNo' ]} )."
354348 )
355349 if found :
356350 fusion_partners = "{}_@_{}" .format (up_gene , down_gene )
@@ -375,7 +369,7 @@ def pubmedByFusion(in_ref):
375369 :return: Pubmed IDs by fusion partners.
376370 :rtype: dict
377371 """
378- # RefNo TitleLength TitleShort TitleLong Volume Year Journal Text Abbreviation AuthorsLength AuthorsShort AuthorsLong Flag Pubmed
372+ # RefNo TitleLength TitleShort TitleLong Volume Year Journal Text Abbreviation AuthorsLength AuthorsShort AuthorsLong Flag Pubmed
379373 pubmed_by_fusion = {}
380374 with HashedSVIO (in_ref ) as reader :
381375 for record in reader :
@@ -422,16 +416,12 @@ def __call__(self, parser, namespace, values, option_string=None):
422416 for db_arg in values :
423417 if db_arg .count (":" ) != 2 :
424418 raise argparse .ArgumentTypeError (
425- 'Argument "{}" is invalid. The format must be: "MODEL:VERSION:PATH".' .format (
426- db_arg
427- )
419+ f'Argument "{ db_arg } " is invalid. The format must be: "MODEL:VERSION:PATH".'
428420 )
429421 model , version , path = db_arg .split (":" )
430422 if model .lower () not in fct_by_model :
431423 raise argparse .ArgumentTypeError (
432- 'Database model "{}" is invalid. It must be selected in {}.' .format (
433- model , sorted (fct_by_model .keys ())
434- )
424+ f'Database model "{ model } " is invalid. It must be selected in { sorted (fct_by_model .keys ())} .'
435425 )
436426 databases .append ({
437427 "model" : model ,
@@ -451,11 +441,11 @@ def __call__(self, parser, namespace, values, option_string=None):
451441 # Manage parameters
452442 parser = argparse .ArgumentParser (description = 'Write unique known fusions partners database from multiple databases.' )
453443 parser .add_argument ('-v' , '--version' , action = 'version' , version = __version__ )
454- group_input = parser .add_argument_group ('Inputs' ) # Inputs
444+ group_input = parser .add_argument_group ('Inputs' )
455445 group_input .add_argument ('-l' , '--input-aliases' , required = True , help = "Path to the file containing aliases between genes symbols (format: TSV). Each line contains a symbol (Gene name) with one of these aliases (Gene Synonym). This file can be obtain from Ensembl's biomart." )
456446 group_input .add_argument ('-a' , '--input-annotations' , required = True , help = 'Path to the file containing the genes annotations used in analysis (format: GTF).' )
457447 group_input .add_argument ('-d' , '--inputs-databases' , action = InputsDatabases , nargs = '+' , required = True , help = 'Paths to databases format: "model:version:path". Model must be in ["babiceanu", "bodymap", "chimerdb", "cosmic", "mitelman"]. Example: -d cosmic:91:~/cosmic91_fusion.tsv chimerdb:Kb3.0:~/chimerKb.tsv mitelman:2019:~/MBCA.TXT.DATA,~/REF.TXT.DATA.' )
458- group_output = parser .add_argument_group ('Outputs' ) # Outputs
448+ group_output = parser .add_argument_group ('Outputs' )
459449 group_output .add_argument ('-o' , '--output-database' , required = True , help = 'Path to the fusions partners database (format: TSV).' )
460450 args = parser .parse_args ()
461451
@@ -474,4 +464,4 @@ def __call__(self, parser, namespace, values, option_string=None):
474464 log .info ("Load {}:{}" .format (db ["model" ], db ["version" ]))
475465 db ["parser" ](db ["path" ], db ["version" ], fusions_by_partners , aliases_by_symbol , annotation_symbols )
476466 writePartnersDb (args .output_database , fusions_by_partners )
477- log .info ("End of job" )
467+ log .info ("End of job" )
0 commit comments