Migrate query: Key not present in data error


#1

Hi all,

I’m having a question related to the migrate query starting from a csv.
I have a csv file containing the following columns: SNP, gene where the gene column is a list of values, separated by ;. For example:

SNP,gene
A1,X1;X2
A2,X3;X4

For every row, I want to add new relationships between a SNP and every gene in the gene column (SNP and GENE are loaded in the keyspace already).

Therefore, I was using the split macro in my migrate query:

for (element in @split(<gene>, ';')) do {
    match $s isa SNP has identifier <SNP>;
    match $g isa Gene has approved_symbol <element>;
    insert(gene: $g, snp: $s) isa SNP_GENE_ASSOCIATION;
}

However, this does not seem to work as the <SNP> information is not available. This is the message that is returned:

Query not sent to server: Key [<SNP>] not present in data: [{SNP=A1, gene=X1}]

How do I get access to the information in the SNP column?

Thanks,
Greet


#2

The error message here is certainly a bit confusing as the SNP key is definitely there. Maybe it’s a data structure/access issue?


#3

Hi @GreetDB,

do you have the SNP and Genes data in your db already, before creating the relationship?
Otherwise you might need to insert the SNP and genes
before creating all the relationships, something like:

insert $s isa SNP has identifier <SNP>;
for (element in @split(<gene>, ';')) do {
    $<element> isa Gene has approved_symbol <element>;
    (gene: $<element>, snp: $s) isa SNP_GENE_ASSOCIATION;
}

This should result in:

insert 
$s isa SNP has identifier A1;
$X1 isa gene has approved_symbol X1:
(gene: $X1, snp: $s) isa SNP_GENE_ASSOCIATION;
$X2 isa gene has approved_symbol X2;
(gene: $X2, snp: $s) isa SNP_GENE_ASSOCIATION;

You can also run your migration script with -n argument and you will be able to see the queries that get generated from your migration template:
./graql migrate csv -template <arg> -input <arg> -keyspace <arg> -n >> debugfile.txt
will print the queries in the debugfile.txt

If it still doesnt work, join our community channel in Slack and we will be able to help you!

Let us know,

Marco