From 02316faa4eca820ae9d3591ef06beafe9a8206c8 Mon Sep 17 00:00:00 2001 From: Thomas Rich Date: Wed, 13 Oct 2021 11:17:47 -0700 Subject: [PATCH] adding an annotateSingleSeq function --- src/annotateSingleSeq.js | 29 ++++++++++++++++ src/annotateSingleSeq.test.js | 64 +++++++++++++++++++++++++++++++++++ src/index.js | 1 + 3 files changed, 94 insertions(+) create mode 100644 src/annotateSingleSeq.js create mode 100644 src/annotateSingleSeq.test.js diff --git a/src/annotateSingleSeq.js b/src/annotateSingleSeq.js new file mode 100644 index 0000000..df6c5fc --- /dev/null +++ b/src/annotateSingleSeq.js @@ -0,0 +1,29 @@ +const { autoAnnotate } = require("./autoAnnotate"); + +function annotateSingleSeq({ fullSeq, searchSeq }) { + const fullSeqId = fullSeq.id || "fullSeqId"; + const searchSeqId = searchSeq.id || "searchSeqId"; + const results = autoAnnotate({ + seqsToAnnotateById: { + [fullSeqId]: { + ...fullSeq, + id: fullSeqId + } + }, + annotationsToCheckById: { + [searchSeqId]: { + ...searchSeq, + id: searchSeqId + } + }, + compareName: false + }); + if (results && results[fullSeqId]) { + return { + matches: results[fullSeqId] + }; + } else { + return { matches: [] }; + } +} +module.exports = { annotateSingleSeq }; diff --git a/src/annotateSingleSeq.test.js b/src/annotateSingleSeq.test.js new file mode 100644 index 0000000..e89b89d --- /dev/null +++ b/src/annotateSingleSeq.test.js @@ -0,0 +1,64 @@ +const { annotateSingleSeq } = require("./annotateSingleSeq"); +const { expect } = require("chai"); + +describe("annotateSingleSeq", function() { + it(`regexes work - correctly annotates a single seq with a regex annotation`, done => { + const results = annotateSingleSeq({ + fullSeq: { sequence: "AAAATTTTGGGGGCCCCCAAGT" }, + searchSeq: { sequence: "TTTT.*CCC" } + }); + // eslint-disable-next-line no-unused-expressions + expect(results).to.not.be.undefined; + //this should return an object keyed by the sequence id with the list of annotations to create + expect(results).to.deep.eq({ + matches: [ + { + start: 4, + end: 17, + strand: 1, + id: "searchSeqId" + } + ] + }); + done(); + }); + it(`correctly annotates a single seq with multiple matches`, done => { + const results = annotateSingleSeq({ + fullSeq: { sequence: "AAAATTTTGGGGGCCCCCAAGTAAAATTTTGGGGGCCCCCAAGT" }, + searchSeq: { sequence: "AAAATTTTGGGGGCCCCCAAGT", id: 2 } + }); + // eslint-disable-next-line no-unused-expressions + expect(results).to.not.be.undefined; + //this should return an object keyed by the sequence id with the list of annotations to create + expect(results).to.deep.eq({ + matches: [ + { + start: 0, + end: 21, + strand: 1, + id: 2 + }, + { + start: 22, + end: 43, + strand: 1, + id: 2 + } + ] + }); + done(); + }); + it(`correctly finds no matches when there are none`, done => { + const results = annotateSingleSeq({ + fullSeq: { sequence: "AAAATTTTGGGGGCCCCCAAGTAAAATTTTGGGGGCCCCCAAGT" }, + searchSeq: { sequence: "AAAATTTTGGGGGGGGGGCCCCCAAGT" } + }); + // eslint-disable-next-line no-unused-expressions + expect(results).to.not.be.undefined; + //this should return an object keyed by the sequence id with the list of annotations to create + expect(results).to.deep.eq({ + matches: [] + }); + done(); + }); +}); diff --git a/src/index.js b/src/index.js index 2f95d38..26b8842 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ module.exports.getDiffFromSeqs = diffUtils.getDiffFromSeqs; module.exports.patchSeqWithDiff = diffUtils.patchSeqWithDiff; module.exports.reverseSeqDiff = diffUtils.reverseSeqDiff; module.exports.getAllInsertionsInSeqReads = require("./getAllInsertionsInSeqReads"); +module.exports.annotateSingleSeq = require("./annotateSingleSeq").annotateSingleSeq; module.exports.getDegenerateDnaStringFromAAString = require("./getDegenerateDnaStringFromAAString"); module.exports.getDegenerateRnaStringFromAAString = require("./getDegenerateRnaStringFromAAString"); module.exports.getVirtualDigest = require("./getVirtualDigest");