From f35df2b89c4524221396cc590d10eeb59c6a8772 Mon Sep 17 00:00:00 2001 From: preecej Date: Tue, 11 Mar 2014 21:09:58 +0000 Subject: [PATCH] Performance improvement. Changed dictionary lookup from... if item in dict.keys() : to... if item in dict : Noticeably faster. svn path=/; revision=536 --- Personnel/preecej/python_singletons/map_os_2_at.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Personnel/preecej/python_singletons/map_os_2_at.py b/Personnel/preecej/python_singletons/map_os_2_at.py index 1f101cf..b7deced 100755 --- a/Personnel/preecej/python_singletons/map_os_2_at.py +++ b/Personnel/preecej/python_singletons/map_os_2_at.py @@ -61,7 +61,7 @@ def ens_map(input_file, output_file) : cols = line.rstrip().split() if len(cols) == 5 : if int(cols[2]) >= 50 and int(cols[3]) >= 50 and int(cols[4]) == 1 : # reciprocal identity is >= 50%, high confidence - if cols[0] in dict_ens_ids.keys() : + if cols[0] in dict_ens_ids : dict_ens_ids[cols[0]].append(cols[1]) else : dict_ens_ids[cols[0]] = [cols[1]] @@ -104,7 +104,7 @@ def inp_map(input_file, output_file) : cols = line.rstrip().split() os_locus = cols[1].rstrip(".1") prj_locus = cols[2].rsplit("_",1)[0].rsplit(".",1)[0] # remove any isoform suffixes - if os_locus in dict_inp_ids.keys() : + if os_locus in dict_inp_ids : dict_inp_ids[os_locus].append(prj_locus) else : dict_inp_ids[os_locus] = [prj_locus] @@ -149,7 +149,7 @@ def compare_maps(input_file, output_file) : prj_loci = cols[1].split(',') # build ref_dict - if os_locus in ref_dict.keys() : + if os_locus in ref_dict : ref_dict[os_locus][0].extend(prj_loci) # add ens projected loci in the first list slot else : ref_dict[os_locus] = [prj_loci, []] @@ -165,7 +165,7 @@ def compare_maps(input_file, output_file) : prj_loci = cols[1].split(',') # continue build of ref_dict - if os_locus in ref_dict.keys() : + if os_locus in ref_dict : ref_dict[os_locus][1].extend(prj_loci) # put the inp projected loci in the second list slot else : ref_dict[os_locus] = [[], prj_loci] # create an empty slot for the ens projected loci, put the inp projected loci in the second list slot -- 2.34.1