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
# 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 :
#----------------------------------------------------------------------------------------------------------------------
-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
# 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() :
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
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
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
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)