13
13
use lib " $FindBin::RealBin /../lib/perl5" ;
14
14
use SneakerNet qw/ exitOnSomeSneakernetOptions recordProperties readConfig samplesheetInfo_tsv command logmsg fullPathToExec/ ;
15
15
16
- use Text::Fuzzy ;
16
+ use Text::Levenshtein qw/ distance / ;
17
17
18
- our $VERSION = " 1.9 " ;
18
+ our $VERSION = " 2.0 " ;
19
19
our $CITATION = " Immediate status report by Lee Katz" ;
20
20
21
21
local $0 =fileparse $0 ;
@@ -166,8 +166,9 @@ sub doubleCheckRun{
166
166
}
167
167
168
168
if ($errHash {sample }{$sample }{fastqNotFound }){
169
- my $tf = Text::Fuzzy-> new($sample );
170
- my $nearest = $tf -> nearestv(\@fastq );
169
+ my $nearest = nearestString($sample , \@fastq , $settings );
170
+ # my $tf = Text::Fuzzy->new($sample);
171
+ # my $nearest = $tf->nearestv(\@fastq);
171
172
$errHash {sample }{$sample }{fastqNotFound } = " For sample $sample , the closest named fastq files are $nearest " ;
172
173
}
173
174
@@ -179,15 +180,32 @@ sub doubleCheckRun{
179
180
my $basename = basename($filename );
180
181
$basename =~ s / _.*// ;
181
182
if (!$$sampleInfo {$basename }){
182
- my $tf = Text::Fuzzy-> new($filename );
183
- my $nearest = $tf -> nearestv(\@sample );
183
+ # my $tf = Text::Fuzzy->new($filename);
184
+ # my $nearest = $tf->nearestv(\@sample);
185
+ my $nearest = nearestString($filename , \@sample , $settings );
184
186
$errHash {fastq }{$filename }{sampleNotFound } = " Found fastq $filename but no entry in the sample sheet matching $basename . Did you mean $nearest ?" ;
185
187
}
186
188
}
187
189
188
190
return \%errHash ;
189
191
}
190
192
193
+ sub nearestString{
194
+ my ($query , $strings , $settings ) = @_ ;
195
+
196
+ my $minDist = ~0; # max int
197
+ my $nearest = " " ;
198
+ for my $string (@$strings ){
199
+ my $dist = distance($query , $string );
200
+ if ($dist < $minDist ){
201
+ $minDist = $dist ;
202
+ $nearest = $string ;
203
+ }
204
+ }
205
+
206
+ return $nearest ;
207
+ }
208
+
191
209
# Add an attachment to an email file handle
192
210
sub append_attachment {
193
211
my ($fh , $file_path ) = @_ ;
0 commit comments