From 16b18ea559e1b787cda395bbc587ee754707ece3 Mon Sep 17 00:00:00 2001 From: preecej Date: Wed, 2 Apr 2014 00:14:21 +0000 Subject: [PATCH] wip: joining list of projections and prefixing at same time svn path=/; revision=566 --- .../python_singletons/incomparanoid.py | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Personnel/preecej/python_singletons/incomparanoid.py b/Personnel/preecej/python_singletons/incomparanoid.py index 53408b7..18576a6 100755 --- a/Personnel/preecej/python_singletons/incomparanoid.py +++ b/Personnel/preecej/python_singletons/incomparanoid.py @@ -71,7 +71,7 @@ def create_dict_uniprot_map(uniprot_substitution_path) : return dict_uniprot_map #---------------------------------------------------------------------------------------------------------------------- -def create_inp_map(inparanoid_input_path, dict_uniprot_map, projection_prefix) : +def create_inp_map(inparanoid_input_path, dict_uniprot_map) : #---------------------------------------------------------------------------------------------------------------------- """ open the inparanoid file (which is already loci-filtered for curated reference set) and generate a 2-col mapping of PRJ to LOC loci @@ -90,7 +90,7 @@ def create_inp_map(inparanoid_input_path, dict_uniprot_map, projection_prefix) : # swap loc for uniprot, if specified if dict_uniprot_map : os_locus = dict_uniprot_map[os_locus] - prj_locus = (projection_prefix if projection_prefix else "") + cols[1].rsplit("_",1)[0].rsplit(".",1)[0] # remove any isoform suffixes (i.e. '.#', '_T0#') + prj_locus = cols[1].rsplit("_",1)[0].rsplit(".",1)[0] # remove any isoform suffixes (i.e. '.#', '_T0#') if os_locus in dict_inp_map : dict_inp_map[os_locus].add(prj_locus) else : @@ -108,7 +108,7 @@ def create_inp_map(inparanoid_input_path, dict_uniprot_map, projection_prefix) : #---------------------------------------------------------------------------------------------------------------------- -def create_ens_map(filtering_loci_path, ensembl_input_path, rap_map_path, recip_id, dict_uniprot_map, projection_prefix) : +def create_ens_map(filtering_loci_path, ensembl_input_path, rap_map_path, recip_id, dict_uniprot_map) : #---------------------------------------------------------------------------------------------------------------------- """ open the ensemble plants and rap::irgsp mapping files and generate a hash mapping of reference to projected loci where @@ -161,9 +161,9 @@ def create_ens_map(filtering_loci_path, ensembl_input_path, rap_map_path, recip_ # reciprocal identity is >= recip_id%, high confidence if int(cols[2]) >= recip_id and int(cols[3]) >= recip_id and int(cols[4]) == 1 : if os_locus in dict_ens_map : - dict_ens_map[os_locus].add((projection_prefix if projection_prefix else "") + cols[1]) + dict_ens_map[os_locus].add(cols[1]) else : - dict_ens_map[os_locus] = set([(projection_prefix if projection_prefix else "") + cols[1]]) + dict_ens_map[os_locus] = set([cols[1]]) ENS.close() for k, v in dict_ens_map.iteritems() : @@ -281,13 +281,18 @@ def write_reactome_files(dict_map, reactome_gene_protein_path, reactome_projecti accepts a single projection map source and outputs the appropriate reference::projection protein and gene::protein "orthopair" format files, including a projection prefix as needed """ - REACTOME_GENE_PROTEIN_OUT_FILE = open(os.getcwd() + reactome_projection_species + '_gene_protein_mapping.txt','w') - for v in sorted(dict_map.values()) : - # TODO: iterate each values list for 1-to-many individual values - # need to make sure values are unique by putting in temp set as you print - REACTOME_GENE_PROTEIN_OUT_FILE.write(v + "\t" + (projection_prefix if projection_prefix else "") + v) + "\n") + val_set = set() # hold unique protein list + + REACTOME_GENE_PROTEIN_OUT_FILE = open(reactome_gene_protein_path,'w') + REACTOME_PROJECTION_OUT_FILE = open(reactome_projection_path,'w') + for k, v_list in sorted(dict_map.iteritems()) : + REACTOME_PROJECTION_OUT_FILE.write(k + "\t" + " ".join(v_list) + "\n") + for v in v_list : + if v not in val_set : + val_set.add(v) + REACTOME_GENE_PROTEIN_OUT_FILE.write(v + "\t" + (projection_prefix if projection_prefix else "") + v + "\n") REACTOME_GENE_PROTEIN_OUT_FILE.close() - + REACTOME_PROJECTION_OUT_FILE.close() #---------------------------------------------------------------------------------------------------------------------- # main @@ -302,7 +307,7 @@ parser.add_argument('-e', '--ensembl_input_path', help='ensembl compara input fi parser.add_argument('-i', '--inparanoid_input_path', help='inparanoid supercluster input file') parser.add_argument('-m', '--rap_map_path', help='MSU-RAP mapping file') parser.add_argument('-r', '--reciprocal_id', type=int, help='reciprocal identity percentage') -parser.add_argument('-u', '--uniprot_substitution', help='substitute UniProt for reference loci') +parser.add_argument('-u', '--uniprot_substitution', help='file path to UniProt substitution data for reference loci') # TODO: add an "inparanoid super-cluster vs. conventional input" flag # output settings @@ -311,8 +316,8 @@ parser.add_argument('-c', '--comparison_file_path', help='output file containing parser.add_argument('-E', '--ensembl_output_path', help='output file containing flat (1-to-many) ensemble ortho pairs') parser.add_argument('-I', '--inparanoid_output_path', help='output file containing flat (1-to-many) inparanoid ortho pairs') parser.add_argument('-g', '--generate_reactome_output', help='produce ortho_pair files required by Reactome projection inference script for specified projection source', choices=['ensembl', 'inparanoid']) -parser.add_argument('-R', '--reactome_gene_protein_path', help='four-letter Reactome reference species abbreviation') # e.g. 'zmay_gene_protein_mapping.txt' -parser.add_argument('-P', '--reactome_projection_path', help='four-letter Reactome projection species abbreviation') # e.g. 'osat_zmay_mapping.txt' +parser.add_argument('-R', '--reactome_gene_protein_path', help='output file containing gene::protein mappings for Reactome projection inference') # e.g. 'zmay_gene_protein_mapping.txt' +parser.add_argument('-P', '--reactome_projection_path', help='output file containing reference::projection protein mappings for Reactome inference') # e.g. 'osat_zmay_mapping.txt' args = parser.parse_args() #print args @@ -322,13 +327,13 @@ if args.uniprot_substitution : dict_uniprot_map = create_dict_uniprot_map(args.uniprot_substitution) # create projection maps -dict_inp_map = create_inp_map(args.inparanoid_input_path, dict_uniprot_map, args.projection_prefix) -dict_ens_map = create_ens_map(args.filtering_loci_path, args.ensembl_input_path, args.rap_map_path, args.reciprocal_id, dict_uniprot_map, args.projection_prefix) +dict_inp_map = create_inp_map(args.inparanoid_input_path, dict_uniprot_map) +dict_ens_map = create_ens_map(args.filtering_loci_path, args.ensembl_input_path, args.rap_map_path, args.reciprocal_id, dict_uniprot_map) # generate stats and output them compare_maps(dict_ens_map, dict_inp_map, args.comparison_file_path, args.ensembl_output_path, args.inparanoid_output_path) -if args.generate_reactome_output == 'ensemble' : +if args.generate_reactome_output == 'ensembl' : write_reactome_files(dict_ens_map, args.reactome_gene_protein_path, args.reactome_projection_path, args.projection_prefix) if args.generate_reactome_output == 'inparanoid' : write_reactome_files(dict_inp_map, args.reactome_gene_protein_path, args.reactome_projection_path, args.projection_prefix) -- 2.34.1