Mercurial > repos > bimib > cobraxy
comparison COBRAxy/flux_to_map.py @ 302:753347af8bc9 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Tue, 20 May 2025 14:49:15 +0000 |
| parents | 626b6d1de075 |
| children | a9d6e916ea6e |
comparison
equal
deleted
inserted
replaced
| 301:5a595a737220 | 302:753347af8bc9 |
|---|---|
| 269 | 269 |
| 270 class ArrowColor(Enum): | 270 class ArrowColor(Enum): |
| 271 """ | 271 """ |
| 272 Encodes possible arrow colors based on their meaning in the enrichment process. | 272 Encodes possible arrow colors based on their meaning in the enrichment process. |
| 273 """ | 273 """ |
| 274 Invalid = "#BEBEBE" # gray, fold-change under treshold | 274 Invalid = "#BEBEBE" # gray, fold-change under treshold or not significant p-value |
| 275 Transparent = "#ffffff00" # white, not significant p-value | 275 Transparent = "#ffffff00" # transparent, to make some arrow segments disappear |
| 276 UpRegulated = "#ecac68" # red, up-regulated reaction | 276 UpRegulated = "#ecac68" # red, up-regulated reaction |
| 277 DownRegulated = "#6495ed" # blue, down-regulated reaction | 277 DownRegulated = "#6495ed" # blue, down-regulated reaction |
| 278 | 278 |
| 279 UpRegulatedInv = "#FF0000" | 279 UpRegulatedInv = "#FF0000" |
| 280 # ^^^ different shade of red (actually orange), up-regulated net value for a reversible reaction with | 280 # ^^^ different shade of red (actually orange), up-regulated net value for a reversible reaction with |
| 623 match ARGS.test: | 623 match ARGS.test: |
| 624 case "ks": | 624 case "ks": |
| 625 # Perform Kolmogorov-Smirnov test | 625 # Perform Kolmogorov-Smirnov test |
| 626 _, p_value = st.ks_2samp(dataset1Data, dataset2Data) | 626 _, p_value = st.ks_2samp(dataset1Data, dataset2Data) |
| 627 case "ttest_p": | 627 case "ttest_p": |
| 628 # Datasets should have same size | |
| 629 if len(dataset1Data) != len(dataset2Data): | |
| 630 raise ValueError("Datasets must have the same size for paired t-test.") | |
| 628 # Perform t-test for paired samples | 631 # Perform t-test for paired samples |
| 629 _, p_value = st.ttest_rel(dataset1Data, dataset2Data) | 632 _, p_value = st.ttest_rel(dataset1Data, dataset2Data) |
| 630 case "ttest_ind": | 633 case "ttest_ind": |
| 631 # Perform t-test for independent samples | 634 # Perform t-test for independent samples |
| 632 _, p_value = st.ttest_ind(dataset1Data, dataset2Data) | 635 _, p_value = st.ttest_ind(dataset1Data, dataset2Data) |
| 633 case "wilcoxon": | 636 case "wilcoxon": |
| 637 # Datasets should have same size | |
| 638 if len(dataset1Data) != len(dataset2Data): | |
| 639 raise ValueError("Datasets must have the same size for Wilcoxon signed-rank test.") | |
| 634 # Perform Wilcoxon signed-rank test | 640 # Perform Wilcoxon signed-rank test |
| 635 _, p_value = st.wilcoxon(dataset1Data, dataset2Data) | 641 _, p_value = st.wilcoxon(dataset1Data, dataset2Data) |
| 636 case "mw": | 642 case "mw": |
| 637 # Perform Mann-Whitney U test | 643 # Perform Mann-Whitney U test |
| 638 _, p_value = st.mannwhitneyu(dataset1Data, dataset2Data) | 644 _, p_value = st.mannwhitneyu(dataset1Data, dataset2Data) |
| 672 except (TypeError, ZeroDivisionError): continue | 678 except (TypeError, ZeroDivisionError): continue |
| 673 | 679 |
| 674 # Apply multiple testing correction if set by the user | 680 # Apply multiple testing correction if set by the user |
| 675 if ARGS.adjusted: | 681 if ARGS.adjusted: |
| 676 | 682 |
| 677 # Retrive the p-values from the comparisonResult dictionary | 683 # Retrieve the p-values from the comparisonResult dictionary, they have to be different from NaN |
| 678 reactIds = list(comparisonResult.keys()) | 684 validPValues = [(reactId, result[0]) for reactId, result in comparisonResult.items() if not np.isnan(result[0])] |
| 679 pValues = [comparisonResult[reactId][0] for reactId in reactIds] | 685 |
| 680 | 686 if not validPValues: |
| 681 # Apply the Benjamini-Hochberg correction and update | 687 return comparisonResult, max_z_score |
| 682 adjustedPValues = st.multipletests(pValues, method="fdr_bh")[1] | 688 |
| 683 for i, reactId in enumerate(reactIds): | 689 # Unpack the valid p-values |
| 684 comparisonResult[reactId][0] = adjustedPValues[i] | 690 reactIds, pValues = zip(*validPValues) |
| 691 # Adjust the p-values using the Benjamini-Hochberg method | |
| 692 adjustedPValues = st.false_discovery_control(pValues) | |
| 693 # Update the comparisonResult dictionary with the adjusted p-values | |
| 694 for reactId , adjustedPValue in zip(reactIds, adjustedPValues): | |
| 695 comparisonResult[reactId][0] = adjustedPValue | |
| 685 | 696 |
| 686 return comparisonResult, max_z_score | 697 return comparisonResult, max_z_score |
| 687 | 698 |
| 688 def computeEnrichment(class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]: | 699 def computeEnrichment(class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]: |
| 689 """ | 700 """ |
