cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
48 stars 20 forks source link

setNodeCustomHeatMapChart() Function #221

Closed zcsharp101 closed 2 months ago

zcsharp101 commented 2 months ago

Hi there,

I'm using your package to import WikiPathways and then am using the setNodeCustomHeatMapChart() function to colour the genes in the pathways with colours representing values from different treatments.

I am having an issue where any nodes with no values are coloured to colour specified. This is great for highlight genes with no values but it is colouring other nodes, namely shapes and text boxes that aren't genes.

I did get around this before by inputting hex numbers with alpha info as well (like #00000000 instead of #000000); however, I don't seem to be able to do this anymore and get the error '#00f8f8f0 is not a valid hexadecimal color, e.g. #FD39B8.' for instances.

Thank you for the help.

AlexanderPico commented 2 months ago

Happy to help. Can you share your code, so I can reproduce this issue. Then I can either suggest a workaround or fix any bugs in the way.

zcsharp101 commented 2 months ago

Thank you!

#for setNodeCustomHeatMapChart parameter 'colors': colours assigned in order: Max, Mid, Min, NA for heatmap function setNodeCustomHeatMapChart(columns, range = c(min,max), colors = c('#EF8A62','#FFFFFF','#67A9CF', '#f8f8f0'), slot=1, style.name = "WikiPathways")

"columns" is specifying 3 column names in the node table that has values assigned to genes specifically. In this case, all nodes without values (NA) have a beige (#f8f8f0) square set around them as well. Can share the node table as well with that helps.

Thank you again for the help.

AlexanderPico commented 2 months ago

Right. In order to reproduce this, I can pick a random pathway, make up data and write my own script.... or you could share yours :)

As much as you can share as possible would help me test the issue you are seeing faster.

zcsharp101 commented 2 months ago

Sorry, I wasn't sure if you meant to whole thing. I've uploaded the data but have changed it since I can't share the original stuff; however, the data isn't the issue and I tested it again with the script attached and it all works and the issue discussed is still observed. I had to change the script to a .txt file to upload it but if you change it back to a .R file it should work the same.

Treatment_vs_Ctrl.gene_summary - Copy.csv wikiPathways GSEA+Pathway Viewer_V2 - copy.txt

AlexanderPico commented 2 months ago
Screenshot 2024-04-26 at 11 20 53 AM

Excellent. I can reproduce your case. By the way, this script is awesome. Nice work!

I will return a version of the script with my suggestions, prefaced with ##AP:. But first I'll detail what I'm seeing to confirm that we fix all the issues...

  1. The Mismatch Repair box and the group nodes have beige custom graphics applied, but they should not.
  2. Some gene labels are shifted up (see RFC5).
AlexanderPico commented 2 months ago

Solutions:

  1. We should be able to select all non-gene nodes (using the Type column from WikiPathways or, even better, the Ensembl column) and then set a bypass to null to remove the custom graphics from just those nodes.
  2. We need to find/replace all node labels that have a newline character (for some unknown reason) at the end.

I'll add these to the script now...

AlexanderPico commented 2 months ago
Screenshot 2024-04-26 at 12 31 20 PM
AlexanderPico commented 2 months ago

Here are the key new code chunks and an edited version of your script.

    ##AP: Set null bypass for custom graphics on non-gene nodes, i.e., nodes 
    # missing a possible match with the 'Ensembl' column
    node.SUIDs = Node.table[which(is.na(Node.table$Ensembl)),'SUID']
    setNodePropertyBypass(node.SUIDs, 'null', 'NODE_CUSTOMGRAPHICS_1')

    ##AP: Remove trailing newline characters from node names
    Node.table.subset <- Node.table[,c('SUID','name')]
    Node.table.subset$name <- gsub("\n$", "", Node.table.subset$name)
    loadTableData(Node.table.subset, 'SUID','node','SUID')

wikiPathways.GSEA+Pathway.Viewer_V2.-.copy_AP.txt

AlexanderPico commented 2 months ago

Note: I chose to use the Ensembl column provided by WikiPathways to distinguish nodes that should retain a beige color (i.e., those where a possible data mapping could occur, but didn't due to missing data), versus nodes that should not (i.e., maybe you have relevant data, but the pathway does not include an Ensembl ID to match to). In your case, this means H2AX is beige, while XRS2 is not (it's blank... which also looks like white data).

You could set the fill color on those non-mapping gene cases to indicate this case better. Or you could choose to use the Type column provided by WikiPathways instead to distinguish genes from non-genes. Be aware of the following Types that might be real genes amenable to data mapping via Ensembl: GeneProduct, Protein, DNA, RNA.

zcsharp101 commented 2 months ago

That's amazing, thanks! And thank you for the complement on my code. Didn't realise it be this simple to fix and was trying something along these lines but couldn't figure out what to do exactly. I didn't even realise the gene names that were misplaced could be fixed.

Now you have shown me that I do have another bug with WikiPathways that comes to mind, can I share it here or do you want a new thread started? I don't think this one has as simple a fix.

Regardless, this has been a great help so thank you again.

AlexanderPico commented 2 months ago

If you don't mind, starting a new issue would be best. Cheers.