Skip to content

Commit

Permalink
adding a loose mode to guessIfSequenceIsDnaAndNotProtein
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Jul 29, 2022
1 parent f0fbce5 commit 02aa24c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
10 changes: 8 additions & 2 deletions src/guessIfSequenceIsDnaAndNotProtein.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = function guessIfSequenceIsDnaAndNotProtein(seq, options = {}) {
const { threshold = 0.9, dnaLetters = ["G", "A", "T", "C", "U"] } = options;
const { ambiguous_dna_letters } = require("./bioData");

module.exports = function guessIfSequenceIsDnaAndNotProtein(seq, options = {}) {
const { threshold = 0.9, loose } = options;
const dnaLetters =
options.dnaLetters || loose
? ambiguous_dna_letters.split("")
: ["G", "A", "T", "C", "U"];
// Guess if the given sequence is DNA or Protein.

// It's considered DNA if more than 90% of the sequence is GATCs. The threshold
Expand All @@ -12,6 +17,7 @@ module.exports = function guessIfSequenceIsDnaAndNotProtein(seq, options = {}) {
return acc;
}, {});
let count = 0;
if (!seq || !seq.length) return true;
for (let index = 0; index < seq.length; index++) {
const letter = seq[index];
if (dnaLetterMap[letter.toUpperCase()]) {
Expand Down
52 changes: 32 additions & 20 deletions src/guessIfSequenceIsDnaAndNotProtein.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
const chai = require("chai");
chai.should();
const guessIfSequenceIsDnaAndNotProtein = require('./guessIfSequenceIsDnaAndNotProtein')
describe('guessIfSequenceIsDnaAndNotProtein', function() {
it('should correctly guess that a DNA seq is DNA', function() {
guessIfSequenceIsDnaAndNotProtein("gtatacc").should.equal(true)
})
it('should correctly guess that a DNA seq with some ambiguity is a DNA', function() {
guessIfSequenceIsDnaAndNotProtein("gtatacctaacn").should.equal(true)
})
it('should correctly guess that a seq with lots of ambiguity is a protein', function() {
guessIfSequenceIsDnaAndNotProtein("gtatacybctaacn").should.equal(false)
})
it('should correctly guess that a DNA with lots of ambiguities is dna when the threshold is lower ', function() {
guessIfSequenceIsDnaAndNotProtein("gtatacybctaacn", {
threshold: .5
}).should.equal(true)
})
it('should correctly guess that a DNA with lots of ambiguity is a dna when the ambiguous letter is included ', function() {
guessIfSequenceIsDnaAndNotProtein("gtatanccnnntaacn", {dnaLetters: ["g",'a', 't', 'c', 'n']}).should.equal(true)
})
})
const guessIfSequenceIsDnaAndNotProtein = require("./guessIfSequenceIsDnaAndNotProtein");
describe("guessIfSequenceIsDnaAndNotProtein", function() {
it("should default to DNA for a length 0 sequecne", function() {
guessIfSequenceIsDnaAndNotProtein("").should.equal(true);
});
it("should correctly guess that a DNA seq is DNA", function() {
guessIfSequenceIsDnaAndNotProtein("gtatacc").should.equal(true);
});
it("should correctly guess that a DNA seq with some ambiguity is a DNA", function() {
guessIfSequenceIsDnaAndNotProtein("gtatacctaacn").should.equal(true);
});
it("should correctly guess that a seq with lots of ambiguity is a protein when in the default strict mode", function() {
guessIfSequenceIsDnaAndNotProtein("gtatacybctaacn", {
loose: false
}).should.equal(false);
});
it("should correctly guess that a seq with lots of ambiguity is dna when in the loose mode", function() {
guessIfSequenceIsDnaAndNotProtein("gtatacybctaacn", {
loose: true
}).should.equal(true);
});
it("should correctly guess that a DNA with lots of ambiguities is dna when the threshold is lower ", function() {
guessIfSequenceIsDnaAndNotProtein("gtatacybctaacn", {
threshold: 0.5
}).should.equal(true);
});
it("should correctly guess that a DNA with lots of ambiguity is a dna when the ambiguous letter is included ", function() {
guessIfSequenceIsDnaAndNotProtein("gtatanccnnntaacn", {
dnaLetters: ["g", "a", "t", "c", "n"]
}).should.equal(true);
});
});

0 comments on commit 02aa24c

Please sign in to comment.