-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_dbCAN_to_ENV.pl
executable file
·170 lines (144 loc) · 5.52 KB
/
load_dbCAN_to_ENV.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl
#edited by JMo January 12 2016 to update for format of new dbCAN output file after dbCAN parsing
#see readme file in scripts/db/hmm/dbCAN for specifics
use lib $ENV{ENVSCRIPTS};
use ENV;
use strict;
use Getopt::Std;
use DBI;
use Cwd;
my $host = $ENV{'DBSERVER'} ? $ENV{'DBSERVER'} : 'localhost';
my %arg;
&getopts('D:p:u:d:h',\%arg);
my $USER = $arg{'u'} ? $arg{'u'} : $ENV{'USER'};
my $PSWD = $arg{'p'} or die "Need to provide database password with -P\n";
my $DB = $arg{'D'} or die "Need to provide database with -D\n";
if ($arg{'h'}) {
print "USAGE load_dbCAN_to_ENV.pl -D db -P dbpassword -d dbCANoutputdirectorypath [-U user ]\n";
}
my $dbh = DBI->connect("dbi:mysql:host=$host;db=$DB", $USER, $PSWD);
my $path = $arg{'d'} or die "Need to provide dbCAN output directory with -d\n";
cwd($path) or die "Can't change path to $path? : $!\n";
opendir(DIR, $path) or die "cannot open directory: $!\n";
my @files = grep(/\.out$/,readdir(DIR));
foreach my $file (@files) {
$file = $path . "/" . $file;
################################################################################
########## dbCAN HMMER
################################################################################
if ($file =~ /hmmer/) {
open (my $HMM, "$file") or die "Can't open $file. Is path correct? $!\n";
my $delete_q = "DELETE e FROM feature_evidence e"
. " WHERE e.feature_id=?"
. " AND e.ev_accession = ?"
. " AND e.ev_type = 'CAZy'"
. " AND e.program='dbCAN'";
my $dsth = $dbh->prepare($delete_q);
my $insert_q = "INSERT INTO feature_evidence"
. " (feature_id, feat_min, feat_max, program, ev_type, ev_accession, ev_min, ev_max, ev_length, score)"
. " VALUES(?, ?, ?, \"dbCAN\", \"CAZy\", ?, ?, ?, ?, ?)";
my $isth = $dbh->prepare($insert_q);
my $linecount = 0;
while (my $line = <$HMM>) {
if ($line =~ /^HMM/) { next }
$linecount++;
chomp $line;
my ($hacc,
$hmm_len,
$feat_acc,
$gene_len,
$evalue,
$hmm_start,
$hmm_end,
$gene_start,
$gene_end,
$cov) = split(/\t/,$line);
if ($evalue > 1e-15 || $cov < 0.35) { next }
my $fid = &get_feature_id_by_accession($dbh, $feat_acc);
if (! $fid) { warn "HMMer: Can't get feature_id from '$line'. Not loading this one.\n"; next }
my $sxs = $dsth->execute($fid, $hacc);
if (! $sxs) { print STDERR $dbh->errstr() }
my $sxs = $isth->execute($fid, $gene_start, $gene_end, $hacc, $hmm_start, $hmm_end, $hmm_len, $evalue);
if (! $sxs) { print STDERR $dbh->errstr() }
}
} elsif ($file =~ /HotPep/) {
################################################################################
########## HOTPEP/PPR
################################################################################
open (my $HPEP, $file) or die "Can't open $file. Is path correct? $!\n";
my $HP_delete_q = "DELETE e FROM feature_evidence e"
. " WHERE e.feature_id = ?"
. " AND e.ev_accession = ?"
. " AND e.program='HotPep'"
. " AND e.ev_type='CAZy'";
my $HPdsth = $dbh->prepare($HP_delete_q);
my $HP_insert_q = "INSERT INTO feature_evidence"
. " (feature_id, feat_min, feat_max, program, ev_type, ev_accession, score)"
. " VALUES(?, 1, 2, \"HotPep\", \"CAZy\", ?, ?)";
my $HPisth = $dbh->prepare($HP_insert_q);
my $linecount;
while (my $line = <$HPEP>) {
if ($line =~ /^CAZy/) { next }
$linecount++;
chomp $line;
my ($cazy,
$ppr,
$feat_acc,
$freq,
$hits,
$peps,
$ECs) = split(/\t/, $line);
my $fid = &get_feature_id_by_accession($dbh, $feat_acc);
if (! $fid) { warn "HOTPEPPPR: Can't get feature_id from '$line'. Not loading this one.\n"; next }
my $evacc = $cazy . "(" . $ppr . ")";
my $sxs = $HPdsth->execute($fid, $evacc);
if (! $sxs) { print STDERR $dbh->errstr() }
my $sxs = $HPisth->execute($fid, $evacc, $freq);
if (! $sxs) { print STDERR $dbh->errstr() }
}
} elsif ($file =~ /diamond/) {
################################################################################
########## DIAMOND
################################################################################
open (my $DIA, $file) or die "Can't open $file. Is path correct? $!\n";
my $D_delete_q = "DELETE e FROM feature_evidence e"
. " WHERE feature_id = ?"
. " AND e.ev_accession = ?"
. " AND ev_type = 'CAZy'"
. " AND program = 'diamond'";
my $Ddsth = $dbh->prepare($D_delete_q);
my $D_insert_q = "INSERT INTO feature_evidence"
. " (feature_id, feat_min, feat_max, program, ev_type, ev_accession, ev_min, ev_max, ev_length, score)"
. " VALUES(?, ?, ?, \"diamond\", \"CAZy\", ?, ?, ?, ?, ?)";
my $Disth = $dbh->prepare($D_insert_q);
my $linecount;
while (my $line = <$DIA>) {
if ($line =~ /^Gene/) { next }
$linecount++;
chomp $line;
my ($feat_acc,
$dcazy,
$per_id,
$length,
$mismatches,
$gap,
$gene_start,
$gene_end,
$cazy_start,
$cazy_end,
$evalue,
$bits) = split(/\t/, $line);
my $fid = &get_feature_id_by_accession($dbh, $feat_acc);
if (! $fid) { warn "DIAMOND: Can't get feature_id from '$line'. Not loading this one.\n"; next }
my $cazy;
if ($dcazy =~ /((GH|GT|CE|CBM|AA|PL)\d+)/) {
$cazy = $1;
} else { warn "$feat_acc: Can't find CAZy acc in '$dcazy'. Need to update REGEX?\n"; next; }
my $sxs = $Ddsth->execute($fid, $cazy);
if (! $sxs) { print STDERR $dbh->errstr() }
my $sxs = $Disth->execute($fid, $gene_start, $gene_end, $cazy, $cazy_start, $cazy_end,
$length, $evalue);
if (! $sxs) { print STDERR $dbh->errstr() }
}
}
}