cytoscape / RCy3

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

loadTableData with numeric column but it becomes string in cytoscape desktop #207

Closed gmhhope closed 1 year ago

gmhhope commented 1 year ago

Hi Alex,

Somehow I tried to load my node table and visualize with fill color (e.g., Chisq_illness_duration ), and using str() shows the column is numeric. However, when I load the node_table, the type of the column becomes string in cytoscape desktop. What might be the issue and how to solve this? Thanks!

Interestingly, manual loading of the table renders float for those columns. Is the NA the culprit? I have tested if I remove the NA rows, it seems to work. But I have to keep them :/

loadTableData(
  node_table,
  data.key.column = "ID",
  table = "node"
)
str(node_table)
'data.frame':   362 obs. of  33 variables:
 $ Panel                               : chr  "P1" "P1" "P1" "P1" ...
 $ Parent                              : chr  "" "" "" "" ...
 $ new_subgate_copied_Courtney_09212022: chr  "" "" "" "" ...
 $ ID                                  : chr  "P1_T1" "P1_T2" "P1_T3" "P1_T4" ...
 $ Note                                : chr  "" "" "" "" ...
 $ gate                                : chr  "" "" "" "" ...
 $ current_gate                        : chr  "Singlets" "CD3+" "CD4+" "CD8+" ...
 $ Unnamed..0                          : chr  "" "" "" "" ...
 $ Chisq_.Intercept.                   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Chisq_illness_duration              : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Chisq_gender                        : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Chisq_age                           : num  NA NA NA NA NA NA NA NA NA NA ...

Attached is the test node & edge table attr_test.csv full_tree_edge_table.csv

Thanks, Minghao Gong

gmhhope commented 1 year ago

using cytoscapejs solves this issue

AlexanderPico commented 1 year ago

Ok. Regarding import to Cytoscape via automation, Cytoscape checks the first few values to guess the type. I see perhaps the first values were NA, so it defaults to string. You can sort your data prior to import to present numerical values first, or you can initialize column type in an explicit creation step prior to loading data.

oolonek commented 4 months ago

Ok. Regarding import to Cytoscape via automation, Cytoscape checks the first few values to guess the type. I see perhaps the first values were NA, so it defaults to string. You can sort your data prior to import to present numerical values first,

How do you do then if you have multiple columns ? Sorting might not work across all columns.

or you can initialize column type in an explicit creation step prior to loading data.

Could you please detail how to proceed ?

AlexanderPico commented 4 months ago

You can find an example in the code for the handling of Integers here: https://github.com/cytoscape/RCy3/blob/devel/R/Tables.R#L345

If you have Cytoscape running, then you can view the documentation for the CyREST API call being used here: http://localhost:1234/v1/swaggerUI/swagger-ui/index.html?url=http%3A%2F%2Flocalhost%3A1234%2Fv1%2Fswagger.json#!/Tables/createColumn

So, you can explicitly set the names and types for new columns this way, before importing the values.

A less elegant (but less coding) approach would be to lapply through each column in your data, sort it and load it. This is how you'd get around sorting across multiple columns.