From d0bb37809224de3ed7de6046e8c0ec01f8b8c1d5 Mon Sep 17 00:00:00 2001 From: Usman Raza Date: Sun, 13 Jul 2014 13:49:51 +0500 Subject: [PATCH 1/3] added condition on fail --- lib/DDG/Goodie/ReverseComplement.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/ReverseComplement.pm b/lib/DDG/Goodie/ReverseComplement.pm index 667a9e3d1c8..125adc78e07 100644 --- a/lib/DDG/Goodie/ReverseComplement.pm +++ b/lib/DDG/Goodie/ReverseComplement.pm @@ -45,7 +45,10 @@ handle remainder => sub { #Reverse $sequence = reverse($sequence); - + + #Return if we get no sequence + return if(!$sequence); + return $sequence, html => wrap_html('DNA reverse complement:', $sequence); }; From d87be41e31a9bdac9f6dc3d86e8f77f61896b514 Mon Sep 17 00:00:00 2001 From: Usman Raza Date: Sun, 13 Jul 2014 16:25:17 +0500 Subject: [PATCH 2/3] added test --- lib/DDG/Goodie/ReverseComplement.pm | 10 ++-------- t/ReverseComplement.t | 3 ++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/DDG/Goodie/ReverseComplement.pm b/lib/DDG/Goodie/ReverseComplement.pm index 125adc78e07..f0444a26fe3 100644 --- a/lib/DDG/Goodie/ReverseComplement.pm +++ b/lib/DDG/Goodie/ReverseComplement.pm @@ -24,15 +24,12 @@ handle remainder => sub { $sequence =~ s/\bsequence\b//gi; $sequence =~ s/\b[DR]NA\b//gi; $sequence =~ s/\bnucleotide\b//gi; - #Remove whitespace and dashes and make uppercase $sequence =~ s/\s|-//g; $sequence = uc($sequence); - - #Return nothing if sequence contains characters + #Return nothing if sequence does not contains characters or contains characters # other than DNA/RNA bases or standard IUPAC ambiguity codes - return if $sequence =~ /[^ATCGURYKMSWBVDHN]/; - + return if (!$sequence || $sequence =~ /[^ATCGURYKMSWBVDHN]/); #DNA contains thymine (T) but not uracil (U); # RNA contains U but not T (with some extremely # rare exceptions). Hence, if the sequence @@ -46,9 +43,6 @@ handle remainder => sub { #Reverse $sequence = reverse($sequence); - #Return if we get no sequence - return if(!$sequence); - return $sequence, html => wrap_html('DNA reverse complement:', $sequence); }; diff --git a/t/ReverseComplement.t b/t/ReverseComplement.t index bc459c557b8..aa6893f2b0c 100644 --- a/t/ReverseComplement.t +++ b/t/ReverseComplement.t @@ -34,8 +34,9 @@ ddg_goodie_test( # is an error than one of the edge cases of uracil-containing DNA) 'reverse complement AAATTTCCCGGGUUU' => undef, - #Non-nucleic acid query string (should return empty, no idea what they wanted) + #Non-nucleic acid query strings (should return empty, no idea what they wanted) 'reverse complement hello-this-is-DNA' => undef, + 'DNA reverse complement' => undef, ); From 0b1923d1b72a4185ea66025c7556a65c03ae27fb Mon Sep 17 00:00:00 2001 From: Usman Raza Date: Sun, 13 Jul 2014 19:46:16 +0500 Subject: [PATCH 3/3] updated check --- lib/DDG/Goodie/ReverseComplement.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/ReverseComplement.pm b/lib/DDG/Goodie/ReverseComplement.pm index f0444a26fe3..fe57735c30e 100644 --- a/lib/DDG/Goodie/ReverseComplement.pm +++ b/lib/DDG/Goodie/ReverseComplement.pm @@ -29,7 +29,7 @@ handle remainder => sub { $sequence = uc($sequence); #Return nothing if sequence does not contains characters or contains characters # other than DNA/RNA bases or standard IUPAC ambiguity codes - return if (!$sequence || $sequence =~ /[^ATCGURYKMSWBVDHN]/); + return unless ($sequence =~ /^[ATCGURYKMSWBVDHN]+$/); #DNA contains thymine (T) but not uracil (U); # RNA contains U but not T (with some extremely # rare exceptions). Hence, if the sequence