Mercurial > repos > proteore > proteore_id_converter
comparison id_converter.py @ 17:1e45ea50f145 draft
planemo upload commit 640429adac783e2354f5caf12d7b6b81b8ddf54f-dirty
author | proteore |
---|---|
date | Thu, 07 Mar 2019 07:49:18 -0500 |
parents | b6607b7e683f |
children | 5252bbcfbdd7 |
comparison
equal
deleted
inserted
replaced
16:b6607b7e683f | 17:1e45ea50f145 |
---|---|
42 ids_list=[] | 42 ids_list=[] |
43 | 43 |
44 for line in input_file : | 44 for line in input_file : |
45 if line != [] and set(line) != {''}: | 45 if line != [] and set(line) != {''}: |
46 line[nb_col] = re.sub(r"\s+","",line[nb_col]) | 46 line[nb_col] = re.sub(r"\s+","",line[nb_col]) |
47 if line[nb_col] == "" : line[nb_col]='NA' | |
47 if ";" in line[nb_col] : | 48 if ";" in line[nb_col] : |
48 ids = line[nb_col].split(";") | 49 ids = line[nb_col].split(";") |
49 for id in ids : | 50 for id in ids : |
50 new_file.append(line[:nb_col]+[id]+line[nb_col+1:]) | 51 new_file.append(line[:nb_col]+[id]+line[nb_col+1:]) |
51 ids_list.append(id) | 52 ids_list.append(id) |
117 header=False | 118 header=False |
118 if args.id_type in target_ids : target_ids.remove(args.id_type) | 119 if args.id_type in target_ids : target_ids.remove(args.id_type) |
119 if args.input_type=="file" : | 120 if args.input_type=="file" : |
120 args.column_number = nb_col_to_int(args.column_number) | 121 args.column_number = nb_col_to_int(args.column_number) |
121 header = str2bool(args.header) | 122 header = str2bool(args.header) |
123 | |
122 | 124 |
123 #Get ref file to build dictionary | 125 #Get ref file to build dictionary |
124 csv.field_size_limit(sys.maxsize) # to handle big files | 126 csv.field_size_limit(sys.maxsize) # to handle big files |
125 with open(args.ref_file, "r") as csv_file : | 127 with open(args.ref_file, "r") as csv_file : |
126 tab = csv.reader(csv_file, delimiter='\t') | 128 tab = csv.reader(csv_file, delimiter='\t') |
149 | 151 |
150 #Get file and/or ids from input | 152 #Get file and/or ids from input |
151 if args.input_type == "list" : | 153 if args.input_type == "list" : |
152 ids = get_input_ids_from_string(args.input) | 154 ids = get_input_ids_from_string(args.input) |
153 elif args.input_type == "file" : | 155 elif args.input_type == "file" : |
154 input_file, ids = get_input_ids_from_file(args.input,args.column_number,args.header) | 156 input_file, ids = get_input_ids_from_file(args.input,args.column_number,header) |
155 | 157 |
156 #Mapping ids | 158 #Mapping ids |
157 result_dict = map_to_dictionary(ids,ids_dictionary,args.id_type,target_ids) | 159 result_dict = map_to_dictionary(ids,ids_dictionary,args.id_type,target_ids) |
158 | 160 |
159 #creating output file | 161 #creating output file |