comparison COBRAxy/marea.py @ 289:3f5cfcf4d9eb draft

Uploaded
author francesco_lapi
date Wed, 14 May 2025 10:08:09 +0000
parents d1d732d1705c
children 71ec0b6ddde9
comparison
equal deleted inserted replaced
288:d1d732d1705c 289:3f5cfcf4d9eb
369 reactionId : the provided reaction ID. 369 reactionId : the provided reaction ID.
370 370
371 Returns: 371 Returns:
372 Tuple[str, str]: either a single str ID for the correct arrow head followed by an empty string or both options to try. 372 Tuple[str, str]: either a single str ID for the correct arrow head followed by an empty string or both options to try.
373 """ 373 """
374 print("getArrowHeadElementId: ", reactionId)
375 if reactionId.endswith("_RV"): reactionId = reactionId[:-3] #TODO: standardize _RV 374 if reactionId.endswith("_RV"): reactionId = reactionId[:-3] #TODO: standardize _RV
376 elif ReactionDirection.fromReactionId(reactionId) is not ReactionDirection.Unknown: 375 elif ReactionDirection.fromReactionId(reactionId) is not ReactionDirection.Unknown:
377 print(f"getArrowHeadElementId: {reactionId} this was not unknown.")
378 return reactionId[:-3:-1] + reactionId[:-2], "" # ^^^ Invert _F to F_ 376 return reactionId[:-3:-1] + reactionId[:-2], "" # ^^^ Invert _F to F_
379 377
380 return f"F_{reactionId}", f"B_{reactionId}" 378 return f"F_{reactionId}", f"B_{reactionId}"
381 379
382 class ArrowColor(Enum): 380 class ArrowColor(Enum):
383 """ 381 """
384 Encodes possible arrow colors based on their meaning in the enrichment process. 382 Encodes possible arrow colors based on their meaning in the enrichment process.
385 """ 383 """
386 Invalid = "#BEBEBE" # gray, fold-change under treshold 384 Invalid = "#BEBEBE" # gray, fold-change under treshold
387 Transparent = "#ffffff00" # transparent, not significant p-value
388 UpRegulated = "#ecac68" # orange, up-regulated reaction 385 UpRegulated = "#ecac68" # orange, up-regulated reaction
389 DownRegulated = "#6495ed" # lightblue, down-regulated reaction 386 DownRegulated = "#6495ed" # lightblue, down-regulated reaction
390 387
391 UpRegulatedInv = "#FF0000" 388 UpRegulatedInv = "#FF0000"
392 # ^^^ bright red, up-regulated net value for a reversible reaction with 389 # ^^^ bright red, up-regulated net value for a reversible reaction with
425 self.w = width 422 self.w = width
426 self.col = col 423 self.col = col
427 self.dash = isDashed 424 self.dash = isDashed
428 425
429 def applyTo(self, reactionId :str, metabMap :ET.ElementTree, styleStr :str) -> None: 426 def applyTo(self, reactionId :str, metabMap :ET.ElementTree, styleStr :str) -> None:
430 #if 427 if getElementById(reactionId, metabMap).map(lambda el : styleMapElement(el, styleStr)).isErr:
431 getElementById(reactionId, metabMap).map(lambda el : styleMapElement(el, styleStr)).unwrap() 428 ERRORS.append(reactionId)
432 #.isErr:
433 # ERRORS.append(reactionId)
434 429
435 def styleReactionElements(self, metabMap :ET.ElementTree, reactionId :str, *, mindReactionDir = True) -> None: 430 def styleReactionElements(self, metabMap :ET.ElementTree, reactionId :str, *, mindReactionDir = True) -> None:
436 # 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 431 # 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
437 if not mindReactionDir: 432 if not mindReactionDir:
438 return self.applyTo(getArrowBodyElementId(reactionId), metabMap, self.toStyleStr()) 433 return self.applyTo(getArrowBodyElementId(reactionId), metabMap, self.toStyleStr())
439 434
440 # Now we style the arrow head(s): 435 # Now we style the arrow head(s):
441 idOpt1, idOpt2 = getArrowHeadElementId(reactionId) 436 idOpt1, idOpt2 = getArrowHeadElementId(reactionId)
442 print("styleReactionElements: ", idOpt1, idOpt2)
443 self.applyTo(idOpt1, metabMap, self.toStyleStr(downSizedForTips = True)) 437 self.applyTo(idOpt1, metabMap, self.toStyleStr(downSizedForTips = True))
444 if idOpt2: self.applyTo(idOpt2, metabMap, self.toStyleStr(downSizedForTips = True)) 438 if idOpt2: self.applyTo(idOpt2, metabMap, self.toStyleStr(downSizedForTips = True))
445 439
446 # TODO: this seems to be unused, remove 440 # TODO: this seems to be unused, remove
447 def getMapReactionId(self, reactionId :str, mindReactionDir :bool) -> str: 441 def getMapReactionId(self, reactionId :str, mindReactionDir :bool) -> str:
500 494
501 if math.isnan(pValue) or (isinstance(foldChange, float) and math.isnan(foldChange)): continue 495 if math.isnan(pValue) or (isinstance(foldChange, float) and math.isnan(foldChange)): continue
502 496
503 if isinstance(foldChange, str): foldChange = float(foldChange) 497 if isinstance(foldChange, str): foldChange = float(foldChange)
504 if pValue >= ARGS.pValue: # pValue above tresh: dashed arrow 498 if pValue >= ARGS.pValue: # pValue above tresh: dashed arrow
505 print("Invalid pValue: ", pValue)
506 INSIGNIFICANT_ARROW.styleReactionElements(metabMap, reactionId) 499 INSIGNIFICANT_ARROW.styleReactionElements(metabMap, reactionId)
507 continue 500 continue
508 501
509 if abs(foldChange) < (ARGS.fChange - 1) / (abs(ARGS.fChange) + 1): 502 if abs(foldChange) < (ARGS.fChange - 1) / (abs(ARGS.fChange) + 1):
510 print("Invalid fc: ", foldChange)
511 INVALID_ARROW.styleReactionElements(metabMap, reactionId) 503 INVALID_ARROW.styleReactionElements(metabMap, reactionId)
512 continue 504 continue
513 505
514 width = Arrow.MAX_W 506 width = Arrow.MAX_W
515 if not math.isinf(foldChange): 507 if not math.isinf(foldChange):