Variable not defined but the variable already exists

Hi,

I am trying to bulid the relationship between my nodes.

However, the "variable not defined "error messages keep pop up in my neo4j browser, even though the variable existed.

When I run this

LOAD CSV WITH HEADERS FROM 'file:///genes2hallmark.csv' AS link
MATCH (g:gene{ENS_ID: topTable.ID}),(hmgs:HMGS{hallmark_gene_sets: hmgenesets.hallmark_genesets})
WITH g, hmgs
MERGE (g)-[r:BELONG]->(hmgs)

Gives me the error message:

Variable topTable not defined (line 2, column 23 (offset: 86))
"MATCH (g:gene{ENS_ID: topTable.ID}),(hmgs:HMGS{hallmark_gene_sets: hmgenesets.hallmark_genesets})"

Anyone can give me a hints about this?

Thank you so much.



My code and data --------------------------------------------------------------------------------------------------------------------------- - neo4j version 3.5.14, browser version 3.2.26 - API / driver: I am using neo4j browser
My cypher query as following (I run them in order): > USING PERIODIC COMMIT 1000 > LOAD CSV WITH HEADERS FROM 'file:///hmgs.csv' AS hmgenesets > MERGE (hmgs:HMGS{hallmark_gene_sets: hmgenesets.hallmark_genesets}) > WITH hmgs > MATCH (hmgs) > RETURN (hmgs)

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM 'file:///topTable.csv' AS topTable
MERGE (g:gene
{ENS_ID: topTable.ID,
log_FG: topTable.logFC,
Average_Expression: topTable.AveExpr,
t_test: topTable.t,
P_value: topTable.P_Value,
Adjusted_P_value: topTable.adj_P_Val,
entrez_id: topTable.entrezid,
gene_name: topTable.gene_name})
WITH (g)
MATCH (g)
RETURN (g)

LOAD CSV WITH HEADERS FROM 'file:///genes2hallmark.csv' AS link
MATCH (g:gene{ENS_ID: topTable.ID}),(hmgs:HMGS{hallmark_gene_sets: hmgenesets.hallmark_genesets})
WITH g, hmgs
MERGE (g)-[r:BELONG]->(hmgs)


The topTable.csv looks like this:

ID,logFC,AveExpr,t,P_Value,adj_P_Val,entrezid,gene_name
E971,3,8,3,8,1,5,FO
E938,3,8,3,8,1,5,F

The geneshallmark.csv looks like this:

gene_id,geneset
E938,HALLMARK_A
E971,HALLMARK_C
E971,HALLMARK_C

The hmgs.csv looks like this:

hallmark_genesets
HALLMARK_A
HALLMARK_C

Where exactly are you getting the variable does not exist error?

Hi,

Thank you for your reply.
The error message is

Variable topTable not defined (line 2, column 23 (offset: 86))
"MATCH (g:gene{ENS_ID: topTable.ID}),(hmgs:HMGS{hallmark_gene_sets: hmgenesets.hallmark_genesets})"

So the I think it stands for the variable topTable is not defined. But I defined it in

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM 'file:///topTable.csv' AS topTable

Ok, it looks like the problem is you're calling that topTable, without providing the ID. Yes you've created it, but you would need to provide the ID again as a parameter. You can't simply just call it again. You need to have a list of the IDs you're trying to call and match to the links. You could probably collect the ids before hand and loop through them like:

MATCH (g:gene)
with COLLECT(g.ENS_ID) as ids
......

Then you'd be able to match them correctly and go on.

Hi, you are referring to a variable defined in another query.

Here the variable available for you is "link"

gene_id,geneset
E938,HALLMARK_A
E971,HALLMARK_C
E971,HALLMARK_C

Based on this data set change the code to

LOAD CSV WITH HEADERS FROM 'file:///genes2hallmark.csv' AS link
MATCH (g:gene{ENS_ID: link.gene_id}),(hmgs:HMGS{hallmark_gene_sets: link.geneset})
WITH g, hmgs
MERGE (g)-[r:BELONG]->(hmgs)

This should work.

Thank you so much for your reply.

It works!