forked from tomdeman-bio/Sequence-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontig_size_select.pl
77 lines (71 loc) · 1.48 KB
/
contig_size_select.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
#! /usr/bin/perl
#Copied from Umer Zeeshan Ijaz at University of Glasgow
use strict;
use Getopt::Long;
my ($low,$high)=(0,99999999);
GetOptions( "low=i" => \$low,
"high=i" => \$high,
"help|?" => sub {Usage()}
);
sub Usage
{
print STDERR "perl $0 -low <lower_bound> -high <higher_bound> <fasta_file>\n\n";
exit;
}
if (scalar(@ARGV)!=1) {print STDERR "Please give one input fasta file\n";&Usage;}
my $seq;
my $id;
my $len;
my @seq;
open (IN,"$ARGV[0]") or die ":$!";
while(<IN>)
{
chomp;
if(/^>(.*)/)
{
if ($seq){
if ($seq=~/\d+/)
{
chop $seq;
@seq = split /\s+/,$seq;
$len=scalar(@seq);
}
else
{
$len=length ($seq);
}
if ($len>=$low and $len<=$high){
print ">$id\n$seq\n";
}
}
$id =$1;
$seq ="";
}
else
{
if ($_ =~/\d+/) # for qual file
{
$seq .= $_." ";
}
else
{
$seq .= $_;
}
}
}
if ($seq){
if ($seq=~/\d+/)
{
chop $seq;
@seq = split /\s+/,$seq;
$len=scalar(@seq);
}
else
{
$len=length ($seq);
}
if ($len>=$low and $len<=$high){
print ">$id\n$seq\n";
}
}
close IN;