Skip to content

Commit

Permalink
adding includeOverAndUnderHangs option to computeDigestFragments
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Oct 3, 2022
1 parent ce53ecd commit 65dfc90
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/computeDigestFragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function computeDigestFragments({
sequenceLength,
circular,
//optional:
includeOverAndUnderHangs,
computePartialDigest,
computeDigestDisabled,
computePartialDigestDisabled,
Expand Down Expand Up @@ -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);
Expand All @@ -105,6 +130,7 @@ function computeDigestFragments({
start,
end,
size,
overlapsSelf,
id,
name,
cut1,
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/computeDigestFragments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 65dfc90

Please sign in to comment.