File: insert_ad_doc_cv.pl

package info (click to toggle)
libchado-perl 1.23-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,976 kB
  • ctags: 10,378
  • sloc: xml: 192,540; sql: 165,945; perl: 28,339; sh: 101; python: 73; makefile: 46
file content (32 lines) | stat: -rwxr-xr-x 1,262 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env perl
use strict;
use warnings;

open ONTO, "ad_hoc_cv" or die "couldn't open ad_hoc_cv:$!\n"; 
open INSERTS, ">cv_inserts.sql" or die "couldn't open cv_inserts.sql: $!\n";

my $cv;

while (<ONTO>) {
    if (/^#/) {
        print INSERTS "\n";
    }
    elsif (/^\[(.+)\]/) {
        $cv = $1;
        print INSERTS "INSERT INTO cv (name) VALUES ('$cv');\n";
    } elsif (/^(.+)$/) {
        my $term=$1;
        if ($term =~ /(.+)\s+\[REL\]/) {
            my $cvterm = $1;
            print INSERTS "INSERT INTO dbxref (db_id,accession) VALUES ((select db_id from db where name='null'), '$cv:$cvterm');\n";
            print INSERTS "INSERT INTO cvterm (cv_id,name,dbxref_id,is_relationshiptype) VALUES ((select cv_id from cv where name='$cv'),'$cvterm',(select dbxref_id from dbxref where accession='$cv:$cvterm'),1);\n";
        } else {
            my $cvterm = $term;
            print INSERTS "INSERT INTO dbxref (db_id,accession) VALUES ((select db_id from db where name='null'), '$cv:$cvterm');\n";
            print INSERTS "INSERT INTO cvterm (cv_id,name,dbxref_id) VALUES ((select cv_id from cv where name='$cv'),'$cvterm',(select dbxref_id from dbxref where accession='$cv:$cvterm'));\n";
        }
    }
}
close ONTO;
close INSERTS;