diff --git a/samclip b/samclip index 3ffce7a..f90b66c 100755 --- a/samclip +++ b/samclip @@ -20,7 +20,7 @@ use Data::Dumper; # globals my $EXE = basename($0); -my $VERSION = "0.3.0"; +my $VERSION = "0.4.0"; my $AUTHOR = 'Torsten Seemann (@torstenseemann)'; my $HOMEPAGE = "https://github.com/tseemann/samclip"; @@ -123,14 +123,17 @@ while (my $line = ) { my $start = $sam[SAM_POS]; my $end = $start + length($sam[SAM_SEQ]) - 1; my $contiglen = $len->{$sam[SAM_RNAME]} or err("Reference", $sam[SAM_RNAME], "not in '$ref'"); - msg("CHROM=$sam[SAM_RNAME]:1-$contiglen POS=$start..$end CIGAR=$sam[SAM_CIGAR] HL=$HL SL=$SL SR=$SR HR=$HR max=$max)") if $debug; - unless ($start <= 1 or $end >= $contiglen) { - if ($HL+$SL > $max or $HR+$SR > $max) { - $removed++; - next; - } + my $L = $HL + $SL; + my $R = $HR + $SR; + $L = 0 if $start <= 1+$L; + $R = 0 if $end >= $contiglen-$R; + my $info = $debug ? "CHROM=$sam[SAM_RNAME]:1..$contiglen POS=$start..$end CIGAR=$sam[SAM_CIGAR] L=$L R=$R | HL=$HL SL=$SL SR=$SR HR=$HR max=$max)" : "need --debug"; + if ($L > $max or $R > $max) { + msg("BAD! $info") if $debug; + $removed++; + next; } - msg("^^^ KEPT") if $debug; + msg("GOOD $info") if $debug; # otherwise pass through untouched print $line if $invert; $kept++;