Skip to content

Commit 0849513

Browse files
committed
use english and fix perl critic errors
no substantial code changes
1 parent 68f06d9 commit 0849513

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

bin/embedded_UMI_extractor.pl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# https://github.com/tjparnell/HCI-Scripts/
1313

1414
use strict;
15+
use English qw(-no_match_vars);
1516
use Getopt::Long qw(:config no_ignore_case);
1617
use File::Basename qw(fileparse);
1718
use Bio::UMIScripts::FastqHelper qw(
@@ -28,7 +29,7 @@
2829
name_append_umi_from_fastq_read
2930
);
3031

31-
my $VERSION = 3.01;
32+
our $VERSION = 3.02;
3233

3334
####### Documentation
3435
my $description = <<END;
@@ -217,29 +218,29 @@ END
217218
if ($read_file2 and not $sam_format) {
218219
# open two separate output handles
219220
$outfile = $read_file1;
220-
$outfile =~ s/\.(txt|fq|fastq)/.umi.$1/;
221+
$outfile =~ s/\. (txt | fq | fastq) /.umi.$1/x;
221222
$out_fh1 = write_fastq_filehandle($outfile, $cpu);
222223
my $outfile2 = $read_file2;
223-
$outfile2 =~ s/\.(txt|fq|fastq)/.umi.$1/;
224+
$outfile2 =~ s/\. (txt | fq | fastq) /.umi.$1/x;
224225
$out_fh2 = write_fastq_filehandle($outfile2, $cpu);
225226
}
226227
elsif (not $read_file2 and not $sam_format) {
227228
# just one file output
228229
$outfile = $read_file1;
229-
$outfile =~ s/\.(txt|fq|fastq)/.umi.$1/;
230+
$outfile =~ s/\. (txt | fq | fastq) /.umi.$1/x;
230231
$out_fh1 = write_fastq_filehandle($outfile, $cpu);
231232
}
232233
elsif ($read_file2 and $sam_format) {
233234
# open one bam output handle for both
234235
$outfile = $read_file1;
235-
$outfile =~ s/\.(?:txt|fq|fastq)(?:\.gz)?$/.bam/;
236+
$outfile =~ s/\. (?: txt | fq | fastq) (?: \.gz)? $/.bam/x;
236237
$out_fh1 = write_bam_filehandle($outfile, $cpu);
237238
$out_fh2 = $out_fh2;
238239
}
239240
elsif (not $read_file2 and $sam_format) {
240241
# just one file output
241242
$outfile = $read_file1;
242-
$outfile =~ s/\.(?:fq|fastq)(?:\.gz)?$/.bam/;
243+
$outfile =~ s/\. (?: fq | fastq) (?: \.gz)? $/.bam/x;
243244
$out_fh1 = write_bam_filehandle($outfile, $cpu);
244245
}
245246
else {
@@ -280,7 +281,7 @@ END
280281

281282
### Write sam header as necessary
282283
if ($sam_format) {
283-
my $cl = "$0 --read1 $read_file1 ";
284+
my $cl = "$PROGRAM_NAME --read1 $read_file1 ";
284285
$cl .= "--read2 $read_file2 " if $read_file2;
285286
$cl .= "--out $outfile " if $outfile;
286287
$cl .= "--umi $umi_location ";
@@ -401,7 +402,7 @@ sub process_single_end_sam {
401402
while (my $read = get_fastq_read($in_fh1)) {
402403

403404
# extract UMI sequence
404-
my $umi = &$extract_umi($read, $umi1_length, $fixed1);
405+
my $umi = &{$extract_umi}($read, $umi1_length, $fixed1);
405406
if ($umi) {
406407
my $tag = umi_sam_tags_from_fastq_read($umi);
407408
$out_fh1->print( $read->sam_string($flag1, $tag) );
@@ -418,7 +419,7 @@ sub process_single_end_name_append {
418419
while (my $read = get_fastq_read($in_fh1)) {
419420

420421
# extract UMI sequence
421-
my $umi = &$extract_umi($read, $umi1_length, $fixed1);
422+
my $umi = &{$extract_umi}($read, $umi1_length, $fixed1);
422423
if ($umi) {
423424
name_append_umi_from_fastq_read($read, $umi);
424425
$out_fh1->print( $read->fastq_string );
@@ -435,7 +436,7 @@ sub process_single_end_fastq_tag {
435436
while (my $read = get_fastq_read($in_fh1)) {
436437

437438
# extract UMI sequence
438-
my $umi = &$extract_umi($read, $umi1_length, $fixed1);
439+
my $umi = &{$extract_umi}($read, $umi1_length, $fixed1);
439440
if ($umi) {
440441
my $tag = umi_sam_tags_from_fastq_read($umi);
441442
$out_fh1->print( $read->fastq_string($tag) );
@@ -461,7 +462,7 @@ sub process_paired_end_with_one_umi_sam {
461462
}
462463

463464
# extract UMI sequence
464-
my $umi = &$extract_umi($umi_location == 1 ? $read1 : $read2,
465+
my $umi = &{$extract_umi}($umi_location == 1 ? $read1 : $read2,
465466
$umi1_length, $fixed1);
466467
if ($umi) {
467468
my $tag = umi_sam_tags_from_fastq_read($umi);
@@ -489,7 +490,7 @@ sub process_paired_end_with_one_umi_name_append {
489490
}
490491

491492
# extract UMI sequence
492-
my $umi = &$extract_umi($umi_location == 1 ? $read1 : $read2,
493+
my $umi = &{$extract_umi}($umi_location == 1 ? $read1 : $read2,
493494
$umi1_length, $fixed1);
494495
if ($umi) {
495496
name_append_umi_from_fastq_read($read1, $umi);
@@ -518,7 +519,7 @@ sub process_paired_end_with_one_umi_fastq_tag {
518519
}
519520

520521
# extract UMI sequence
521-
my $umi = &$extract_umi($umi_location == 1 ? $read1 : $read2,
522+
my $umi = &{$extract_umi}($umi_location == 1 ? $read1 : $read2,
522523
$umi1_length, $fixed1);
523524
if ($umi) {
524525
my $tag = umi_sam_tags_from_fastq_read($umi);
@@ -548,8 +549,8 @@ sub process_paired_end_with_two_umi_sam {
548549
}
549550

550551
# extract UMI sequence
551-
my $umi1 = &$extract_umi($read1, $umi1_length, $fixed1);
552-
my $umi2 = &$extract_umi($read2, $umi2_length, $fixed2);
552+
my $umi1 = &{$extract_umi}($read1, $umi1_length, $fixed1);
553+
my $umi2 = &{$extract_umi}($read2, $umi2_length, $fixed2);
553554
if ($umi1 and $umi2) {
554555
# both found, both good
555556
my $umi = $umi1->concatenate_reads($umi2);
@@ -583,8 +584,8 @@ sub process_paired_end_with_two_umi_name_append {
583584
}
584585

585586
# extract UMI sequence
586-
my $umi1 = &$extract_umi($read1, $umi1_length, $fixed1);
587-
my $umi2 = &$extract_umi($read2, $umi2_length, $fixed2);
587+
my $umi1 = &{$extract_umi}($read1, $umi1_length, $fixed1);
588+
my $umi2 = &{$extract_umi}($read2, $umi2_length, $fixed2);
588589
if ($umi1 and $umi2) {
589590
# both found, both good
590591
my $umi = $umi1->concatenate_reads($umi2);
@@ -619,8 +620,8 @@ sub process_paired_end_with_two_umi_fastq_tag {
619620
}
620621

621622
# extract UMI sequence
622-
my $umi1 = &$extract_umi($read1, $umi1_length, $fixed1);
623-
my $umi2 = &$extract_umi($read2, $umi2_length, $fixed2);
623+
my $umi1 = &{$extract_umi}($read1, $umi1_length, $fixed1);
624+
my $umi2 = &{$extract_umi}($read2, $umi2_length, $fixed2);
624625
if ($umi1 and $umi2) {
625626
# both found, both good
626627
my $umi = $umi1->concatenate_reads($umi2);

bin/qiagen_smallRNA_umi_extractor.pl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# https://github.com/tjparnell/HCI-Scripts/
1313

1414
use strict;
15+
use English qw(-no_match_vars);
1516
use IO::File;
1617
use IO::Handle;
1718
use Getopt::Long;
@@ -23,7 +24,7 @@
2324
$mismatch_ok = 1;
2425
};
2526

26-
my $VERSION = 2;
27+
our $VERSION = 2.01;
2728

2829
########################################
2930

@@ -59,7 +60,8 @@
5960
duplicates in combination with alignment information. See the script
6061
bam_umi_dedup.pl as the companion application to do this.
6162
62-
Usage: $0 -i input.fastq.gz --fail noUMI.fastq.gz | <aligner>
63+
Usage:
64+
qiagen_smallRNA_umi_extractor.pl -i input.fastq.gz --fail noUMI.fastq.gz | <aligner>
6365
6466
Options:
6567
-i | --input <file> Fastq file, may be gzipped
@@ -139,22 +141,22 @@ END
139141
# input
140142
if ($file1 =~ /gz$/i) {
141143
$infh = IO::File->new("gzip -dc $file1 |") or
142-
die "unable to open $file1! $!\n";
144+
die "unable to open $file1! $OS_ERROR\n";
143145
}
144146
else {
145147
$infh = IO::File->new("$file1") or
146-
die "unable to open $file1! $!\n";
148+
die "unable to open $file1! $OS_ERROR\n";
147149
}
148150

149151
# output
150152
if ($outfile) {
151153
if ($outfile =~ /\.gz$/) {
152154
$outfh = IO::File->new("| gzip >$outfile") or
153-
die "unable to open output $outfile! $!\n";
155+
die "unable to open output $outfile! $OS_ERROR\n";
154156
}
155157
else {
156158
$outfh = IO::File->new("$outfile", 'w') or
157-
die "unable to open output $outfile! $!\n";
159+
die "unable to open output $outfile! $OS_ERROR\n";
158160
}
159161
}
160162
else {
@@ -168,11 +170,11 @@ END
168170
if ($failfile) {
169171
if ($failfile =~ /\.gz$/) {
170172
$failfh = IO::File->new("| gzip >$failfile") or
171-
die "unable to open output $failfile! $!\n";
173+
die "unable to open output $failfile! $OS_ERROR\n";
172174
}
173175
else {
174176
$failfh = IO::File->new("$failfile", 'w') or
175-
die "unable to open output $failfile! $!\n";
177+
die "unable to open output $failfile! $OS_ERROR\n";
176178
}
177179
}
178180

@@ -192,7 +194,7 @@ END
192194
my $quality1 = $infh->getline or die "malformed file! no quality line";
193195

194196
# find the position of the fixed adapter using the callback determined above
195-
my $i = &$myindex($sequence1);
197+
my $i = &{ $myindex }($sequence1);
196198

197199
if ($i == -1) {
198200
# the adapter sequence was not found

0 commit comments

Comments
 (0)