Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit 0178ed9

Browse files
committed
Initial commit
0 parents  commit 0178ed9

22 files changed

Lines changed: 1398 additions & 0 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
coverage
4+
tmp

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
after_script:
5+
- npm run coveralls

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Bruno Vieira <mail@bmpvieira.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<p align="center">
2+
<a href="http://bionode.io">
3+
<img height="200" width="200" title="bionode" alt="bionode logo" src="https://rawgithub.com/bionode/bionode/master/docs/bionode-logo.min.svg"/>
4+
</a>
5+
<br/>
6+
<a href="http://bionode.io/">bionode.io</a>
7+
</p>
8+
# bionode-sra [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status](https://david-dm.org/bionode/bionode.png?theme=shields.io)](//david-dm.org/bionode/bionode)
9+
10+
> A Node.js wrapper for SRA Toolkit.
11+
12+
Install
13+
-------
14+
15+
Install bionode-sra with [npm](//npmjs.org):
16+
17+
```sh
18+
$ npm install bionode-sra
19+
```
20+
To use it as a command line tool, you can install it globally by adding ```-g``` .
21+
22+
Usage
23+
-----
24+
25+
If you're using bionode-sra with Node.js, you can require the module:
26+
27+
```js
28+
var sra = require('bionode-sra')
29+
var fastqDump = sra('fastq-dump')
30+
fastqDump('SRR1509835.sra')
31+
```
32+
33+
Please read the [documentation](http://rawgit.com/bionode/bionode-sra/master/docs/bionode-sra.html) for the methods exposed by bionode.
34+
35+
### Command line examples
36+
```sh
37+
$ bionode-sra fastq-dump SRR1509835.sra
38+
$ bionode-sra fastq-dump SRR1509835.sra fastqOutputDirectory
39+
```
40+
41+
Contributing
42+
------------
43+
44+
To contribute, clone this repo locally and commit your code on a separate branch.
45+
46+
Please write unit tests for your code, and check that everything works by running the following before opening a pull-request:
47+
48+
```sh
49+
$ npm test
50+
```
51+
52+
Please also check for code coverage:
53+
54+
```sh
55+
$ npm run coverage
56+
```
57+
58+
To rebuild the documentation using the comments in the code:
59+
60+
```sh
61+
$ npm run build-docs
62+
```
63+
Check the [issues](http://github.com/bionode/bionode-sra/issues) for ways to contribute.
64+
65+
Contacts
66+
--------
67+
Bruno Vieira <[mail@bmpvieira.com](mailto:mail@bmpvieira.com)> [@bmpvieira](//twitter.com/bmpvieira)
68+
69+
Yannick Wurm ([yannick.poulet.org](http://yannick.poulet.org)) [@yannick__](//twitter.com/yannick__)
70+
71+
License
72+
-------
73+
74+
bionode-sra is licensed under the [MIT](https://raw.github.com/bionode/bionode/master/LICENSE) license.
75+
Check [ChooseALicense.com](http://choosealicense.com/licenses/mit) for details.
76+
77+
[npm-url]: //npmjs.org/package/bionode-sra
78+
[npm-image]: https://badge.fury.io/js/bionode-sra.png
79+
[travis-url]: //travis-ci.org/bionode/bionode-sra
80+
[travis-image]: https://travis-ci.org/bionode/bionode-sra.png?branch=master
81+
[coveralls-url]: //coveralls.io/r/bionode/bionode-sra
82+
[coveralls-image]: https://coveralls.io/repos/bionode/bionode-sra/badge.png
83+
[depstat-url]: //david-dm.org/bionode/bionode-sra
84+
[depstat-image]: https://david-dm.org/bionode/bionode-sra.png
85+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/bionode/bionode-sra/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

cli.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
var JSONStream = require('JSONStream')
3+
var sra = require('./')
4+
5+
var args = process.argv.slice(2)
6+
7+
var command = args[0]
8+
var srcFile = args[1]
9+
var destDir = args[2]
10+
11+
12+
var sraStream = sra(command)
13+
14+
sraStream([srcFile, destDir]).pipe(JSONStream.stringify(false)).pipe(process.stdout)

docs/bionode-sra.html

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<title>bionode-sra</title>
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
7+
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
8+
<link rel="stylesheet" media="all" href="docco.css" />
9+
</head>
10+
<body>
11+
<div id="container">
12+
<div id="background"></div>
13+
14+
<ul class="sections">
15+
16+
17+
18+
<li id="section-1">
19+
<div class="annotation">
20+
21+
<div class="pilwrap ">
22+
<a class="pilcrow" href="#section-1">&#182;</a>
23+
</div>
24+
<h1 id="bionode-sra">bionode-sra</h1>
25+
<blockquote>
26+
<p>A Node.js wrapper for SRA Toolkit.</p>
27+
<p>doi: <a href="?">?</a>
28+
author: <a href="http://bmpvieira.com">Bruno Vieira</a>
29+
email: <a href="&#109;&#x61;&#x69;&#108;&#x74;&#111;&#58;&#x6d;&#x61;&#x69;&#x6c;&#64;&#x62;&#109;&#112;&#x76;&#x69;&#x65;&#105;&#114;&#x61;&#46;&#x63;&#x6f;&#109;">&#x6d;&#x61;&#x69;&#x6c;&#64;&#x62;&#109;&#112;&#x76;&#x69;&#x65;&#105;&#114;&#x61;&#46;&#x63;&#x6f;&#109;</a>
30+
license: <a href="https://raw.githubusercontent.com/bionode/bionode-sra/master/LICENSE">MIT</a></p>
31+
</blockquote>
32+
<hr>
33+
34+
</div>
35+
36+
</li>
37+
38+
39+
<li id="section-2">
40+
<div class="annotation">
41+
42+
<div class="pilwrap ">
43+
<a class="pilcrow" href="#section-2">&#182;</a>
44+
</div>
45+
<h2 id="usage">Usage</h2>
46+
<p>This module can be used in Node.js as described further below, or as a command line tool.
47+
Examples:</p>
48+
<pre><code>$ npm install -g bionode-sra
49+
50+
# bionode-sra [command] [<span class="hljs-built_in">arguments</span>...]
51+
$ bionode-sra fastq-dump SRR1509835.sra
52+
$ bionode-sra fastq-dump SRR1509835.sra fastqOutputDirectory
53+
</code></pre>
54+
</div>
55+
56+
<div class="content"><div class='highlight'><pre>
57+
58+
<span class="hljs-keyword">var</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">'path'</span>)
59+
<span class="hljs-keyword">var</span> spawn = <span class="hljs-built_in">require</span>(<span class="hljs-string">'child_process'</span>).spawn
60+
<span class="hljs-keyword">var</span> through = <span class="hljs-built_in">require</span>(<span class="hljs-string">'through2'</span>)
61+
62+
<span class="hljs-built_in">module</span>.exports = exports = SRA</pre></div></div>
63+
64+
</li>
65+
66+
67+
<li id="section-3">
68+
<div class="annotation">
69+
70+
<div class="pilwrap ">
71+
<a class="pilcrow" href="#section-3">&#182;</a>
72+
</div>
73+
<h2 id="sra">SRA</h2>
74+
<p>Takes a SRA toolkit command and returns a Stream that accepts arguments for it.
75+
For example, for <code>fastq-dump</code>, arguments can be an array with <code>[srcSRA, destDir]</code>,
76+
a string like <code>&#39;srcSRA destDir&#39;</code>. If <code>destDir</code> is omitted, the current directory will be used.</p>
77+
<pre><code><span class="hljs-keyword">var</span> sra = <span class="hljs-built_in">require</span>(<span class="hljs-string">'bionode-sra'</span>)
78+
<span class="hljs-keyword">var</span> fastqDump = sra(<span class="hljs-string">'fastq-dump'</span>)()
79+
fastqDump.on(<span class="hljs-string">'data'</span>, <span class="hljs-built_in">console</span>.log)
80+
fastqDump.write([<span class="hljs-string">'SRR1509835.sra'</span>, <span class="hljs-string">'fastqOutDir'</span>])
81+
=&gt; { srcFile: <span class="hljs-string">'SRR1509835.sra'</span>,
82+
command: <span class="hljs-string">'fastq-dump'</span>,
83+
destDir: <span class="hljs-string">'fastqOutDir'</span> }
84+
</code></pre><p>A callback style can also be used:</p>
85+
<pre><code><span class="hljs-keyword">var</span> fastqDump = sra(<span class="hljs-string">'fastq-dump'</span>)
86+
fastqDump(<span class="hljs-string">'SRR1509835.sra fastqOutDir'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, data)</span> </span>{
87+
<span class="hljs-built_in">console</span>.log(data)
88+
})
89+
</code></pre><p>Or pipes, for example, from a file with just a list of SRA file names:</p>
90+
<pre><code><span class="hljs-keyword">var</span> split = <span class="hljs-built_in">require</span>(<span class="hljs-string">'split'</span>)
91+
<span class="hljs-keyword">var</span> fastqDump = sra(<span class="hljs-string">'fastq-dump'</span>)()
92+
fs.createReadStream(<span class="hljs-string">'sraFilesList.txt'</span>)
93+
.pipe(split())
94+
.pipe(fastqDump)
95+
</code></pre>
96+
</div>
97+
98+
<div class="content"><div class='highlight'><pre>
99+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">SRA</span><span class="hljs-params">(command)</span> </span>{
100+
<span class="hljs-keyword">var</span> command = command || <span class="hljs-string">'fastq-dump'</span>
101+
102+
<span class="hljs-keyword">return</span> sraStream
103+
104+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sraStream</span><span class="hljs-params">(srcFileDestDir, callback)</span> </span>{
105+
<span class="hljs-keyword">var</span> stream = through.obj(transform)
106+
<span class="hljs-keyword">if</span> (srcFileDestDir) { stream.write(srcFileDestDir); stream.end() }
107+
<span class="hljs-keyword">if</span> (callback) {
108+
stream.on(<span class="hljs-string">'data'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(data)</span> </span>{
109+
callback(<span class="hljs-literal">null</span>, data)
110+
})
111+
stream.on(<span class="hljs-string">'error'</span>, callback)
112+
}
113+
<span class="hljs-keyword">return</span> stream
114+
115+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transform</span><span class="hljs-params">(obj, enc, next)</span> </span>{
116+
<span class="hljs-keyword">var</span> self = <span class="hljs-keyword">this</span>
117+
118+
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> obj === <span class="hljs-string">'string'</span>) { obj = obj.split(<span class="hljs-string">' '</span>) }
119+
120+
<span class="hljs-keyword">if</span> (obj.length &gt; <span class="hljs-number">2</span>) { self.emit(<span class="hljs-string">'error'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Too many arguments for aspera'</span>)); next() }
121+
122+
<span class="hljs-keyword">if</span> (obj.length === <span class="hljs-number">1</span>) { obj.push(<span class="hljs-string">'.'</span>) }
123+
124+
<span class="hljs-keyword">var</span> sraPath = path.join(__dirname, <span class="hljs-string">'../sra/bin/'</span>+command)
125+
<span class="hljs-keyword">var</span> srcFile = obj[<span class="hljs-number">0</span>]
126+
<span class="hljs-keyword">var</span> destDir = obj[<span class="hljs-number">1</span>]
127+
<span class="hljs-keyword">var</span> options
128+
<span class="hljs-keyword">if</span> (destDir === <span class="hljs-string">'.'</span>) {
129+
options = [srcFile]
130+
}
131+
<span class="hljs-keyword">else</span> {
132+
<span class="hljs-keyword">var</span> options = [srcFile, <span class="hljs-string">'-O'</span>, destDir]
133+
}
134+
<span class="hljs-keyword">var</span> sra = spawn(sraPath, options)
135+
136+
sra.stderr.on(<span class="hljs-string">'data'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(data)</span> </span>{
137+
self.emit(<span class="hljs-string">'error'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(data.toString()))
138+
next()
139+
})
140+
141+
sra.on(<span class="hljs-string">'close'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(code)</span> </span>{
142+
<span class="hljs-keyword">if</span> (code) {
143+
self.emit(<span class="hljs-string">'error'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Unknown error, check that "'</span>+obj[<span class="hljs-number">0</span>]+<span class="hljs-string">'" exists'</span>))
144+
}
145+
<span class="hljs-keyword">else</span> {
146+
self.push({srcFile: obj[<span class="hljs-number">0</span>], command: command, destDir: obj[<span class="hljs-number">1</span>]})
147+
next()
148+
}
149+
})
150+
}
151+
}
152+
}</pre></div></div>
153+
154+
</li>
155+
156+
</ul>
157+
</div>
158+
</body>
159+
</html>

0 commit comments

Comments
 (0)