-
Notifications
You must be signed in to change notification settings - Fork 2
/
fa2primer3.pl
executable file
·69 lines (62 loc) · 1.37 KB
/
fa2primer3.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
#!/usr/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: [email protected]
=cut
use 5.012;
use warnings;
use Getopt::Long;
use File::Basename;
my $threeEnd;
GetOptions(
'3=i' => \$threeEnd,
'h|help' => sub{usage()}
) || usage();
$ARGV[0] = '-' unless defined $ARGV[0];
open IN, "$ARGV[0]" or die "Can't read file ($ARGV[0]): $!";
my ($title, $seq);
$title = <IN>;
while(<IN>){
chomp;
if(/^>/){
&output($title, $seq);
$title = $_;
$seq = '';
}else{
$seq .= $_;
}
}
&output($title, $seq);
sub output{
my ($title, $seq) = @_;
$title =~ /^>(.+)/;
my $id = $1;
print <<EOF;
SEQUENCE_ID=$id
SEQUENCE_TEMPLATE=$seq
EOF
if(defined $threeEnd){
my $seqLen = length $seq;
my ($start, $length);
if($threeEnd <= $seqLen){
$start = $seqLen - $threeEnd;
$length = $threeEnd;
}else{
$start = 0;
$length = $seqLen;
}
say "SEQUENCE_INCLUDED_REGION=$start,$length";
}
say "=";
}
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: perl $scriptName INPUT >OUTPUT
If INPUT isn't specified, input from STDIN
Option:
-3 INT Only search primer within the INT bp to the three prime of the sequence
-h --help Print this help information
HELP
exit(-1);
}