X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=misc%2Fsamtools.pl;h=1d9cf59b2ebd84a6ccc5c3bbc8eb48718c555d90;hb=2104bef5b18bf46562b9eca9c3d9a681ad6e8cf3;hp=320e8aaeda8ff2fab7fd91ab5e02073d5f3ba8fe;hpb=4234ca876913410a3db043171d2fecb6f871bae2;p=samtools.git diff --git a/misc/samtools.pl b/misc/samtools.pl index 320e8aa..1d9cf59 100755 --- a/misc/samtools.pl +++ b/misc/samtools.pl @@ -11,7 +11,7 @@ my $version = '0.3.3'; my $command = shift(@ARGV); my %func = (showALEN=>\&showALEN, pileup2fq=>\&pileup2fq, varFilter=>\&varFilter, - unique=>\&unique, uniqcmp=>\&uniqcmp, sra2hdr=>\&sra2hdr); + unique=>\&unique, uniqcmp=>\&uniqcmp, sra2hdr=>\&sra2hdr, sam2fq=>\&sam2fq); die("Unknown command \"$command\".\n") if (!defined($func{$command})); &{$func{$command}}; @@ -226,6 +226,49 @@ sub p2q_print_str { } } +# +# sam2fq +# + +sub sam2fq { + my %opts = (n=>20, p=>''); + getopts('n:p:', \%opts); + die("Usage: samtools.pl sam2fq [-n 20] [-p ] \n") if (@ARGV == 0 && -t STDIN); + if ($opts{p} && $opts{n} > 1) { + my $pre = $opts{p}; + my @fh; + for (0 .. $opts{n}-1) { + open($fh[$_], sprintf("| gzip > $pre.%.3d.fq.gz", $_)) || die; + } + my $i = 0; + while (<>) { + next if (/^@/); + chomp; + my @t = split("\t"); + next if ($t[9] eq '*'); + my ($name, $seq, $qual); + if ($t[1] & 16) { # reverse strand + $seq = reverse($t[9]); + $qual = reverse($t[10]); + $seq =~ tr/ACGTacgt/TGCAtgca/; + } else { + ($seq, $qual) = @t[9,10]; + } + $name = $t[0]; + $name .= "/1" if ($t[1] & 0x40); + $name .= "/2" if ($t[1] & 0x80); + print {$fh[$i]} "\@$name\n$seq\n"; + if ($qual ne '*') { + print {$fh[$i]} "+\n$qual\n"; + } + $i = 0 if (++$i == $opts{n}); + } + close($fh[$_]) for (0 .. $opts{n}-1); + } else { + die("To be implemented.\n"); + } +} + # # sra2hdr #