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

Uploaded
author luca_milaz
date Wed, 06 Nov 2024 21:02:00 +0000
parents 5683406a8cfd
children 929104dceba8
comparison
equal deleted inserted replaced
150:834009d1a094 151:8e3cbf68cdc4
731 tmp[reactId] = [float(p_value), avg, z_score, avg1, avg2] 731 tmp[reactId] = [float(p_value), avg, z_score, avg1, avg2]
732 except (TypeError, ZeroDivisionError): continue 732 except (TypeError, ZeroDivisionError): continue
733 733
734 return tmp, max_z_score 734 return tmp, max_z_score
735 735
736 def computeEnrichment(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]: 736 def computeEnrichment(class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]:
737 """ 737 """
738 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the 738 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the
739 provided metabolic map. 739 provided metabolic map.
740 740
741 Args: 741 Args:
742 metabMap : SVG map to modify.
743 class_pat : the clustered data. 742 class_pat : the clustered data.
744 ids : ids for data association. 743 ids : ids for data association.
745 744
746 745
747 Returns: 746 Returns:
748 List[Tuple[str, str, dict, float]]: List of tuples with pairs of dataset names, comparison dictionary, and max z-score. 747 List[Tuple[str, str, dict, float]]: List of tuples with pairs of dataset names, comparison dictionary, and max z-score.
749 748
750 Raises: 749 Raises:
751 sys.exit : if there are less than 2 classes for comparison 750 sys.exit : if there are less than 2 classes for comparison
752 751
753 Side effects:
754 metabMap : mut
755 ids : mut
756 """ 752 """
757 class_pat = { k.strip() : v for k, v in class_pat.items() } 753 class_pat = { k.strip() : v for k, v in class_pat.items() }
758 #TODO: simplfy this stuff vvv and stop using sys.exit (raise the correct utils error) 754 #TODO: simplfy this stuff vvv and stop using sys.exit (raise the correct utils error)
759 if (not class_pat) or (len(class_pat.keys()) < 2): sys.exit('Execution aborted: classes provided for comparisons are less than two\n') 755 if (not class_pat) or (len(class_pat.keys()) < 2): sys.exit('Execution aborted: classes provided for comparisons are less than two\n')
760 756
763 759
764 if ARGS.comparison == "manyvsmany": 760 if ARGS.comparison == "manyvsmany":
765 for i, j in it.combinations(class_pat.keys(), 2): 761 for i, j in it.combinations(class_pat.keys(), 2):
766 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(i), class_pat.get(j), ids) 762 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(i), class_pat.get(j), ids)
767 enrichment_results.append((i, j, comparisonDict, max_z_score)) 763 enrichment_results.append((i, j, comparisonDict, max_z_score))
768
769
770 764
771 elif ARGS.comparison == "onevsrest": 765 elif ARGS.comparison == "onevsrest":
772 for single_cluster in class_pat.keys(): 766 for single_cluster in class_pat.keys():
773 rest = [item for k, v in class_pat.items() if k != single_cluster for item in v] 767 rest = [item for k, v in class_pat.items() if k != single_cluster for item in v]
774 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(single_cluster), rest, ids) 768 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(single_cluster), rest, ids)
1028 computeEnrichmentMeanMedian(temp_map.getMap(ARGS.tool_dir), class_pat, ids, ARGS.color_map) 1022 computeEnrichmentMeanMedian(temp_map.getMap(ARGS.tool_dir), class_pat, ids, ARGS.color_map)
1029 else: 1023 else:
1030 computeEnrichmentMeanMedian(core_map, class_pat, ids, ARGS.color_map) 1024 computeEnrichmentMeanMedian(core_map, class_pat, ids, ARGS.color_map)
1031 1025
1032 1026
1033 enrichment_results = computeEnrichment(core_map, class_pat, ids) 1027 enrichment_results = computeEnrichment(class_pat, ids)
1034 for i, j, comparisonDict, max_z_score in enrichment_results: 1028 for i, j, comparisonDict, max_z_score in enrichment_results:
1035 map_copy = copy.deepcopy(core_map) 1029 map_copy = copy.deepcopy(core_map)
1036 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j) 1030 temp_thingsInCommon(comparisonDict, map_copy, max_z_score, i, j)
1037 createOutputMaps(i, j, map_copy) 1031 createOutputMaps(i, j, map_copy)
1038 1032