-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_KAAS.pl
executable file
·49 lines (40 loc) · 1.39 KB
/
load_KAAS.pl
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
#!/usr/bin/perl
use Getopt::Std;
use DBI;
use strict;
use lib $ENV{SCRIPTS};
use ENV;
my %arg;
&getopts('D:u:p:i:', \%arg);
my $user = $arg{'u'};
my $password = $arg{'p'};
my $db = $arg{'D'};
my $host = $ENV{DBSERVER} ? $ENV{DBSERVER} : 'localhost';
my $dbh = DBI->connect("dbi:mysql:host=$host;database=$db", $user, $password);
if (! $dbh) { die "Couldn't connect with $host / $db / $user / $password\n";}
my $infile = $arg{'i'};
if (! $infile) { die "No KAAS file provided with -i\n";}
if (! -r $infile) { die "$infile is not readable: $!\n";}
open my $in, $infile or die "Can't open $infile: $!\n";
while (my $line = <$in>) {
chomp $line;
my ($acc, $ko) = split/\s+/, $line;
next if (! $ko);
my @acc = split/\|/, $acc;
my $fid = &get_feature_id_by_accession($dbh, $acc[0]);
my $len = &get_feature_product_length($dbh, $fid);
my $ev_i = "INSERT INTO feature_evidence (feature_id, ev_accession, feat_min, feat_max, ev_type, program)"
. " VALUES ($fid, \"$ko\", 1, $len, \"KO\", \"KAAS\")\n";
$dbh->do($ev_i);
}
sub get_feature_product_length {
my $dbh = shift;
my $fid = shift;
my $fq = "SELECT length(product) FROM sequence_features WHERE feature_id=$fid";
my @l = $dbh->selectrow_array($fq);
if ($l[0]==0) {
my $mq = "SELECT (feat_max - feat_min + 1)/3 from seq_feat_mappings m where feature_id=$fid";
@l = $dbh->selectrow_array($mq);
}
return $l[0];
}