Skip to content

Commit

Permalink
Issue #10 | fix and simplify contig end logic again
Browse files Browse the repository at this point in the history
  • Loading branch information
tseemann committed Mar 7, 2020
1 parent 20a3ca7 commit c668054
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions samclip
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -123,14 +123,17 @@ while (my $line = <ARGV>) {
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++;
Expand Down

0 comments on commit c668054

Please sign in to comment.