-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlucyTrim.pl
70 lines (56 loc) · 1.22 KB
/
lucyTrim.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
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
#use vars qw($opt_f);
my %opts;
getopts('f:',\%opts);
&varcheck;
my ($outPre,$outPost,$outName);
if ($opts{'f'} =~ /\./){
$opts{'f'} =~ /(.*)\.(.*)/;
$outName = $1."_trim\.".$2;
}
else {
$outName = $opts{'f'}."_trim";
}
open (FA,$opts{'f'}) or die "Can't open $opts{'f'}\n";
open (OF,">$outName") or die "Can't open out\n";
my %headerInfo;
my $sequence="";
while (my $line = <FA>){
chomp $line;
if ($line =~ />/ || eof FA) {
if ($sequence ne "" || eof FA){
$sequence .= $line if eof FA;
my $trimmedLen = $headerInfo{'stop'} - $headerInfo{'start'} + 1;
my $trimmedSeq = substr($sequence,$headerInfo{'start'}-1,$trimmedLen);
print OF ">$headerInfo{'name'}\n$trimmedSeq\n";
}
if ($line =~ />/){
my @lsplit = split(/\s/,$line);
$lsplit[0] =~ />(.*)/;
$headerInfo{'name'} = $1;
$headerInfo{'start'} = $lsplit[4];
$headerInfo{'stop'} = $lsplit[5];
}
}
else {
$sequence .= $line;
}
}
sub varcheck {
#print "f=$options{'f'}\n";
if (!$opts{'f'}) {
print "No filename provided.\n";
&usage;
}
}
sub usage{
print STDERR "\nusage: perl \n";
print STDERR "\n\n";
print STDERR "\n";
print STDERR "\n";
print STDERR "\n\n";
exit;
}