Mercurial > repos > bimib > cobraxy
comparison COBRAxy/rps_generator.py @ 402:ccccb731c953 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Sun, 07 Sep 2025 21:16:26 +0000 |
| parents | 0a3ca20848f3 |
| children | 187cee1a00e2 |
comparison
equal
deleted
inserted
replaced
| 401:6c7ddf68381a | 402:ccccb731c953 |
|---|---|
| 23 Namespace: An object containing parsed arguments. | 23 Namespace: An object containing parsed arguments. |
| 24 """ | 24 """ |
| 25 parser = argparse.ArgumentParser(usage = '%(prog)s [options]', | 25 parser = argparse.ArgumentParser(usage = '%(prog)s [options]', |
| 26 description = 'process some value\'s'+ | 26 description = 'process some value\'s'+ |
| 27 ' abundances and reactions to create RPS scores.') | 27 ' abundances and reactions to create RPS scores.') |
| 28 parser.add_argument('-rc', '--reaction_choice', | 28 |
| 29 type = str, | 29 parser.add_argument("-rl", "--model_upload", type = str, |
| 30 default = 'default', | 30 help = "path to input file containing the reactions") |
| 31 choices = ['default','custom'], | 31 |
| 32 help = 'chose which type of reaction dataset you want use') | 32 # model_upload custom |
| 33 parser.add_argument('-cm', '--custom', | |
| 34 type = str, | |
| 35 help='your dataset if you want custom reactions') | |
| 36 parser.add_argument('-td', '--tool_dir', | 33 parser.add_argument('-td', '--tool_dir', |
| 37 type = str, | 34 type = str, |
| 38 required = True, | 35 required = True, |
| 39 help = 'your tool directory') | 36 help = 'your tool directory') |
| 40 parser.add_argument('-ol', '--out_log', | 37 parser.add_argument('-ol', '--out_log', |
| 203 """ | 200 """ |
| 204 | 201 |
| 205 cell_lines = dataset[0][1:] | 202 cell_lines = dataset[0][1:] |
| 206 abundances_dict = {} | 203 abundances_dict = {} |
| 207 | 204 |
| 208 translationIsApplied = ARGS.reaction_choice == "default" | |
| 209 for row in dataset[1:]: | 205 for row in dataset[1:]: |
| 210 id = get_metabolite_id(row[0], syn_dict) #if translationIsApplied else row[0] | 206 id = get_metabolite_id(row[0], syn_dict) #if translationIsApplied else row[0] |
| 211 if id: | 207 if id: |
| 212 abundances_dict[id] = list(map(utils.Float(), row[1:])) | 208 abundances_dict[id] = list(map(utils.Float(), row[1:])) |
| 213 | 209 |
| 243 with open(ARGS.tool_dir + '/local/pickle files/synonyms.pickle', 'rb') as sd: | 239 with open(ARGS.tool_dir + '/local/pickle files/synonyms.pickle', 'rb') as sd: |
| 244 syn_dict = pk.load(sd) | 240 syn_dict = pk.load(sd) |
| 245 | 241 |
| 246 dataset = utils.readCsv(utils.FilePath.fromStrPath(ARGS.input), '\t', skipHeader = False) | 242 dataset = utils.readCsv(utils.FilePath.fromStrPath(ARGS.input), '\t', skipHeader = False) |
| 247 tmp_dict = None | 243 tmp_dict = None |
| 248 if ARGS.reaction_choice == 'default': | 244 #if ARGS.reaction_choice == 'default': |
| 249 reactions = pk.load(open(ARGS.tool_dir + '/local/pickle files/reactions.pickle', 'rb')) | 245 # reactions = pk.load(open(ARGS.tool_dir + '/local/pickle files/reactions.pickle', 'rb')) |
| 250 substrateFreqTable = pk.load(open(ARGS.tool_dir + '/local/pickle files/substrate_frequencies.pickle', 'rb')) | 246 # substrateFreqTable = pk.load(open(ARGS.tool_dir + '/local/pickle files/substrate_frequencies.pickle', 'rb')) |
| 251 | 247 |
| 252 elif ARGS.reaction_choice == 'custom': | 248 #elif ARGS.reaction_choice == 'custom': |
| 253 reactions = reactionUtils.parse_custom_reactions(ARGS.custom) | 249 reactions = reactionUtils.parse_custom_reactions(ARGS.model_upload) |
| 254 for r, s in reactions.items(): | 250 for r, s in reactions.items(): |
| 255 tmp_list = list(s.keys()) | 251 tmp_list = list(s.keys()) |
| 256 for k in tmp_list: | 252 for k in tmp_list: |
| 257 if k[-2] == '_': | 253 if k[-2] == '_': |
| 258 s[k[:-2]] = s.pop(k) | 254 s[k[:-2]] = s.pop(k) |
| 259 substrateFreqTable = {} | 255 substrateFreqTable = {} |
| 260 for _, substrates in reactions.items(): | 256 for _, substrates in reactions.items(): |
| 261 for substrateName, _ in substrates.items(): | 257 for substrateName, _ in substrates.items(): |
| 262 if substrateName not in substrateFreqTable: substrateFreqTable[substrateName] = 0 | 258 if substrateName not in substrateFreqTable: substrateFreqTable[substrateName] = 0 |
| 263 substrateFreqTable[substrateName] += 1 | 259 substrateFreqTable[substrateName] += 1 |
| 264 | 260 |
| 265 print(f"Reactions: {reactions}") | 261 print(f"Reactions: {reactions}") |
| 266 print(f"Substrate Frequencies: {substrateFreqTable}") | 262 print(f"Substrate Frequencies: {substrateFreqTable}") |
| 267 print(f"Synonyms: {syn_dict}") | 263 print(f"Synonyms: {syn_dict}") |
| 268 tmp_dict = {} | 264 tmp_dict = {} |
