comparison COBRAxy/marea.py @ 151:8e3cbf68cdc4 draft

Uploaded
author luca_milaz
date Wed, 06 Nov 2024 21:02:00 +0000
parents 3fca9b568faf
children
comparison
equal deleted inserted replaced
150:834009d1a094 151:8e3cbf68cdc4
766 766
767 except (TypeError, ZeroDivisionError): continue 767 except (TypeError, ZeroDivisionError): continue
768 768
769 return tmp, max_z_score 769 return tmp, max_z_score
770 770
771 def computeEnrichment(metabMap: ET.ElementTree, class_pat: Dict[str, List[List[float]]], ids: List[str], *, fromRAS=True) -> List[Tuple[str, str, dict, float]]: 771 def computeEnrichment(class_pat: Dict[str, List[List[float]]], ids: List[str], *, fromRAS=True) -> List[Tuple[str, str, dict, float]]:
772 """ 772 """
773 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the 773 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the
774 provided metabolic map. 774 provided metabolic map.
775 775
776 Args: 776 Args:
777 metabMap : SVG map to modify.
778 class_pat : the clustered data. 777 class_pat : the clustered data.
779 ids : ids for data association. 778 ids : ids for data association.
780 fromRAS : whether the data to enrich consists of RAS scores. 779 fromRAS : whether the data to enrich consists of RAS scores.
781 780
782 Returns: 781 Returns:
783 List[Tuple[str, str, dict, float]]: List of tuples with pairs of dataset names, comparison dictionary, and max z-score. 782 List[Tuple[str, str, dict, float]]: List of tuples with pairs of dataset names, comparison dictionary, and max z-score.
784 783
785 Raises: 784 Raises:
786 sys.exit : if there are less than 2 classes for comparison 785 sys.exit : if there are less than 2 classes for comparison
787
788 Side effects:
789 metabMap : mutates based on calculated enrichment
790 """ 786 """
791 class_pat = {k.strip(): v for k, v in class_pat.items()} 787 class_pat = {k.strip(): v for k, v in class_pat.items()}
792 if (not class_pat) or (len(class_pat.keys()) < 2): 788 if (not class_pat) or (len(class_pat.keys()) < 2):
793 sys.exit('Execution aborted: classes provided for comparisons are less than two\n') 789 sys.exit('Execution aborted: classes provided for comparisons are less than two\n')
794 790
891 ARGS.tool_dir, 887 ARGS.tool_dir,
892 utils.FilePath.fromStrPath(ARGS.custom_map) if ARGS.custom_map else None) 888 utils.FilePath.fromStrPath(ARGS.custom_map) if ARGS.custom_map else None)
893 889
894 if ARGS.using_RAS: 890 if ARGS.using_RAS:
895 ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas, ARGS.input_data, ARGS.input_class, ARGS.names) 891 ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas, ARGS.input_data, ARGS.input_class, ARGS.names)
896 enrichment_results = computeEnrichment(core_map, class_pat, ids) 892 enrichment_results = computeEnrichment(class_pat, ids)
897 for i, j, comparisonDict, max_z_score in enrichment_results: 893 for i, j, comparisonDict, max_z_score in enrichment_results:
898 map_copy = copy.deepcopy(core_map) 894 map_copy = copy.deepcopy(core_map)
899 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=True) 895 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=True)
900 createOutputMaps(i, j, map_copy) 896 createOutputMaps(i, j, map_copy)
901 897
902 if ARGS.using_RPS: 898 if ARGS.using_RPS:
903 ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas_rps, ARGS.input_data_rps, ARGS.input_class_rps, ARGS.names_rps) 899 ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas_rps, ARGS.input_data_rps, ARGS.input_class_rps, ARGS.names_rps)
904 enrichment_results = computeEnrichment(core_map, class_pat, ids, fromRAS=False) 900 enrichment_results = computeEnrichment(class_pat, ids, fromRAS=False)
905 for i, j, comparisonDict, max_z_score in enrichment_results: 901 for i, j, comparisonDict, max_z_score in enrichment_results:
906 map_copy = copy.deepcopy(core_map) 902 map_copy = copy.deepcopy(core_map)
907 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=False) 903 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j, ras_enrichment=False)
908 createOutputMaps(i, j, map_copy) 904 createOutputMaps(i, j, map_copy)
909 905