Skip to content

Instantly share code, notes, and snippets.

@maasha
Last active December 24, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maasha/6769603 to your computer and use it in GitHub Desktop.
Save maasha/6769603 to your computer and use it in GitHub Desktop.
Script for alphabetical sorting FASTQ files by their identifier. Example: `bzcat unsorted.fq.bz2 | sortfq | bzip2 > sorted.fq.bz2`
#!/usr/bin/env perl
# Martin A. Hansen (mail@maasha.dk), September 2011
use strict;
use warnings;
use IPC::Open2;
use File::Which;
print STDERR "Usage: sortfq < unsorted.fq > sorted.fq\n\n" and exit if -t STDIN;
my $exe = which("psort") ? "psort" : "sort";
open2(\*IN, \*OUT, qq(paste - - - - | $exe -k1,1 -t " " | tr "\t" "\n"));
while (<>) {
print OUT $_;
}
close OUT;
while (<IN>) {
print;
}
close IN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment