comparison COBRAxy/flux_to_map.py @ 198:1dda40a60037 draft

Uploaded
author francesco_lapi
date Thu, 21 Nov 2024 10:57:58 +0000
parents 1306b3543e57
children df664d1a86d4
comparison
equal deleted inserted replaced
197:1306b3543e57 198:1dda40a60037
714 def compareDatasetPair(dataset1Data :List[List[float]], dataset2Data :List[List[float]], ids :List[str]) -> Tuple[Dict[str, List[Union[float, FoldChange]]], float]: 714 def compareDatasetPair(dataset1Data :List[List[float]], dataset2Data :List[List[float]], ids :List[str]) -> Tuple[Dict[str, List[Union[float, FoldChange]]], float]:
715 #TODO: the following code still suffers from "dumbvarnames-osis" 715 #TODO: the following code still suffers from "dumbvarnames-osis"
716 tmp :Dict[str, List[Union[float, FoldChange]]] = {} 716 tmp :Dict[str, List[Union[float, FoldChange]]] = {}
717 count = 0 717 count = 0
718 max_z_score = 0 718 max_z_score = 0
719
720 for l1, l2 in zip(dataset1Data, dataset2Data): 719 for l1, l2 in zip(dataset1Data, dataset2Data):
721 reactId = ids[count] 720 reactId = ids[count]
722 count += 1 721 count += 1
723 if not reactId: continue # we skip ids that have already been processed 722 if not reactId: continue # we skip ids that have already been processed
724 723
726 p_value, z_score = computePValue(l1, l2) 725 p_value, z_score = computePValue(l1, l2)
727 avg1 = sum(l1) / len(l1) 726 avg1 = sum(l1) / len(l1)
728 avg2 = sum(l2) / len(l2) 727 avg2 = sum(l2) / len(l2)
729 f_c = fold_change(avg1, avg2) 728 f_c = fold_change(avg1, avg2)
730 if not isinstance(z_score, str) and max_z_score < abs(z_score): max_z_score = abs(z_score) 729 if not isinstance(z_score, str) and max_z_score < abs(z_score): max_z_score = abs(z_score)
731 print(reactId, float(p_value), f_c, z_score, avg1, avg2) 730 print(reactId, 'pValue ', float(p_value), 'fold change ', f_c, 'z_score ', z_score, 'avg1 ', avg1, 'avg2 ', avg2)
732 tmp[reactId] = [float(p_value), f_c, z_score, avg1, avg2] 731 tmp[reactId] = [float(p_value), f_c, z_score, avg1, avg2]
733 except (TypeError, ZeroDivisionError): continue 732 except (TypeError, ZeroDivisionError): continue
734 733
735 return tmp, max_z_score 734 return tmp, max_z_score
736 735
758 enrichment_results = [] 757 enrichment_results = []
759 758
760 759
761 if ARGS.comparison == "manyvsmany": 760 if ARGS.comparison == "manyvsmany":
762 for i, j in it.combinations(class_pat.keys(), 2): 761 for i, j in it.combinations(class_pat.keys(), 2):
762 print(f"Comparing {i} and {j}")
763 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(i), class_pat.get(j), ids) 763 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(i), class_pat.get(j), ids)
764 enrichment_results.append((i, j, comparisonDict, max_z_score)) 764 enrichment_results.append((i, j, comparisonDict, max_z_score))
765 765
766 elif ARGS.comparison == "onevsrest": 766 elif ARGS.comparison == "onevsrest":
767 for single_cluster in class_pat.keys(): 767 for single_cluster in class_pat.keys():
768 rest = [item for k, v in class_pat.items() if k != single_cluster for item in v] 768 rest = [item for k, v in class_pat.items() if k != single_cluster for item in v]
769 print(f"Comparing {single_cluster} and {rest}")
769 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(single_cluster), rest, ids) 770 comparisonDict, max_z_score = compareDatasetPair(class_pat.get(single_cluster), rest, ids)
770 enrichment_results.append((single_cluster, "rest", comparisonDict, max_z_score)) 771 enrichment_results.append((single_cluster, "rest", comparisonDict, max_z_score))
771 772
772 elif ARGS.comparison == "onevsmany": 773 elif ARGS.comparison == "onevsmany":
773 controlItems = class_pat.get(ARGS.control) 774 controlItems = class_pat.get(ARGS.control)