-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_CDSs.pl
More file actions
executable file
·61 lines (46 loc) · 1.41 KB
/
Copy pathget_CDSs.pl
File metadata and controls
executable file
·61 lines (46 loc) · 1.41 KB
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
#!/usr/bin/perl -w
use strict;
use Bio::SeqIO;
my ($gbk, $cds) = @ARGV;
my $in = Bio::SeqIO->new(-format => 'genbank',
-file => $gbk);
my $out = Bio::SeqIO->new(-format => 'fasta',
-fh => \*STDOUT);
# loop over records
while (my $seq = $in->next_seq) {
# get definition or description of sequence
my $def = $seq->desc;
# get species name
my $strain = $seq->species->node_name;
# loop over features
for my $ft ($seq->get_SeqFeatures) {
# skip all non-CDS features
next unless ($ft->primary_tag eq 'CDS');
# skip CDS features that have pseudo tags
next if ($ft->has_tag('pseudo'));
# get CDS accession
my ($acc) = $ft->get_tag_values('protein_id') if ($ft->has_tag('protein_id'));
# print $acc, "\n";
# get CDS product names
my ($prod) = $ft->get_tag_values('product') if ($ft->has_tag('product'));
# print $prod, "\n";
# make fasta header
my $hdr;
$hdr = $strain . '_i_' . $acc . '_l_' . $prod;
$hdr =~ s/\s/_/g;
# print $hdr, "\n";
# get sequence of CDS
my ($aa_seq) = $ft->get_tag_values('translation') if ($ft->has_tag('translation'));
# print $aa_seq, "\n";
# provide $ft_seq with new id and description and print out
my $outseq_obj = Bio::Seq->new(-seq => $aa_seq,
-id => $hdr,
-desc => '',
);
# my $ft_seq;
# $ft_seq->seq($aa_seq);
# # $ft_seq->id($hdr);
# # $ft_seq->desc('');
$out->write_seq($outseq_obj);
}
}