-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_id_list_to_pep.pl
executable file
·63 lines (57 loc) · 1.43 KB
/
feature_id_list_to_pep.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
#!/usr/bin/perl
use lib $ENV{SCRIPTS};
use ENV;
use DBI;
use Getopt::Std;
use Bio::SeqIO;
&getopts('D:i:o:');
my $host = $ENV{DBSERVER} ? $ENV{DBSERVER} : 'localhost';
my $dbh = DBI->connect("dbi:mysql:host=$host;db=$opt_D", 'access', 'access');
my $setid = $opt_i;
my $setname = $opt_n;
my $outfh;
if ($opt_o) {
$outfh = Bio::SeqIO->new(-file => ">$opt_o",
-format => 'fasta');
} else {
$outfh = Bio::SeqIO->new(-fh => \*STDOUT,
-format => 'fasta');
}
my @feat_ids;
if ($opt_i) {
open my $in, $opt_i;
while (my $line=<$in>) {
my @f = split/\s+/, $line;
push @feat_ids, $f[0];
}
} else {
while ($l = <STDIN>) {
chomp $l;
if (!$l) { last }
$l =~ s/^>//;
my @f = split/\s/, $l;
push @feat_ids, $f[0];
}
}
my $protref = &get_protein_by_feature_id($dbh, @feat_ids);
foreach my $fid (keys %{$protref}) {
my $acc = join "|", @{$protref->{$fid}->{'accessions'}};
if (length($protref->{$fid}->{'product'}) == 0 ||
!defined($protref->{$fid}->{'product'})) {
warn "No product string for feature $fid ($acc). Skipping...";
next;
}
my $desc;
while (my ($k,$v) = each %{$protref->{$fid}->{'annotation'}}) {
if ($k eq "product") { $desc = $v->[0] . " " . $desc; }
else {
foreach my $val (@$v) {
$desc .= " [$k=$val]";
}
}
}
my $seqo = Bio::Seq->new(-display_id => $acc,
-desc => $desc,
-seq => $protref->{$fid}->{'product'});
$outfh->write_seq($seqo);
}