diff --git a/src/computeDigestFragments.js b/src/computeDigestFragments.js index dac121e..69801f5 100644 --- a/src/computeDigestFragments.js +++ b/src/computeDigestFragments.js @@ -25,7 +25,7 @@ function computeDigestFragments({ const sortedCutsites = cutsites.sort((a, b) => { return a.topSnipPosition - b.topSnipPosition; }); - if (!circular) { + if (!circular && cutsites.length) { sortedCutsites.push({ id: "seqTerm_" + bsonObjectId().str, start: 0, diff --git a/src/computeDigestFragments.test.js b/src/computeDigestFragments.test.js index 869fedf..c03cab3 100644 --- a/src/computeDigestFragments.test.js +++ b/src/computeDigestFragments.test.js @@ -4,7 +4,7 @@ const { const aliasedEnzymesByName = require("./aliasedEnzymesByName"); describe("computeDigestFragments", function() { - it.only("it should correctly generate fragments for bamhi cutting once in a circular sequence", function() { + it("it should correctly generate fragments for bamhi cutting once in a circular sequence", function() { const result = getDigestFragsForSeqAndEnzymes({ sequence: "ggggatccggggggggggggggggggggggggggggggggggggggggg", circular: true, @@ -41,4 +41,20 @@ describe("computeDigestFragments", function() { expect(result.fragments[1].size).toEqual(3); expect(result.fragments[1].madeFromOneCutsite).toEqual(false); }); + it("it should not generate any fragments for bamhi if it doesn't cut in a linear sequence", function() { + const result = getDigestFragsForSeqAndEnzymes({ + sequence: "ggggggggggggggggggggggggggggggggggggggggggggg", + circular: false, + enzymes: [aliasedEnzymesByName.bamhi] + }); + expect(result.fragments).toHaveLength(0); + }); + it("it should not generate any fragments for bamhi if it doesn't cut in a circular sequence", function() { + const result = getDigestFragsForSeqAndEnzymes({ + sequence: "ggggggggggggggggggggggggggggggggggggggggggggg", + circular: true, + enzymes: [aliasedEnzymesByName.bamhi] + }); + expect(result.fragments).toHaveLength(0); + }); });