Mercurial > repos > bimib > cobraxy
changeset 284:2febf79bb334 draft
Uploaded
author | francesco_lapi |
---|---|
date | Tue, 13 May 2025 10:36:11 +0000 |
parents | 2436856c7e51 |
children | 216a796a967a |
files | COBRAxy/marea.py |
diffstat | 1 files changed, 38 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/COBRAxy/marea.py Tue May 13 09:06:31 2025 +0000 +++ b/COBRAxy/marea.py Tue May 13 10:36:11 2025 +0000 @@ -435,11 +435,9 @@ # If We're dealing with RAS data or in general don't care about the direction of the reaction we only style the arrow body if not mindReactionDir: return self.applyTo(getArrowBodyElementId(reactionId), metabMap, self.toStyleStr()) + # Now we style the arrow head(s): idOpt1, idOpt2 = getArrowHeadElementId(reactionId) - print(f'{idOpt1} {self.toStyleStr(downSizedForTips = True)}') - if idOpt2: print(f'{idOpt2} {self.toStyleStr(downSizedForTips = True)}') - print('----') self.applyTo(idOpt1, metabMap, self.toStyleStr(downSizedForTips = True)) if idOpt2: self.applyTo(idOpt2, metabMap, self.toStyleStr(downSizedForTips = True)) @@ -505,7 +503,6 @@ if abs(foldChange) < (ARGS.fChange - 1) / (abs(ARGS.fChange) + 1): INVALID_ARROW.styleReactionElements(metabMap, reactionId) - print('Prova 2') continue width = Arrow.MAX_W @@ -528,7 +525,6 @@ # vvv These 2 if statements can both be true and can both happen if ARGS.net: # style arrow head(s): - print('Prova NET') arrow.styleReactionElements(metabMap, reactionId + ("_B" if inversionScore == 2 else "_F")) if not ARGS.using_RAS: # style arrow body @@ -898,22 +894,46 @@ ARGS.tool_dir, utils.FilePath.fromStrPath(ARGS.custom_map) if ARGS.custom_map else None) + # Prepare enrichment results containers + ras_results = [] + rps_results = [] + + # Compute RAS enrichment if requested if ARGS.using_RAS: - ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas, ARGS.input_data, ARGS.input_class, ARGS.names) - enrichment_results = computeEnrichment(class_pat, ids) - for i, j, comparisonDict, max_z_score in enrichment_results: - map_copy = copy.deepcopy(core_map) - temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=True) - createOutputMaps(i, j, map_copy) - + ids_ras, class_pat_ras = getClassesAndIdsFromDatasets( + ARGS.input_datas, ARGS.input_data, ARGS.input_class, ARGS.names) + ras_results = computeEnrichment(class_pat_ras, ids_ras, fromRAS=True) + + # Compute RPS enrichment if requested if ARGS.using_RPS: - ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas_rps, ARGS.input_data_rps, ARGS.input_class_rps, ARGS.names_rps) - enrichment_results = computeEnrichment(class_pat, ids, fromRAS=False) - for i, j, comparisonDict, max_z_score in enrichment_results: - map_copy = copy.deepcopy(core_map) - temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=False) - createOutputMaps(i, j, map_copy) + ids_rps, class_pat_rps = getClassesAndIdsFromDatasets( + ARGS.input_datas_rps, ARGS.input_data_rps, ARGS.input_class_rps, ARGS.names_rps) + rps_results = computeEnrichment(class_pat_rps, ids_rps, fromRAS=False) + + # Organize by comparison pairs + comparisons: Dict[Tuple[str, str], Dict[str, Tuple]] = {} + for i, j, d, mz in ras_results: + comparisons[(i, j)] = {'ras': (d, mz), 'rps': None} + for i, j, d, mz in rps_results: + comparisons.setdefault((i, j), {}).update({'rps': (d, mz)}) + # For each comparison, create a styled map with RAS bodies and RPS heads + for (i, j), res in comparisons.items(): + map_copy = copy.deepcopy(core_map) + + # Apply RAS styling to arrow bodies + if res.get('ras'): + tmp_ras, max_z_ras = res['ras'] + temp_thingsInCommon(tmp_ras, map_copy, max_z_ras, i, j, ras_enrichment=True) + + # Apply RPS styling to arrow heads + if res.get('rps'): + tmp_rps, max_z_rps = res['rps'] + # Ensure applyRpsEnrichmentToMap styles only heads; adjust internals if needed + applyRpsEnrichmentToMap(tmp_rps, map_copy, max_z_rps) + + # Output both SVG and PDF/PNG as configured + createOutputMaps(i, j, map_copy) print('Execution succeeded') ############################################################################### if __name__ == "__main__":