-
Notifications
You must be signed in to change notification settings - Fork 0
/
fasta-length
executable file
·77 lines (63 loc) · 1.29 KB
/
fasta-length
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
#! /usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin";
use PVS;
# ------------------------------------------------------------------------
use File::Basename;
use Getopt::Std;
our $opt_f;
our $opt_h;
our $opt_t;
my $usage_str = "";
my $progname = basename($0);
$usage_str .= "Usage: $progname [options] ...\n";
$usage_str .= "-f - print names with lengths\n";
$usage_str .= "-h - print help\n";
$usage_str .= "-t - print total of all lengths\n";
sub usage {
print STDERR $usage_str;
exit(@_);
}
my $stat = getopts('fht');
if (!$stat) {
usage(1);
}
if ($opt_h) {
usage();
}
if (scalar(@ARGV) > 1) {
usage(1);
}
# ------------------------------------------------------------------------
my ($file,$nothing) = @ARGV;
if ( !defined($file) ) {
$file = "-";
}
my %h = PVS::read_fasta($file);
my @keys = sort (keys %h);
if ($#keys == 0 && !$opt_f ) {
my $k = $keys[0];
my $v = $h{$k};
print length($v),"\n";
exit;
}
if ( $opt_t ) {
my $total_length = 0;
foreach my $k ( @keys ) {
my $v = $h{$k};
my $l = length($v);
$total_length += $l;
}
print $total_length,"\n";
} else {
foreach my $k ( @keys ) {
my $v = $h{$k};
my $l = length($v);
if ( $k =~ /gi\|[0-9]+\|ref\|([^\|.]+)/ ) {
$k = $1;
}
print "$l\t$k\n";
}
}