Skip to content

Commit

Permalink
updating getVirtualDigest to take a couple more options
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Feb 27, 2023
1 parent e587961 commit 045a8e6
Show file tree
Hide file tree
Showing 8 changed files with 1,862 additions and 1,132 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@
"string-splice": "^1.3.0"
},
"devDependencies": {
"@types/jest": "^23.3.11",
"auto-changelog": "^2.2.1",
"@types/jest": "^29.4.0",
"auto-changelog": "^2.4.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"chai": "^3.2.0",
"chai": "^4.3.7",
"chai-subset": "^1.1.0",
"eslint": "6",
"eslint-config-teselagen": "6.0.12",
"eslint": "8.35.0",
"eslint-config-teselagen": "6.0.16",
"husky": "^0.11.6",
"jest": "^23.6.0",
"jest": "^29.4.3",
"jsonfile": "^2.3.1",
"lint-staged": "^9.2.1",
"lodash": "^4.17.11",
Expand Down
28 changes: 14 additions & 14 deletions src/cutSequenceByRestrictionEnzyme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("a simple, palindromic enzyme", function() {
true,
enzymeList["sapi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(5);
Expand All @@ -42,7 +42,7 @@ describe("a simple, palindromic enzyme", function() {
true,
enzymeList["bamhi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(5);
Expand All @@ -60,7 +60,7 @@ describe("a simple, palindromic enzyme", function() {
true,
enzymeList["bamhi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(6);
cutsites[0].end.should.equal(1);
Expand All @@ -77,7 +77,7 @@ describe("a simple, palindromic enzyme", function() {
false,
enzymeList["bamhi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(0);
});
it("cuts multiple times", function() {
Expand All @@ -95,7 +95,7 @@ describe("a simple, palindromic enzyme", function() {
true,
enzymeList["bamhi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(2);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(5);
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("a simple, palindromic enzyme", function() {
bottomSnipOffset: 1
}
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(0);
cutsites.error.should.not.be.null;
cutsites.error.should.equal(
Expand All @@ -153,7 +153,7 @@ describe("non-palindromic enzyme", function() {
false,
enzymeList["bsmbi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(0);
});
it("does cut if the enzyme fits within circular sequence", function() {
Expand All @@ -162,7 +162,7 @@ describe("non-palindromic enzyme", function() {
true,
enzymeList["bsmbi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(4);
Expand All @@ -183,7 +183,7 @@ describe("non-palindromic enzyme", function() {
true,
enzymeList["bsmbi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(10);
Expand All @@ -205,7 +205,7 @@ describe("non-palindromic enzyme", function() {
true,
enzymeList["bsmbi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(18);
cutsites[0].end.should.equal(28);
Expand Down Expand Up @@ -233,7 +233,7 @@ describe("palindromic enzyme that cuts both upstream and downstream", function()
false,
enzymeList["nmedi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(0);
});
it("does cut twice if the enzyme fits within linear sequence", function() {
Expand All @@ -244,7 +244,7 @@ describe("palindromic enzyme that cuts both upstream and downstream", function()
false,
enzymeList["nmedi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(8);
cutsites[0].end.should.equal(37);
Expand All @@ -263,7 +263,7 @@ describe("palindromic enzyme that cuts both upstream and downstream", function()
false,
enzymeList["nmedi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(8);
cutsites[0].end.should.equal(25);
Expand All @@ -282,7 +282,7 @@ describe("palindromic enzyme that cuts both upstream and downstream", function()
false,
enzymeList["nmedi"]
);
cutsites.should.be.an.array;
cutsites.should.be.an("array");
cutsites.length.should.equal(1);
cutsites[0].start.should.equal(0);
cutsites[0].end.should.equal(17);
Expand Down
20 changes: 10 additions & 10 deletions src/getDigestFragmentsForRestrictionEnzymes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
false,
enzymeList["bsai"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(0);
});
it("returns 0 digestFragments for a circular seq with no cutsites", function() {
Expand All @@ -32,7 +32,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
false,
enzymeList["bsai"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(0);
});
it("gets digestFragments for a single type 2s cutsite cutting in a linear sequence", function() {
Expand All @@ -41,7 +41,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
false,
enzymeList["bsai"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(2);
digestFragments[0].start.should.equal(0);
digestFragments[0].end.should.equal(20);
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
// G G A T C C
// C C T A G G
// ^
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(1);
digestFragments[0].start.should.equal(1);
digestFragments[0].end.should.equal(0);
Expand All @@ -95,7 +95,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
false,
enzymeList["bamhi"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(2);
digestFragments[0].cut1.overhangSize.should.equal(0);
digestFragments[0].cut1.isOverhangIncludedInFragmentSize.should.equal(
Expand Down Expand Up @@ -123,7 +123,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
false,
enzymeList["bamhi"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(3);
digestFragments[0].cut1.type.should.equal("START_OR_END_OF_SEQ");
digestFragments[2].cut2.type.should.equal("START_OR_END_OF_SEQ");
Expand All @@ -140,7 +140,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
true,
enzymeList["bamhi"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(2);
digestFragments[0].start.should.equal(1);
digestFragments[0].end.should.equal(13);
Expand All @@ -160,7 +160,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
true,
enzymeList["bsai"]
);
digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(2);
digestFragments[0].cut1.overhangSize.should.equal(4);
digestFragments[0].cut1.isOverhangIncludedInFragmentSize.should.equal(true);
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
{ computePartialDigests: true }
);

digestFragments.should.be.an.array;
digestFragments.should.be.an("array");
digestFragments.length.should.equal(3);
digestFragments[0].start.should.equal(1);
digestFragments[0].end.should.equal(13);
Expand All @@ -212,7 +212,7 @@ describe("getDigestFragmentsForRestrictionEnzymes", function() {
// enzymeList["bamhi"],
// { computePartialDigests: true }
// );
// digestFragments.should.be.an.array;
// digestFragments.should.be.an("array");
// digestFragments.length.should.equal(9);
// digestFragments[0].start.should.equal(1);
// digestFragments[0].end.should.equal(13);
Expand Down
2 changes: 1 addition & 1 deletion src/getLeftAndRightOfSequenceInRangeGivenPosition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("getLeftAndRightOfSequenceInRangeGivenPosition", function() {
result.rightHandSide.should.equal("gatcc");
//
// //
// cutsites.should.be.an.array;
// cutsites.should.be.an("array");
// cutsites.length.should.equal(1);
// cutsites[0].start.should.equal(6);
// cutsites[0].end.should.equal(1);
Expand Down
2 changes: 1 addition & 1 deletion src/getPossiblePartsFromSequenceAndEnzymes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("getPossiblePartsFromSequenceAndEnzymes", function() {
enzymeList["bamhi"]
]);
// eslint-disable-next-line no-unused-expressions
parts.should.be.an.array;
parts.should.be.an("array");
parts.length.should.equal(2);
parts[0].start.should.equal(29);
parts[0].end.should.equal(76);
Expand Down
57 changes: 35 additions & 22 deletions src/getVirtualDigest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,28 @@ module.exports = function getVirtualDigest({
cutsites,
sequenceLength,
isCircular,
allowPartialDigests
computePartialDigest,
computePartialDigestDisabled,
computeDigestDisabled
}) {
let fragments = [];
const overlappingEnzymes = [];
let pairs = [];
const pairs = [];

const sortedCutsites = cutsites.sort((a, b) => {
return a.topSnipPosition - b.topSnipPosition;
});

sortedCutsites.forEach((cutsite1, index) => {
if (allowPartialDigests) {
sortedCutsites.forEach((cutsite2, index2) => {
pairs.push([cutsite1, cutsite2]);
if (computePartialDigest && !computePartialDigestDisabled) {
sortedCutsites.forEach((cs, index2) => {
// if (index2 === index + 1 || index2 === 0) { //tnw: not sure if this is necessary or not. commenting out for now
// return;
// }
pairs.push([cutsite1, sortedCutsites[index2]]);
});
} else {
}
if (!computeDigestDisabled) {
pairs.push([
cutsite1,
sortedCutsites[index + 1]
Expand All @@ -33,9 +40,6 @@ module.exports = function getVirtualDigest({
]);
}
});
// pairs = uniqBy(pairs, ([cut1,cut2]) => {
// return cut1.topSnipPosition > cut2.topSnipPosition ? (cut1.name || "cut1") + "_" + (cut2.name || "cut2") : (cut2.name || "cut2") + "_" + (cut1.name || "cut1")
// })

pairs.forEach(([cut1, cut2]) => {
const start = normalizePositionByRangeLength(
Expand All @@ -46,61 +50,70 @@ module.exports = function getVirtualDigest({
cut2.topSnipPosition - 1,
sequenceLength
);

if (!isCircular && start > end) {
//we have a fragment that spans the origin so we need to split it in 2 pieces
const frag1 = {
start: start,
end: sequenceLength - 1,
cut1,
cut2: "endOfSeq"
cut2: {
type: "endOfSeq",
restrictionEnzyme: {
name: "End Of Seq"
}
}
};
const frag2 = {
start: 0,
end: end,
cut1: "startOfSeq",
cut1: {
type: "startOfSeq",
restrictionEnzyme: {
name: "Start Of Seq"
}
},
cut2: cut2
};

fragments.push(addSizeAndId(frag1, sequenceLength));
fragments.push(addSizeAndId(frag2, sequenceLength));
fragments.push(addSizeIdName(frag1, sequenceLength));
fragments.push(addSizeIdName(frag2, sequenceLength));
} else {
const frag = {
cut1,
cut2,
start,
end
};
fragments.push(addSizeAndId(frag, sequenceLength));
fragments.push(addSizeIdName(frag, sequenceLength));
}
});
// const sizeMap = {};
fragments = fragments.filter(fragment => {
if (!fragment.size) {
overlappingEnzymes.push(fragment);
return false;
}
// if (sizeMap[fragment.size]) {
// sizeMap[fragment.size].push(fragment);
// return false;
// } else {
// sizeMap[fragment.size] = [fragment];
// }
return true;
});
return {
computePartialDigestDisabled,
computeDigestDisabled,
fragments,
overlappingEnzymes
};
};

function addSizeAndId(frag, sequenceLength) {
function addSizeIdName(frag, sequenceLength) {
const size = getRangeLength(
{ start: frag.start, end: frag.end },
sequenceLength
);
const name = `${frag.cut1.restrictionEnzyme?.name} -- ${frag.cut2.restrictionEnzyme?.name} ${size} bps`;

return {
...frag,
size,
name,
id: frag.start + "-" + frag.end + "-" + size + "-"
};
}
Loading

0 comments on commit 045a8e6

Please sign in to comment.