cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to load csv in matrix form and create relationship

I have a csv which is in matrix form and i want to extract values of those

csv file is like:

|Regulon_ID | SelfSufficiencyInGrowthSignals | InsensitivityToAntigrowthSignals|
|R-0 | 1 | 1|

I want to extract values of this eg: R-0 and SelfSufficiencyInGrowthSignals as value 1

i have node Regulon and mark
Regulon node contains Regulon_ID which is R-0,R-1

and second node mark which contains column names of this csv ----------eg.SelfSufficiencyInGrowthSignals,InsensitivityToAntigrowthSignals

how can i create relationship with values .

10 REPLIES 10

Hi kanthalepriyanka, welcome!

If I understand what do you want to do, I suggest something like this:

LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line FIELDTERMINATOR '|'
MATCH (r:Regulon{Regulon_ID: line.Regulon_ID}), (s:SelfSufficiencyInGrowthSignals{name: 'SelfSufficiencyInGrowthSignals'}), (i:InsensitivityToAntigrowthSignals{name: 'InsensitivityToAntigrowthSignals'})
CREATE (r)-[:HAVE {value: line.SelfSufficiencyInGrowthSignals}]->(s)
CREATE (r)-[:HAVE {value: line.InsensitivityToAntigrowthSignals}]->(i)

hey

this makes two different relationship i want to create only one relationship .

Hi Priyanka,

Your requirement is not very clear. However if you looking just one relationship then try
LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
create (r:Regulon{Regulon_ID: line.Regulon_ID})
create (s:Mark{name: line.SelfSufficiencyInGrowthSignals})
create (i:Mark{name: line.InsensitivityToAntigrowthSignals})

MATCH (m:Mark)
WITH m.name as name, collect(m) as nodes
CALL apoc.refactor.mergeNodes(nodes, {properties: "combine"}) YIELD node
RETURN node;

Create (r:Regulon)-[:HAVE ]->(m:Mark)

Instead of creating nodes and immediately merging, you can create the node in one instance;

merge (r:Regulon{Regulon_ID: line.Regulon_ID})
merge (s:Mark{selfsufficieny: line.SelfSufficiencyInGrowthSignals, insensitivity: line.InsensitivityToAntigrowthSignals})
merge (r:Regulon)-[:HAVE ]->(m:Mark)

yeah !!! how to iterate column of csv in neo4j without giving conditions?

Sorry,, did not understand

LOAD CSV WITH HEADERS FROM 'file:///Lin.csv' AS line

MATCH (r:regulons)
WHERE r.Regulon_ID=line.Regulon_ID
MATCH (h:marks) WHERE (h.hallmark = 'SelfSufficiencyInGrowthSignals')
FOREACH (ignoreMe in CASE
WHEN exists(h.hallmark) THEN [line.SelfSufficiencyInGrowthSignals]
ELSE [line.InsensitivityToAntigrowthSignals] END| CREATE (r)-[:REGULON_TO_HALLMARK { value1:line.SelfSufficiencyInGrowthSignals
}]->(h))

I made this relationship but this relationship is only for SelfSufficiencyInGrowthSignals i want to add InsensitivityToAntigrowthSignals also in this relationship .so how will i be able to do this???

Please try this
MATCH (h:marks) WHERE (h.hallmark = 'SelfSufficiencyInGrowthSignals')
FOREACH (ignoreMe in CASE
WHEN h.hallmark = 'SelfSufficiencyInGrowthSignals' CREATE (r)-[:REGULON_TO_HALLMARK { value1:line.SelfSufficiencyInGrowthSignals
}]->(h)
When h.hallmark = 'InsensitivityToAntigrowthSignals' CREATE (r)-[:REGULON_TO_HALLMARK { value1:line.InsensitivityToAntigrowthSignals
}]->(h) END)

OK i will try this and let u know

I DID THE QUERY WHICH WORKED FOR ME
LOAD CSV WITH HEADERS FROM 'filename' AS line
MATCH (r:regulons)
WHERE r.Regulon_ID=line.Regulon_ID
MATCH (h:marks) WHERE (h.mark <> keys(line))
FOREACH (ignoreMe in CASE
WHEN exists(h.mark) AND line[h.mark] THEN [line]
ELSE END | CREATE (r)-[:REGULON_TO_MARKS{value:line[h.mark]}]->(h))

WHICH WILL CREATE ONE RELATIONSHIP and TAKE VALUE of it in edge