-
Notifications
You must be signed in to change notification settings - Fork 10
/
faclean
executable file
·45 lines (39 loc) · 934 Bytes
/
faclean
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
#!/usr/bin/perl
# Reformat and optionally remove short contigs from a FASTA file
# Copyright 2012 Shaun Jackman
use strict;
use Getopt::Std qw'getopts';
my %opt;
getopts 'c:l:L:', \%opt;
my $opt_columns = defined $opt{'c'} ? $opt{'c'} : 0;
my $opt_min_length = defined $opt{'l'} ? $opt{'l'} : 0;
my $opt_max_length = defined $opt{'L'} ? $opt{'L'} : 2000000000;
while (<>) {
next if /^#/;
die unless /^>/;
chomp;
#my $header = $_;
my ($id, $comment) = split ' ', $_, 2;
my $seq = '';
while (<>) {
next if /^#/;
last if /^>/;
chomp;
$seq .= $_;
}
# Skip short sequences.
my $len = $seq =~ tr/ACGTacgt//;
if ($opt_min_length <= $len && $len < $opt_max_length) {
#print $header, "\n";
#print $id, ' ', $comment, "\n";
print $id, "\n";
if ($opt_columns > 0) {
print substr($seq, 0, $opt_columns, ''), "\n"
while length $seq > 0;
} else {
print $seq, "\n";
}
}
redo if /^>/;
last if eof;
}