Skip to content

Commit c668054

Browse files
committed
Issue #10 | fix and simplify contig end logic again
1 parent 20a3ca7 commit c668054

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

samclip

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use Data::Dumper;
2020
# globals
2121

2222
my $EXE = basename($0);
23-
my $VERSION = "0.3.0";
23+
my $VERSION = "0.4.0";
2424
my $AUTHOR = 'Torsten Seemann (@torstenseemann)';
2525
my $HOMEPAGE = "https://github.com/tseemann/samclip";
2626

@@ -123,14 +123,17 @@ while (my $line = <ARGV>) {
123123
my $start = $sam[SAM_POS];
124124
my $end = $start + length($sam[SAM_SEQ]) - 1;
125125
my $contiglen = $len->{$sam[SAM_RNAME]} or err("Reference", $sam[SAM_RNAME], "not in '$ref'");
126-
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;
127-
unless ($start <= 1 or $end >= $contiglen) {
128-
if ($HL+$SL > $max or $HR+$SR > $max) {
129-
$removed++;
130-
next;
131-
}
126+
my $L = $HL + $SL;
127+
my $R = $HR + $SR;
128+
$L = 0 if $start <= 1+$L;
129+
$R = 0 if $end >= $contiglen-$R;
130+
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";
131+
if ($L > $max or $R > $max) {
132+
msg("BAD! $info") if $debug;
133+
$removed++;
134+
next;
132135
}
133-
msg("^^^ KEPT") if $debug;
136+
msg("GOOD $info") if $debug;
134137
# otherwise pass through untouched
135138
print $line if $invert;
136139
$kept++;

0 commit comments

Comments
 (0)