Skip to content

Commit

Permalink
updating tidyUpAnnotation.js to auto-parse annotation.notes into JSON…
Browse files Browse the repository at this point in the history
… and gracefully handle errors
  • Loading branch information
tnrich committed Aug 16, 2022
1 parent 998a637 commit c8821b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/tidyUpAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ module.exports = function tidyUpAnnotation(
);
annotation.type = "misc_feature";
}
if (annotation.notes && typeof annotation.notes === "string") {
try {
annotation.notes = JSON.parse(annotation.notes);
} catch (error) {
console.info(
`warning 33y00a0912 - couldn't parse notes for ${annotation.name ||
""} ${annotation.notes}:`,
error
);
}
}

if (!annotation.color) {
annotation.color = featureColors[annotation.type];
Expand Down
27 changes: 27 additions & 0 deletions src/tidyUpSequenceData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,33 @@ describe("tidyUpSequenceData", function() {
});
res.features[0].type.should.equal("misc_feature");
});
it("should try to auto-parse annotation.notes into JSON and gracefully handle errors", function() {
const res = tidyUpSequenceData({
features: [
{
start: 4,
end: 5,
notes:
'{"gene":["Ampicillin"],"note":["ORF frame 1"],"translation":["MSIQHFRVALIPFFAAFCLPVFAHPETLVKVKDAEDQLGARVGYIELDLNSGKILESFRPEERFPMMSTFKVLLCGAVLSRIDAGQEQLGRRIHYSQNDLVEYSPVTEKHLTDGMTVRELCSAAITMSDNTAANLLLTTIGGPKELTAFLHNMGDHVTRLDRWEPELNEAIPNDERDTTMPVAMATTLRKLLTGELLTLASRQQLIDWMEADKVAGPLLRSALPAGWFIADKSGAGERGSRGIIAALGPDGKPSRIVVIYTTGSQATMDERNRQIAEIGASLIKHW*"],"ApEinfo_fwdcolor":["pink"],"ApEinfo_revcolor":["pink"],"ApEinfo_graphicformat":["arrow_data {{0 1 2 0 0 -1} {} 0}"]}'
}
]
});
res.features[0].notes.gene[0].should.equal("Ampicillin");
const res2 = tidyUpSequenceData({
features: [
{
start: 4,
end: 5,
//messed up JSON notes here:
notes:
'{"gene:["Ampicillin"],"note":["ORF frame 1"],"translation":["MSIQHFRVALIPFFAAFCLPVFAHPETLVKVKDAEDQLGARVGYIELDLNSGKILESFRPEERFPMMSTFKVLLCGAVLSRIDAGQEQLGRRIHYSQNDLVEYSPVTEKHLTDGMTVRELCSAAITMSDNTAANLLLTTIGGPKELTAFLHNMGDHVTRLDRWEPELNEAIPNDERDTTMPVAMATTLRKLLTGELLTLASRQQLIDWMEADKVAGPLLRSALPAGWFIADKSGAGERGSRGIIAALGPDGKPSRIVVIYTTGSQATMDERNRQIAEIGASLIKHW*"],"ApEinfo_fwdcolor":["pink"],"ApEinfo_revcolor":["pink"],"ApEinfo_graphicformat":["arrow_data {{0 1 2 0 0 -1} {} 0}"]}'
}
]
});
res2.features[0].notes.should.equal(
'{"gene:["Ampicillin"],"note":["ORF frame 1"],"translation":["MSIQHFRVALIPFFAAFCLPVFAHPETLVKVKDAEDQLGARVGYIELDLNSGKILESFRPEERFPMMSTFKVLLCGAVLSRIDAGQEQLGRRIHYSQNDLVEYSPVTEKHLTDGMTVRELCSAAITMSDNTAANLLLTTIGGPKELTAFLHNMGDHVTRLDRWEPELNEAIPNDERDTTMPVAMATTLRKLLTGELLTLASRQQLIDWMEADKVAGPLLRSALPAGWFIADKSGAGERGSRGIIAALGPDGKPSRIVVIYTTGSQATMDERNRQIAEIGASLIKHW*"],"ApEinfo_fwdcolor":["pink"],"ApEinfo_revcolor":["pink"],"ApEinfo_graphicformat":["arrow_data {{0 1 2 0 0 -1} {} 0}"]}'
);
});
it("should add feature type = misc_feature if an invalid type is provided", function() {
const res = tidyUpSequenceData({
features: [{ start: 4, end: 5, type: "idontexist" }]
Expand Down

0 comments on commit c8821b9

Please sign in to comment.