-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgemboss.pl
executable file
·130 lines (118 loc) · 3.72 KB
/
pgemboss.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
my $buildno = '2.0.x';
#
# pgemboss
#
# Official web site of this script is
# https://www.fifthdimension.jp/products/phylogears/ .
# To know script details, see above URL.
#
# Copyright (C) 2008-2020 Akifumi S. Tanabe
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
my $outputfile = $ARGV[-1];
if ($outputfile !~ /^stdout$/i) {
print(<<"_END");
pgemboss $buildno
=======================================================================
Official web site of this script is
https://www.fifthdimension.jp/products/phylogears/ .
To know script details, see above URL.
Copyright (C) 2008-2020 Akifumi S. Tanabe
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
_END
}
# display usage if command line options were not specified
unless (@ARGV) {
&helpMessage();
}
my @argv;
# get output file name
my $command = $ARGV[0];
if ($outputfile !~ /^stdout$/i && -e $outputfile) {
&errorMessage(__LINE__, "\"$outputfile\" file already exists.");
}
if ($outputfile !~ /^stdout$/i) {
$outputfile = "stdout >> $outputfile";
}
else {
$outputfile = "stdout";
}
my $inputfile = $ARGV[-2];
unless (-e $inputfile) {
&errorMessage(__LINE__, "\"$inputfile\" file does not exist.");
}
# get other options
for (my $i = 1; $i < scalar(@ARGV) - 2; $i ++) {
push(@argv, $ARGV[$i]);
}
unless (@argv) {
&errorMessage(__LINE__, "Options for EMBOSScommands are not specified.");
}
# begin read input file
unless (open(INFILE, "< $inputfile")) {
&errorMessage(__LINE__, "Cannot open \"$inputfile\".");
}
my $num = 1;
# make single sequence temporary file
unless (open(OUTFILE, "> $inputfile.$num.gbk")) {
&errorMessage(__LINE__, "Cannot make temporary file \"$inputfile.$num.gbk\".");
}
while (<INFILE>) {
if ($_ !~ /^\r?\n?$/) {
print(OUTFILE);
}
if (/^\/\//) {
close(OUTFILE);
# extract to output file
system(join(' ', $command, @argv) . " $inputfile.$num.gbk $outputfile");
# delete temporary file
unlink("$inputfile.$num.gbk");
$num ++;
# make next temporary file
unless (open(OUTFILE, "> $inputfile.$num.gbk")) {
&errorMessage(__LINE__, "Cannot make temporary file \"$inputfile.$num.gbk\".");
}
}
}
close(OUTFILE);
# delete temporary file
unlink("$inputfile.$num.gbk");
sub errorMessage {
my $lineno = shift(@_);
my $message = shift(@_);
print("ERROR!: line $lineno\n$message\n");
print("If you want to read help message, run this script without options.\n");
exit(1);
}
sub helpMessage {
print <<"_END";
Usage
=====
pgemboss EMBOSScommands options inputfile outputfile
Acceptable input file formats
=============================
GenBank
_END
exit;
}