File: insert_ad_doc_cv.pl

package info (click to toggle)
libchado-perl 1.22-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 24,024 kB
  • sloc: xml: 192,540; sql: 165,936; perl: 28,298; sh: 101; python: 73; makefile: 46
file content (31 lines) | stat: -rwxr-xr-x 1,247 bytes parent folder | download
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
#!/usr/bin/perl -w
use strict;

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;