Skip to content

Commit

Permalink
Added sort -i (i.e. same order as input file) option.
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaikumar committed Oct 3, 2011
1 parent f9b84cd commit 9c248a4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fastaqual_select.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use warnings;
use Getopt::Long qw(:config pass_through no_ignore_case);

my ($fastafile,$sort,$numfasta,$length,$prefix,$regexp,$headerfile,$includefile,$excludefile,$delimiter,$case) = ("-","S","","","","","","",""," ","");
my ($fastafile,$sort,$numfasta,$length,$prefix,$regexp,$headerfile,$includefile,$excludefile,$delimiter,$case,$interval) = ("-","S","","","","","","",""," ","","");
GetOptions (
"fastafile:s" => \$fastafile,
"sort:s" => \$sort,
Expand All @@ -16,23 +16,26 @@
"excludefile:s" => \$excludefile,
"delimiter:s" => \$delimiter,
"case:s" => \$case,
"interval" => \$interval,
);

$case = uc(substr($case,0,1)) if $case;

my (%include_headers, %exclude_headers);
my (%include_headers, @include_headers_ordering, %exclude_headers);
if ($includefile)
{
open FILE,"<$includefile" or die "Couldn't open includes file $includefile\n";
while (<FILE>)
{
chomp;
if (/^>?(\S+)\s(\d+)\s(\d+)\b/ or /^>?(\S+)_(\d+)_(\d+)\b/)
if ($interval and (/^>?(\S+)\s(\d+)\s(\d+)\b/ or /^>?(\S+)_(\d+)_(\d+)\b/))
{
push @{$include_headers{$1}}, ($2 <= $3) ? [$2,$3] : [$3,$2];
push @include_headers_ordering, $1;
} elsif (/^>?(\S+)/)
{
$include_headers{$1}=1
$include_headers{$1}=1;
push @include_headers_ordering, $1;
}
}
close FILE;
Expand All @@ -57,6 +60,8 @@
@sortkeys = sort {$$seqs{$a}{order} <=> $$seqs{$b}{order}} keys %{$seqs};
} elsif (uc($sort) eq "A") {
@sortkeys = sort keys %{$seqs};
} elsif (uc($sort) eq "I") {
@sortkeys = @include_headers_ordering;
} else {
@sortkeys = sort {length($$seqs{$b}{seq}) <=> length($$seqs{$a}{seq})} keys %{$seqs};
}
Expand Down

0 comments on commit 9c248a4

Please sign in to comment.