Mercurial > repos > bimib > cobraxy
comparison COBRAxy/flux_to_map.py @ 295:626b6d1de075 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Fri, 16 May 2025 10:56:01 +0000 |
| parents | 7b8d9de81a86 |
| children | 753347af8bc9 |
comparison
equal
deleted
inserted
replaced
| 294:274223ff4fb0 | 295:626b6d1de075 |
|---|---|
| 63 parser.add_argument( | 63 parser.add_argument( |
| 64 '-pv' ,'--pValue', | 64 '-pv' ,'--pValue', |
| 65 type = float, | 65 type = float, |
| 66 default = 0.1, | 66 default = 0.1, |
| 67 help = 'P-Value threshold (default: %(default)s)') | 67 help = 'P-Value threshold (default: %(default)s)') |
| 68 | |
| 69 parser.add_argument( | |
| 70 '-adj' ,'--adjusted', | |
| 71 type = utils.Bool("adjusted"), default = False, | |
| 72 help = 'Apply the FDR (Benjamini-Hochberg) correction (default: %(default)s)') | |
| 68 | 73 |
| 69 parser.add_argument( | 74 parser.add_argument( |
| 70 '-fc', '--fChange', | 75 '-fc', '--fChange', |
| 71 type = float, | 76 type = float, |
| 72 default = 1.5, | 77 default = 1.5, |
| 73 help = 'Fold-Change threshold (default: %(default)s)') | 78 help = 'Fold-Change threshold (default: %(default)s)') |
| 74 | 79 |
| 75 | |
| 76 parser.add_argument( | 80 parser.add_argument( |
| 77 '-op', '--option', | 81 '-op', '--option', |
| 78 type = str, | 82 type = str, |
| 79 choices = ['datasets', 'dataset_class'], | 83 choices = ['datasets', 'dataset_class'], |
| 80 help='dataset or dataset and class') | 84 help='dataset or dataset and class') |
| 647 | 651 |
| 648 return p_value, z_score | 652 return p_value, z_score |
| 649 | 653 |
| 650 def compareDatasetPair(dataset1Data :List[List[float]], dataset2Data :List[List[float]], ids :List[str]) -> Tuple[Dict[str, List[Union[float, FoldChange]]], float]: | 654 def compareDatasetPair(dataset1Data :List[List[float]], dataset2Data :List[List[float]], ids :List[str]) -> Tuple[Dict[str, List[Union[float, FoldChange]]], float]: |
| 651 #TODO: the following code still suffers from "dumbvarnames-osis" | 655 #TODO: the following code still suffers from "dumbvarnames-osis" |
| 652 tmp :Dict[str, List[Union[float, FoldChange]]] = {} | 656 comparisonResult :Dict[str, List[Union[float, FoldChange]]] = {} |
| 653 count = 0 | 657 count = 0 |
| 654 max_z_score = 0 | 658 max_z_score = 0 |
| 655 for l1, l2 in zip(dataset1Data, dataset2Data): | 659 for l1, l2 in zip(dataset1Data, dataset2Data): |
| 656 reactId = ids[count] | 660 reactId = ids[count] |
| 657 count += 1 | 661 count += 1 |
| 662 avg1 = sum(l1) / len(l1) | 666 avg1 = sum(l1) / len(l1) |
| 663 avg2 = sum(l2) / len(l2) | 667 avg2 = sum(l2) / len(l2) |
| 664 f_c = fold_change(avg1, avg2) | 668 f_c = fold_change(avg1, avg2) |
| 665 if np.isfinite(z_score) and max_z_score < abs(z_score): max_z_score = abs(z_score) | 669 if np.isfinite(z_score) and max_z_score < abs(z_score): max_z_score = abs(z_score) |
| 666 | 670 |
| 667 tmp[reactId] = [float(p_value), f_c, z_score, avg1, avg2] | 671 comparisonResult[reactId] = [float(p_value), f_c, z_score, avg1, avg2] |
| 668 except (TypeError, ZeroDivisionError): continue | 672 except (TypeError, ZeroDivisionError): continue |
| 669 | 673 |
| 670 return tmp, max_z_score | 674 # Apply multiple testing correction if set by the user |
| 675 if ARGS.adjusted: | |
| 676 | |
| 677 # Retrive the p-values from the comparisonResult dictionary | |
| 678 reactIds = list(comparisonResult.keys()) | |
| 679 pValues = [comparisonResult[reactId][0] for reactId in reactIds] | |
| 680 | |
| 681 # Apply the Benjamini-Hochberg correction and update | |
| 682 adjustedPValues = st.multipletests(pValues, method="fdr_bh")[1] | |
| 683 for i, reactId in enumerate(reactIds): | |
| 684 comparisonResult[reactId][0] = adjustedPValues[i] | |
| 685 | |
| 686 return comparisonResult, max_z_score | |
| 671 | 687 |
| 672 def computeEnrichment(class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]: | 688 def computeEnrichment(class_pat :Dict[str, List[List[float]]], ids :List[str]) -> List[Tuple[str, str, dict, float]]: |
| 673 """ | 689 """ |
| 674 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the | 690 Compares clustered data based on a given comparison mode and applies enrichment-based styling on the |
| 675 provided metabolic map. | 691 provided metabolic map. |
