Skip to content

Commit

Permalink
Add --progress option
Browse files Browse the repository at this point in the history
  • Loading branch information
tseemann committed Apr 1, 2018
1 parent fd45ec4 commit 107d504
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ inc/
/MANIFEST.bak
/pm_to_blib
/*.zip

# samclip
*~
/empty.fai
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ script:
- "samclip --ref test.fna < test.sam 2>&1 > /dev/null | grep 'Header contained 5 lines'"
- "samclip --max 0 --ref test.fna test.sam 2>&1 > /dev/null | grep Done"
- "samclip --invert --ref test.fna test.sam 2>&1 > /dev/null | grep Done"
- "samclip --progress 50 --ref test.fna test.sam 2>&1 > /dev/null | grep 'Processed 150 records'"
23 changes: 14 additions & 9 deletions samclip
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ use constant {
#----------------------------------------------------------------------
# command line parameters

my $max = 5;
my $ref = '';
my $invert = 0;
my $debug = 0;
my $max = 5;
my $ref = '';
my $invert = 0;
my $debug = 0;
my $progress = 100_000;

#----------------------------------------------------------------------
sub usage {
Expand All @@ -43,11 +44,13 @@ sub usage {
" % samclip --ref ref.fa < in.sam > out.sam\n",
" % minimap2 ref.fa R1.fq R2.fq | samclip --ref ref.fa | samtools sort > out.bam\n",
"OPTIONS\n",
" --help This help.\n",
" --version Print version and exit.\n",
" --ref FASTA Reference genome - needs FASTA.fai index.\n",
" --invert Output rejected SAM lines and ignore good ones.\n",
" --debug Print verbose debug info to stderr.\n",
" --help This help\n",
" --version Print version and exit\n",
" --ref FASTA Reference genome - needs FASTA.fai index\n",
" --max NUM Maximum clip length to allow (default=$max)\n",
" --invert Output rejected SAM lines and ignore good ones\n",
" --debug Print verbose debug info to stderr\n",
" --progress N Print progress every NUM records (default=$progress,none=0)\n",
"HOMEPAGE\n $HOMEPAGE\n",
"";
exit($exitcode);
Expand All @@ -65,6 +68,7 @@ GetOptions(
"max=i" => \$max,
"invert" => \$invert,
"debug" => \$debug,
"progress=i" => \$progress,
) or usage(1);

$ref or err("Please supply reference genome with --ref");
Expand Down Expand Up @@ -97,6 +101,7 @@ while (my $line = <ARGV>) {
next;
}
$total++;
msg("Processed $total records...") if $progress and $total % $progress == 0;
my @sam = split m/\t/, $line;
# do a quick 'clipped?' check before heavyweight parsing
if ($sam[SAM_CIGAR] =~ /\d[SH]/) {
Expand Down

0 comments on commit 107d504

Please sign in to comment.