4 #use IO::Unread qw(unread);
5 use Data
::Dump
qw(ddx);
7 die "Usage: $0 <input sam.gz/bam> <output>\n" if @ARGV < 2;
11 open CHR,'<','chr.lst' or die "[x]Cannot read chr.lst, use `samtools faidx` and append ChrID manually to get one!\n";
14 my ($gi,$id) = split /\s+/,$_;
25 if ($inf =~ /\.sam\.gz$/i) {
26 open $FH,'-|',"gzip -dc $inf" or die "Error opening $inf: $!\n";
27 } elsif ($inf =~ /\.bam$/i) {
28 open $FH,'-|',"samtools view -h $inf" or die "Error opening $inf: $!\n";
29 } elsif ($inf =~ /\.sam$/i) {
30 open $FH,'<',$inf or die "Error opening $inf: $!\n";
34 my $FH = openifile
($inf);
38 while ($line = <$FH>) {
39 unless ($line =~ /^\@/) {
43 if ($line =~ /^\@SQ/) {
44 my (undef,$gi,$len) = split /\s+/,$line;
54 #$DatbyChrM{$_}=[] for values %ChrGI2ID;
56 open OUT
,'>',$outf or die "Error opening $outf: $!\n";
59 for my $chr ( keys %ChrLen ) {
60 $FH = openifile
($inf);
61 while ($line = <$FH>) {
62 my ($id, $flag, $ref, $pos, $mapq, $CIAGR, $mref, $mpos, $isize, $seq, $qual, @OPT) = split /\t/,$line;
63 #print "$id, $flag, Chr$ChrGI2ID{$ref}, $pos, $mapq, $CIAGR, Chr$ChrGI2ID{$mref}, $mpos, $isize\n";
65 #my $commonChrID = $ChrGI2ID{$ref};
66 my $commonChrID = $ref;
67 my $posto1m = int($pos/1000000);
68 ++$DatbyChrM{$commonChrID}->[$posto1m];
73 for my $ccid (sort { "$a$b"=~/^\d+$/ ?
$a<=>$b : $a cmp $b } keys %DatbyChrM) {
74 print OUT
"[$ccid]\n";
75 my $ArrayRef = $DatbyChrM{$ccid};
76 for my $i ( 0 .. $#$ArrayRef ) {
77 my $t = $$ArrayRef[$i];
78 print OUT
(defined $t)?
$t:0,"\t",1+$i,"\n";
87 perl startplot
.pl t
.sam t
.out