-
Notifications
You must be signed in to change notification settings - Fork 0
/
gbk2fna
executable file
·70 lines (60 loc) · 1.34 KB
/
gbk2fna
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
#! /usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Carp::Always;
# use FindBin;
# use lib "$FindBin::Bin";
# use Xyzzy;
use constant { TRUE => 1, FALSE => 0 };
# ------------------------------------------------------------------------
# Process the command line
# ------------------------------------------------------------------------
use File::Basename;
use Getopt::Std;
our $opt_h;
our $opt_n;
sub usage {
my $progname = basename($0);
print STDERR "Usage: $progname [options] < genome.gbk > sequences.fna\n";
print STDERR "-n NAME - Use NAME as locus name for a single sequence\n";
print STDERR "-h - print help\n";
exit(@_);
}
my $stat = getopts('hn:');
if (!$stat) {
usage(1);
}
if ($opt_h) {
usage();
}
if (scalar(@ARGV) != 0) {
usage(1);
}
# ------------------------------------------------------------------------
my $count = 0;
my $locus;
my $printing = 0;
while ( <STDIN> ) {
chomp;
if ( $_ =~ "^//" ) {
$printing = 0;
$locus = undef;
} elsif ( $printing ) {
$_ =~ s/^ +[0-9]+//;
$_ =~ s/[ \t]+//g;
print $_,"\n";
} elsif ( $_ =~ /^LOCUS +([^ ]+)/ ) {
$count++;
$locus = $1;
} elsif ( $_ =~ /^ORIGIN/ ) {
if ($opt_n) {
if ($count > 1) {
die "More than one sequence found,";
}
print ">$opt_n\n"
} else {
print ">$locus\n";
}
$printing = 1;
}
}