npm install biojs-io-fasta
<script src="http://wzrd.in/bundle/biojs-io-fasta@latest"></script>
- You can find a JSBin to play around with it.
- Remember that you need CORS to download files from other servers on the web
var Fasta = require('biojs-io-fasta');
Parses an url an calls your parse
method with the returned body.
Fasta.read("https://raw.githubusercontent.com/biojs-io/biojs-io-fasta/master/test/foo.fasta", function(err, model) {
// model is the parsed url
});
If callback is undefined, read
returns a promise.
var p = Fasta.read("https://raw.githubusercontent.com/biojs-io/biojs-io-fasta/master/test/foo.fasta");
// ...
p.then(function(model) {
// model is the parsed url
}, function(err){
console.error("err happened during downloading", err);
});
var seqs = Fasta.parse(str);
var text = Fasta.export(seqs);
Thanks to @sillitoe you can provide a custom parser if your FASTA header is formatted "in weird and wonderful ways".
var customGetMeta = function(header) {
return {
id: "id",
name: "name",
// optional
details: {
foo: "bar"
},
// optional
ids: {
customId: "bar"
}
};
}
var altFasta = Fasta.extend(customGetMeta);
Take a look at tests for a better example of such a parser;
{
seq: "ABC",
name: "awesome seq",
id: "unique id"
}
Install dependencies and execute the tests:
npm install
npm script compile && npm test
To build a JS file for the browser, execute:
npm run build-browser
Apache 2