Skip to content

Commit

Permalink
adding a umd example to the readme and updating the validation functi…
Browse files Browse the repository at this point in the history
…on slightly
  • Loading branch information
tnrich committed Jun 9, 2021
1 parent ce59fbf commit 849b802
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,45 @@ or

`yarn add bio-parsers`

or

use it from a script tag:
```html
<script src="https://unpkg.com/bio-parsers/umd/bio-parsers.js"></script>
<script>
async function main() {
var jsonOutput = await window.bioParsers.genbankToJson(
`LOCUS kc2 108 bp DNA linear 01-NOV-2016
COMMENT teselagen_unique_id: 581929a7bc6d3e00ac7394e8
FEATURES Location/Qualifiers
CDS 1..108
/label="GFPuv"
misc_feature 61..108
/label="gly_ser_linker"
bogus_dude 4..60
/label="ccmN_sig_pep"
misc_feature 4..60
/label="ccmN_nterm_sig_pep"
/pragma="Teselagen_Part"
/preferred5PrimeOverhangs=""
/preferred3PrimeOverhangs=""
ORIGIN
1 atgaaggtct acggcaagga acagtttttg cggatgcgcc agagcatgtt ccccgatcgc
61 ggtggcagtg gtagcgggag ctcgggtggc tcaggctctg ggg
//`
);
console.log('jsonOutput:', jsonOutput);
var genbankString = window.bioParsers.jsonToGenbank(jsonOutput[0].parsedSequence);
console.log(genbankString);
}
main();
</script>
```



see the `./umd_demo.html` file for a full working example

### jsonToGenbank (same interface as jsonToFasta)
```js
//To go from json to genbank:
Expand Down
7 changes: 3 additions & 4 deletions src/parsers/utils/validateSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,14 @@ export default function validateSequence(sequence, options = {}) {
!areNonNegativeIntegers([feature.end]) ||
feature.end > sequence.size - (inclusive1BasedEnd ? 0 : 1)
) {
feature.end = Math.max(sequence.size - 1, inclusive1BasedEnd ? 0 : 1);
response.messages.push(
"Invalid feature end: " +
feature.end +
" detected for " +
feature.name +
" and set to 1"
); //setting it to 0 internally, but users will see it as 1
feature.end = Math.max(sequence.size - 1, inclusive1BasedEnd ? 0 : 1);
// feature.end = 0;
" and set to " + (feature.end + 1)
);
}

if (
Expand Down
35 changes: 35 additions & 0 deletions umd_demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html>
<head>
<script src="https://unpkg.com/bio-parsers/umd/bio-parsers.js"></script>
<!-- you can also specify a version: <script src="https://unpkg.com/bio-parsers@8.3.11/umd/bio-parsers.js"></script> -->
<script>
async function main() {
var jsonOutput = await window.bioParsers.genbankToJson(
`LOCUS kc2 108 bp DNA linear 01-NOV-2016
COMMENT teselagen_unique_id: 581929a7bc6d3e00ac7394e8
FEATURES Location/Qualifiers
CDS 1..108
/label="GFPuv"
misc_feature 61..108
/label="gly_ser_linker"
bogus_dude 4..60
/label="ccmN_sig_pep"
misc_feature 4..60
/label="ccmN_nterm_sig_pep"
/pragma="Teselagen_Part"
/preferred5PrimeOverhangs=""
/preferred3PrimeOverhangs=""
ORIGIN
1 atgaaggtct acggcaagga acagtttttg cggatgcgcc agagcatgtt ccccgatcgc
61 ggtggcagtg gtagcgggag ctcgggtggc tcaggctctg ggg
//`
);
console.log('jsonOutput:', jsonOutput);

var genbankString = window.bioParsers.jsonToGenbank(jsonOutput[0].parsedSequence);
console.log(genbankString);
}
main();
</script>
</head>
</html>

0 comments on commit 849b802

Please sign in to comment.