Skip to content

Commit f9f9ab7

Browse files
committed
change from Text::Fuzzy to Text::Levenshtein
1 parent ea516be commit f9f9ab7

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Makefile.PL

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ WriteMakefile(
5454
'File::Slurp' => 0,
5555
#'Bio::Kmer' => 0, # Bio::Kmer currently requires Jellyfish v2 but Kraken1 requires Jellyfish v1
5656
'Bio::SeqIO' => 0,
57-
'Text::Fuzzy' => 0,
57+
'Text::Levenshtein' => 0.15,
5858
'Bio::FeatureIO' => 0,
5959
# MLST module
6060
'Moo' => 0,

SneakerNet.plugins/sn_immediateStatus.pl

+24-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use lib "$FindBin::RealBin/../lib/perl5";
1414
use SneakerNet qw/exitOnSomeSneakernetOptions recordProperties readConfig samplesheetInfo_tsv command logmsg fullPathToExec/;
1515

16-
use Text::Fuzzy;
16+
use Text::Levenshtein qw/distance/;
1717

18-
our $VERSION = "1.9";
18+
our $VERSION = "2.0";
1919
our $CITATION= "Immediate status report by Lee Katz";
2020

2121
local $0=fileparse $0;
@@ -166,8 +166,9 @@ sub doubleCheckRun{
166166
}
167167

168168
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);
171172
$errHash{sample}{$sample}{fastqNotFound} = "For sample $sample, the closest named fastq files are $nearest";
172173
}
173174

@@ -179,15 +180,32 @@ sub doubleCheckRun{
179180
my $basename = basename($filename);
180181
$basename =~ s/_.*//;
181182
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);
184186
$errHash{fastq}{$filename}{sampleNotFound} = "Found fastq $filename but no entry in the sample sheet matching $basename. Did you mean $nearest?";
185187
}
186188
}
187189

188190
return \%errHash;
189191
}
190192

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+
191209
# Add an attachment to an email file handle
192210
sub append_attachment {
193211
my ($fh, $file_path) = @_;

0 commit comments

Comments
 (0)