Skip to content

Commit

Permalink
adding an annotateSingleSeq function
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Oct 13, 2021
1 parent f9b655f commit 02316fa
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/annotateSingleSeq.js
Original file line number Diff line number Diff line change
@@ -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 };
64 changes: 64 additions & 0 deletions src/annotateSingleSeq.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 02316fa

Please sign in to comment.