changeset 244:f1754122f37d draft

Uploaded
author luca_milaz
date Sat, 03 Aug 2024 14:11:13 +0000
parents b2391e1acdc0
children 42e55436179a
files marea_2/flux_to_map.py
diffstat 1 files changed, 14 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/flux_to_map.py	Sat Aug 03 14:04:13 2024 +0000
+++ b/marea_2/flux_to_map.py	Sat Aug 03 14:11:13 2024 +0000
@@ -95,12 +95,12 @@
     parser.add_argument(
         "-gs", "--generate_svg",
         type = utils.Bool("generate_svg"), default = True,
-        help = "choose whether to use RAS datasets.")
+        help = "choose whether to generate svg")
     
     parser.add_argument(
         "-gp", "--generate_pdf",
         type = utils.Bool("generate_pdf"), default = True,
-        help = "choose whether to use RAS datasets.")
+        help = "choose whether to generate pdf")
     
     parser.add_argument(
         '-cm', '--custom_map',
@@ -385,7 +385,6 @@
             ERRORS.append(reactionId)
 
     def styleReactionElements(self, metabMap :ET.ElementTree, reactionId :str, *, mindReactionDir = True) -> None:
-        # If We're dealing with RAS data or in general don't care about the direction of the reaction we only style the arrow body
         if not mindReactionDir:
             return self.applyTo(getArrowBodyElementId(reactionId), metabMap, self.toStyleStr())
         
@@ -486,9 +485,8 @@
         if ARGS.net: # style arrow head(s):
             arrow.styleReactionElements(metabMap, reactionId + ("_B" if inversionScore == 2 else "_F"))
             arrow.applyTo(("F_" if inversionScore == 2 else "B_") + reactionId, metabMap, f";stroke:{ArrowColor.Transparent};stroke-width:0;stroke-dasharray:None")
-        
-        if not ARGS.using_RAS: # style arrow body
-            arrow.styleReactionElements(metabMap, reactionId, mindReactionDir = False)
+
+        arrow.styleReactionElements(metabMap, reactionId, mindReactionDir = False)
 
 
 ############################ split class ######################################
@@ -638,21 +636,16 @@
             writer.writerow({ field : data for field, data in zip(fieldNames, row) })
 
 OldEnrichedScores = Dict[str, List[Union[float, FoldChange]]] #TODO: try to use Tuple whenever possible
-def writeTabularResult(enrichedScores : OldEnrichedScores, ras_enrichment: bool, outPath :utils.FilePath) -> None:
+def writeTabularResult(enrichedScores : OldEnrichedScores, outPath :utils.FilePath) -> None:
     fieldNames = ["ids", "P_Value", "fold change"]
-    if not ras_enrichment: fieldNames.extend(["average_1", "average_2"])
+    fieldNames.extend(["average_1", "average_2"])
 
     writeToCsv([ [reactId] + values for reactId, values in enrichedScores.items() ], fieldNames, outPath)
 
-def temp_thingsInCommon(tmp :Dict[str, List[Union[float, FoldChange]]], core_map :ET.ElementTree, max_z_score :float, dataset1Name :str, dataset2Name = "rest", ras_enrichment = True) -> None:
+def temp_thingsInCommon(tmp :Dict[str, List[Union[float, FoldChange]]], core_map :ET.ElementTree, max_z_score :float, dataset1Name :str, dataset2Name = "rest") -> None:
     # this function compiles the things always in common between comparison modes after enrichment.
     # TODO: organize, name better.
-    writeTabularResult(tmp, ras_enrichment, buildOutputPath(dataset1Name, dataset2Name, details = "Tabular Result", ext = utils.FileFormat.TSV))
-    
-    if ras_enrichment:
-        fix_map(tmp, core_map, ARGS.pValue, ARGS.fChange, max_z_score)
-        return
-
+    writeTabularResult(tmp, buildOutputPath(dataset1Name, dataset2Name, details = "Tabular Result", ext = utils.FileFormat.TSV))
     for reactId, enrichData in tmp.items(): tmp[reactId] = tuple(enrichData)
     applyFluxesEnrichmentToMap(tmp, core_map, max_z_score)
 
@@ -702,7 +695,6 @@
         if not reactId: continue # we skip ids that have already been processed
 
         try: 
-            # fallthrough is intended, regular scores need to be computed when tips aren't net but RAS datasets aren't used
             p_value, z_score = computePValue(l1, l2)
             avg1 = sum(l1) / len(l1)
             avg2 = sum(l2) / len(l2)
@@ -713,7 +705,7 @@
     
     return tmp, max_z_score
 
-def computeEnrichment(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str], *, fromRAS = True) -> None:
+def computeEnrichment(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> None:
     """
     Compares clustered data based on a given comparison mode and applies enrichment-based styling on the
     provided metabolic map.
@@ -722,7 +714,7 @@
         metabMap : SVG map to modify.
         class_pat : the clustered data.
         ids : ids for data association.
-        fromRAS : whether the data to enrich consists of RAS scores.
+        
 
     Returns:
         None
@@ -743,7 +735,7 @@
             #TODO: these 2 functions are always called in pair and in this order and need common data,
             # some clever refactoring would be appreciated.
             comparisonDict, max_z_score = compareDatasetPair(class_pat.get(i), class_pat.get(j), ids)
-            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, i, j, fromRAS)
+            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, i, j)
     
     elif ARGS.comparison == "onevsrest":
         for single_cluster in class_pat.keys():
@@ -757,7 +749,7 @@
                 rest = rest + i
             
             comparisonDict, max_z_score = compareDatasetPair(class_pat.get(single_cluster), rest, ids)
-            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, single_cluster, fromRAS)
+            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, single_cluster)
     
     elif ARGS.comparison == "onevsmany":
         controlItems = class_pat.get(ARGS.control)
@@ -765,7 +757,7 @@
             if otherDataset == ARGS.control: continue
             
             comparisonDict, max_z_score = compareDatasetPair(controlItems, class_pat.get(otherDataset), ids)
-            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, ARGS.control, otherDataset, fromRAS)
+            temp_thingsInCommon(comparisonDict, metabMap, max_z_score, ARGS.control, otherDataset)
 
 def createOutputMaps(dataset1Name :str, dataset2Name :str, core_map :ET.ElementTree) -> None:
     svgFilePath = buildOutputPath(dataset1Name, dataset2Name, details = "SVG Map", ext = utils.FileFormat.SVG)
@@ -846,7 +838,7 @@
     # solution can be derived from my comment in FilePath.fromStrPath
 
     ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas_fluxes, ARGS.input_data_fluxes, ARGS.input_class_fluxes, ARGS.names_fluxes)
-    computeEnrichment(core_map, class_pat, ids, fromRAS = False)
+    computeEnrichment(core_map, class_pat, ids)
     
     # create output files: TODO: this is the same comparison happening in "maps", find a better way to organize this
     if ARGS.comparison == "manyvsmany":