From 65dfc9079072515e7d713370f89b807124082585 Mon Sep 17 00:00:00 2001 From: Thomas Rich Date: Mon, 3 Oct 2022 15:29:30 -0700 Subject: [PATCH] adding includeOverAndUnderHangs option to computeDigestFragments --- src/computeDigestFragments.js | 42 ++++++++++++++++++++++++++---- src/computeDigestFragments.test.js | 15 +++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/computeDigestFragments.js b/src/computeDigestFragments.js index 69801f5..91b5f60 100644 --- a/src/computeDigestFragments.js +++ b/src/computeDigestFragments.js @@ -12,6 +12,7 @@ function computeDigestFragments({ sequenceLength, circular, //optional: + includeOverAndUnderHangs, computePartialDigest, computeDigestDisabled, computePartialDigestDisabled, @@ -71,17 +72,41 @@ function computeDigestFragments({ pairs.forEach(r => { let [cut1, cut2] = r; - const start = normalizePositionByRangeLength( + let start; + let end; + let size; + start = normalizePositionByRangeLength( cut1.topSnipPosition, sequenceLength ); - const end = normalizePositionByRangeLength( + end = normalizePositionByRangeLength( cut2.topSnipPosition - 1, sequenceLength ); - const size = getRangeLength({ start, end }, sequenceLength); + size = getRangeLength({ start, end }, sequenceLength); + let overlapsSelf; + if (includeOverAndUnderHangs) { + const oldSize = size; + start = normalizePositionByRangeLength( + cut1.topSnipBeforeBottom + ? cut1.topSnipPosition + : cut1.bottomSnipPosition, + sequenceLength + ); + end = normalizePositionByRangeLength( + cut2.topSnipBeforeBottom + ? cut2.bottomSnipPosition - 1 + : cut2.topSnipPosition - 1, + sequenceLength + ); + size = getRangeLength({ start, end }, sequenceLength); + if (oldSize > size) { + //we've got a part that wraps on itself + overlapsSelf = true; + size += sequenceLength; + } + } - // const id = uniqid() let isFormedFromLinearEnd; if (cut1.name === "Sequence_Terminus") { cut1 = cloneDeep(cut1); @@ -105,6 +130,7 @@ function computeDigestFragments({ start, end, size, + overlapsSelf, id, name, cut1, @@ -138,9 +164,15 @@ function computeDigestFragments({ }; } -function getDigestFragsForSeqAndEnzymes({ sequence, circular, enzymes }) { +function getDigestFragsForSeqAndEnzymes({ + sequence, + circular, + enzymes, + includeOverAndUnderHangs +}) { const cutsitesByName = getCutsitesFromSequence(sequence, circular, enzymes); return computeDigestFragments({ + includeOverAndUnderHangs, cutsites: flatMap(cutsitesByName), sequenceLength: sequence.length, circular diff --git a/src/computeDigestFragments.test.js b/src/computeDigestFragments.test.js index c03cab3..409968d 100644 --- a/src/computeDigestFragments.test.js +++ b/src/computeDigestFragments.test.js @@ -4,6 +4,21 @@ const { const aliasedEnzymesByName = require("./aliasedEnzymesByName"); describe("computeDigestFragments", function() { + it("it should correctly generate fragments for bamhi cutting once in a circular sequence with includeOverAndUnderHangs=true", function() { + const result = getDigestFragsForSeqAndEnzymes({ + sequence: "ggggatccggggggggggggggggggggggggggggggggggggggggg", + circular: true, + enzymes: [aliasedEnzymesByName.bamhi], + includeOverAndUnderHangs: true + }); + expect(result.fragments).toHaveLength(1); + expect(result.fragments[0].overlapsSelf).toEqual(true); + expect(result.fragments[0].start).toEqual(3); + expect(result.fragments[0].end).toEqual(6); + // expect(result.fragments[0].size).toEqual(4); + expect(result.fragments[0].size).toEqual(53); + expect(result.fragments[0].madeFromOneCutsite).toEqual(true); + }); it("it should correctly generate fragments for bamhi cutting once in a circular sequence", function() { const result = getDigestFragsForSeqAndEnzymes({ sequence: "ggggatccggggggggggggggggggggggggggggggggggggggggg",