File: gencode2sql.pl

package info (click to toggle)
libchado-perl 1.31-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 44,716 kB
  • sloc: sql: 282,721; xml: 192,553; perl: 25,524; sh: 102; python: 73; makefile: 57
file content (64 lines) | stat: -rwxr-xr-x 1,507 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
#This is old code and hasn't been tested!
use strict;
use warnings;

my @nucs = qw(T C A G);
my $x = 0;
my @codons = ();
for my $i (@nucs) {
    for my $j (@nucs) {
        for my $k (@nucs) {
            my $codon = "$i$j$k";
            $codons[$x] = $codon;
            $x++;
        }
    }
}

print "-- autogenerated by gencode2sql.pl from NCBI gencode.dmp\n";
print "SET search_path=public,genetic_code;\n";

my @rows=();
while(<>) {
    chomp;
    push(@rows, [split(/\s*\|\s*/,$_)]);
}
foreach (@rows) {
    my ($id,$x,$n,$code,$starts) = @$_;
    printf("INSERT INTO gencode (gencode_id,organismstr) VALUES (%d,%s);\n", $id, pquote($n));
}
foreach (@rows) {
    my ($id,$x,$n,$code,$starts) = @$_;
    next unless $id;
    my @codes = split('',$code);
    for (my $i=0;$i<64;$i++) {
        printf("INSERT INTO gencode_codon_aa (gencode_id,codon,aa) VALUES (%d,%s,%s);\n", 
               $id,
               pquote($codons[$i]),
               pquote($codes[$i]));
    }
}
foreach (@rows) {
    my ($id,$x,$n,$code,$start) = @$_;
    next unless $id;
    my @starts = split('',$start);
    for (my $i=0;$i<64;$i++) {
        printf("INSERT INTO gencode_startcodon (gencode_id,codon) VALUES (%d,%s);\n", 
               $id,
               pquote($codons[$i]))
          if $starts[$i] eq 'M';
    }
}

sub pquote {
    my $s = shift;
    $s='' unless defined $s;
    if ($s =~ /^\-?[0-9]+$/) {
	return $s;
    }
    return "''" unless $s;
    $s =~ s/\'/\'\'/g;
    "'$s'";
}