From 4ca04a2ee593bc7e18dc4e5546ee38a008366cbd Mon Sep 17 00:00:00 2001 From: Matias Kaplan Date: Wed, 18 May 2022 17:45:06 -0700 Subject: [PATCH] Adding in a Reverse Function To complement the current set of functions I've added in a reverse sequence function --- src/getReverseSequenceString.js | 16 ++++++++++++++++ src/getReverseSequenceString.test.js | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/getReverseSequenceString.js create mode 100644 src/getReverseSequenceString.test.js diff --git a/src/getReverseSequenceString.js b/src/getReverseSequenceString.js new file mode 100644 index 0000000..6cca91b --- /dev/null +++ b/src/getReverseSequenceString.js @@ -0,0 +1,16 @@ +const DNAComplementMap = require("./DNAComplementMap"); +// const ac = require('ve-api-check'); +// ac.throw([ac.string,ac.bool],arguments); +module.exports = function getReverseSequenceString(sequence) { + // ac.throw([ac.string],arguments); + let reverseSequenceString = ""; + for (let i = sequence.length - 1; i >= 0; i--) { + let revChar = sequence[i]; + if (!revChar) { + revChar = sequence[i]; + // throw new Error('trying to get the reverse of an invalid base'); + } + reverseSequenceString += revChar; + } + return reverseSequenceString; +}; diff --git a/src/getReverseSequenceString.test.js b/src/getReverseSequenceString.test.js new file mode 100644 index 0000000..50b3359 --- /dev/null +++ b/src/getReverseSequenceString.test.js @@ -0,0 +1,11 @@ +const chai = require("chai"); +chai.should(); +const chaiSubset = require("chai-subset"); +chai.use(chaiSubset); +const getReverseSequenceString = require("./getReverseSequenceString"); +describe("getReverseSequenceAndAnnotations", function() { + it("handles a range option correctly and reverse complements a subset of the sequence across the origin ", function() { + const newSeq = getReverseSequenceString("uuuucccttt"); + newSeq.should.eq("tttcccuuuu"); + }); +});