From f8e1ea7b64b71c81c5ab2cf86e4311c4a8cceeab Mon Sep 17 00:00:00 2001 From: corin Date: Mon, 15 Nov 2010 19:44:32 +0000 Subject: [PATCH] Script based on the second part of Eric's createTranscriptToGenomicInfoTables.pl script which sorts flat files by reference order git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4682 348d0f76-0448-11de-a6fe-93d51630548a --- perl/tablesorter.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 perl/tablesorter.pl diff --git a/perl/tablesorter.pl b/perl/tablesorter.pl new file mode 100644 index 000000000..7b8be28d3 --- /dev/null +++ b/perl/tablesorter.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w + +# sorts by reference + +use strict; +use Getopt::Long; + +my $in = undef; +my $gatk = undef; +my $ref = undef; +my $out = undef; +my $tmp = "/tmp"; +my $contig = undef; +my $startpos =undef; +my $mark =undef; + +GetOptions( "in=s" => \$in, + "gatk=s" => \$gatk, + "ref=s" => \$ref, + "out=s" => \$out, + "tmp=s" => \$tmp, + "startpos=s" => \$startpos, + "contig=s" => \$contig, + "headermarker=s" => \$mark); + + if ( !$in || !$gatk || !$ref || !$out ) { + print "Usage: tablesorter.pl\n\t-in \t\t\t\n\t-gatk \t\t\t\n\t-ref \t\t\t\n\t-out \t\t\t\n\t-tmp \t\t\t\n\t-startpos \t\t\n\t-contig \t\t\n\t-headermarker \t\t\n"; + print "Example: ./tablesorter.pl\n\t-in test.foo\n\t-ref /seq/references/Homo_sapiens_assembly18/v0/Homo_sapiens_assembly18.fasta\n\t-gatk /humgen/gsa-s r1/ebanks/Sting_dev\n\t-out test.bar\n\t-tmp /broad/shptmp\n\t-startpos /2\n\t-contig 1\n\t-headermarker haplotype \n"; + exit(1); + } + + +# we need to sort the converted table now + print "\nSorting the table...\n"; + open(SORTED, ">$out") or die "can't open $out: $!"; + +# write the header + open(UNSORTED, "< $in") or die "can't open $in: $!"; + my $line = ; + print SORTED "$line"; + close(UNSORTED); + close(SORTED); + +print "$line is the header"; + my $cmd = "grep $mark -v $in | sort -n -k$startpos -T $tmp | $gatk/perl/sortByRef.pl --k $contig --tmp $tmp - $ref.fai >> $out"; + system($cmd); +# clean upunlink $unsorted_table; + + print "\nDone!\n";