cytoscape / cyREST

Core App: REST API module for Cytoscape
https://github.com/cytoscape/cyREST/wiki
MIT License
30 stars 13 forks source link

import table file failed CyREST #105

Closed slfan2013 closed 4 years ago

slfan2013 commented 4 years ago

I cannot import the table file correctly. I can import the network file but cannot import the table file.

The table headers are read but not the content. Please see the figures.

截屏2019-10-31下午8 32 12

The code I am using is as follows,

# add a new network
RCurl::getURL(URLencode("http://localhost:1234/v1/commands/network/import file"),customrequest='POST',httpheader=c('Content-Type'='application/json'),postfields=  jsonlite::toJSON(
  list(
    columnTypeList="source,interaction,target",
    dataTypeList="i,s,i",
    file=paste0(getwd(),"/GCTOF/GCTOF_Abraham_M_v_CM_Dobutamine/MetaMapp/chemsim_krp_07.sif"),
    firstRowAsColumnNames="false"
  ), auto_unbox = T, force = T))

# set attributes.
RCurl::getURL(URLencode("http://localhost:1234/v1/commands/table/import file"),customrequest='POST',httpheader=c('Content-Type'='application/json'),postfields=  jsonlite::toJSON(
  list(
    # caseSensitiveNetworkKeys="true",
    # dataTypeList="i,s,s,s,d,d,s",
    # dataTypeTargetForNetworkCollection="Node Table Columns",
    # dataTypeTargetForNetworkList="Node Table Columns",
    # delimiters="\t",
    # delimitersForDataList="\t",
    file=paste0(getwd(),"/GCTOF/GCTOF_Abraham_M_v_CM_Dobutamine/MetaMapp/node_attributes_chemsim_krp_07.tsv"),
    firstRowAsColumnNames="true",
    # keyColumnForMapping="shared name",
    keyColumnIndex="1",
    # newTableName="table",
    # whereImportTable="To a Network Collection",
    startLoadRow="2"

  ), auto_unbox = T, force = T))

The files I am using can be downloaded network here and table here.

AlexanderPico commented 4 years ago

You were very close! I got it work with the following parameters:

dataTypeTargetForNetworkCollection="Node Table Columns",
dataTypeList="s,s,s,s,d,d,s",
delimiters="\t",
file=paste0(getwd(),"/GCTOF/GCTOF_Abraham_M_v_CM_Dobutamine/MetaMapp/node_attributes_chemsim_krp_07.tsv"),
firstRowAsColumnNames="true",
keyColumnIndex="1",
whereImportTable="To a Network Collection",
startLoadRow=“2"

I think the main issue was with dataTypeList. Note that key columns should always be STRING type (s), even if they are technically integers. You’ll notice that after the SIF import, the name and shared names are STRING type. So, when Cytoscape then tries to read in your table data, it sees INT types and Java can’t safely match INTs and STRINGs, so no matches are found and no data are loaded. By forcing the key column to be STRING (the first ’s’ in dataTypeList) this issue is resolved.

If it is helpful, I troubleshooted this case using the Swagger interface (Help > Automation > CyREST Commands API). This makes it easy to try a bunch of things without worrying about confounding errors coming from local setup, etc. You can also work on the syntax directly in Cytoscape via the Automation Panel (View > Show Automation Panel). I almost always work out syntax here first before scripting.

Also, there is an RCy3 package that provides helpful wrapper functions around all this syntax so you don’t have to worry about it! See recent paper: https://f1000research.com/articles/8-1774/v1