Skip to content

Commit

Permalink
Rename primer features to primer_bind on export
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreen7 committed Apr 8, 2021
1 parent 683aa3a commit ebc286e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"nwb": "^0.23.0",
"prettier": "^1.16.4",
"ve-range-utils": "^2.5.9",
"ve-sequence-utils": "5.0.0"
"ve-sequence-utils": "5.1.0"
},
"peerDependencies": {
"ve-range-utils": "*",
Expand Down
29 changes: 19 additions & 10 deletions src/parsers/genbankToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,27 @@ function genbankToJson(string, options = {}) {
);
// default sequence json has primers at the top level separate from features, e.g. parsedSequence: { primers: [ {}, {} ], features: [ {}, {} ] }
// if options.primersAsFeatures is set to true, primers are included in features with type set to primer
if (!options.primersAsFeatures) {
for (let i = 0; i < results.length; i++) {
if (results[i].success) {
results[i].parsedSequence.primers = results[
i
].parsedSequence.features.filter((feat) => feat.type === "primer");
results[i].parsedSequence.features = results[
i
].parsedSequence.features.filter((feat) => feat.type !== "primer");

results.forEach((result) => {
if (result.success) {
const sequence = result.parsedSequence;
sequence.features.forEach((feat) => {
if (feat.type === "primer") {
feat.type = "primer_bind";
}
});

if (!options.primersAsFeatures) {
sequence.primers = sequence.features.filter(
(feat) => feat.type === "primer_bind"
);
sequence.features = sequence.features.filter(
(feat) => feat.type !== "primer_bind"
);
}
}
}
});

return results;

function endSeq() {
Expand Down
7 changes: 7 additions & 0 deletions src/parsers/utils/validateSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ export default function validateSequence(sequence, options = {}) {
feature.strand = 1;
}
let invalidFeatureType;
if (
feature.type &&
typeof feature.type === "string" &&
feature.type.toLowerCase() === "primer"
) {
feature.type = "primer_bind";
}
if (
!feature.type ||
typeof feature.type !== "string" ||
Expand Down
16 changes: 8 additions & 8 deletions src/test/genbankToJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ ORIGIN
});
});

it("parses a gb with features of type primer, outputs json w/primers at top level by default", function() {
it("parses a gb with features of type primer_bind, outputs json w/primers at top level by default", function() {
const string = fs.readFileSync(
path.join(__dirname, "./testData/genbank/testing_primers.gb"),
"utf8"
Expand Down Expand Up @@ -441,15 +441,15 @@ ORIGIN
result[0].parsedSequence.primers.should.containSubset([
{
notes: {},
type: "primer",
type: "primer_bind",
strand: 1,
name: "primer1",
start: 5,
end: 9,
},
{
notes: {},
type: "primer",
type: "primer_bind",
strand: 1,
name: "primer2",
start: 17,
Expand All @@ -462,7 +462,7 @@ ORIGIN
});
});

it("parses a gb with features of type primer, outputs json w/primers as features of type primer because primersAsFeatures = true", function() {
it("parses a gb with features of type primer_bind, outputs json w/primers as features of type primer_bind because primersAsFeatures = true", function() {
const string = fs.readFileSync(
path.join(__dirname, "./testData/genbank/testing_primers.gb"),
"utf8"
Expand All @@ -483,7 +483,7 @@ ORIGIN
},
{
notes: {},
type: "primer",
type: "primer_bind",
strand: 1,
name: "primer1",
start: 5,
Expand All @@ -499,7 +499,7 @@ ORIGIN
},
{
notes: {},
type: "primer",
type: "primer_bind",
strand: 1,
name: "primer2",
start: 17,
Expand All @@ -512,7 +512,7 @@ ORIGIN
});
});

it("parses a multi-seq gb with features of type primer, outputs json w/primers at top level by default", function() {
it("parses a multi-seq gb with features of type primer_bind, outputs json w/primers at top level by default", function() {
const string = fs.readFileSync(
path.join(__dirname, "./testData/genbank/testing_primers_multiseq.gb"),
"utf8"
Expand All @@ -530,7 +530,7 @@ ORIGIN
});
});

it("parses a multi-seq gb with features of type primer, outputs json w/primers as features of type primer because primersAsFeatures = true", function() {
it("parses a multi-seq gb with features of type primer_bind, outputs json w/primers as features of type primer_bind because primersAsFeatures = true", function() {
const string = fs.readFileSync(
path.join(__dirname, "./testData/genbank/testing_primers_multiseq.gb"),
"utf8"
Expand Down
2 changes: 1 addition & 1 deletion src/test/jsonToGenbank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe("genbank exporter/parser conversion", function() {

result[0].parsedSequence.primers.should.containSubset([
{
type: "primer",
type: "primer_bind",
strand: 1,
name: "primer_to_export",
start: 5,
Expand Down
2 changes: 1 addition & 1 deletion src/test/testData/genbank/testing_primers.gb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ LOCUS testing_primers 27 bp DNA linear 25-JUL-2019
FEATURES Location/Qualifiers
misc_feature 2..4
/label="feature1"
primer 6..10
primer_bind 6..10
/label="primer1"
misc_feature 12..16
/label="feature2"
Expand Down
6 changes: 3 additions & 3 deletions src/test/testData/genbank/testing_primers_multiseq.gb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ LOCUS testing_primers1 27 bp DNA linear 25-JUL-2019
FEATURES Location/Qualifiers
misc_feature 2..4
/label="feature1"
primer 6..10
primer_bind 6..10
/label="primer1"
misc_feature 12..16
/label="feature2"
primer 18..24
primer_bind 18..24
/label="primer2"
ORIGIN
1 ATGCATTGAG GACCTAACCA TATCTAA
Expand All @@ -15,7 +15,7 @@ LOCUS testing_primers2 27 bp DNA linear 25-JUL-2019
FEATURES Location/Qualifiers
misc_feature 2..4
/label="feature3"
primer 6..10
primer_bind 6..10
/label="primer3"
misc_feature 12..16
/label="feature4"
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async@1.x, async@^1.5.0, async@^1.5.2:
async@1.x, async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=
Expand Down Expand Up @@ -10945,10 +10945,10 @@ ve-range-utils@^2.5.9:
lodash "^4.17.4"
validate.io-nonnegative-integer-array "^1.0.1"

ve-sequence-utils@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/ve-sequence-utils/-/ve-sequence-utils-5.0.0.tgz#521379ca017348714476bf60f276cd220ed8ee1d"
integrity sha512-kQKJbiwTlxBIWbQih5tRhpmUzERPkLDnL93EJeQTXSg7LSZn0fLzjtpc3Yjuu6ok8tNLApn420e0QVbvc2b5cA==
ve-sequence-utils@5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/ve-sequence-utils/-/ve-sequence-utils-5.1.0.tgz#3a2948a71fbce7c3ff0e102760598ef3e32070ad"
integrity sha512-/9gHhuXjcu2gR5yCrCwy5b0ie/5r+umZDF3fJswT7uO+K6RfNEszVRKByHwOfwKCK0dgGrzs6dMaDZfRETlZdA==
dependencies:
bson-objectid "^1.1.1"
escape-string-regexp "^1.0.5"
Expand Down

0 comments on commit ebc286e

Please sign in to comment.