Skip to content

Commit

Permalink
made convertResponse browser compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarks committed Jan 28, 2016
1 parent 8665498 commit c669c50
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 78 deletions.
80 changes: 45 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://img.shields.io/circleci/project/nathanmarks/cbioportal-api-client/master.svg?style=flat-square)](https://circleci.com/gh/nathanmarks/cbioportal-api-client) [![Coverage Status](https://img.shields.io/coveralls/nathanmarks/cbioportal-api-client/master.svg?style=flat-square)](https://coveralls.io/github/nathanmarks/cbioportal-api-client?branch=master)
[![Dependency Status](https://david-dm.org/nathanmarks/cbioportal-api-client.svg?style=flat-square)](https://david-dm.org/nathanmarks/cbioportal-api-client)

[cBio Portal API](http://www.cbioportal.org/web_api.jsp) client. Parses tab separated responses into JSON format. Works in node and in the browser* via a module loader such as [Webpack](http://webpack.github.io) (***soon:** just finalizing the browser build).
[cBio Portal API](http://www.cbioportal.org/web_api.jsp) client. Parses tab separated responses into JSON format. Works in node and in the browser via a module loader such as [Webpack](http://webpack.github.io) (**soon:** just finalizing the browser build).

This library can be used programatically or via the command line.

Expand Down Expand Up @@ -82,9 +82,8 @@ $ cbioportal-api-client getAlterationSummary -s gbm_tcga_cnaseq -p gbm_tcga_muta
## Modules
<dl>
<dt><a href="#module_cbioportal-api-client">cbioportal-api-client</a><code>cbioPortal</code></dt>
<dd><p>Creates a new cBio Portal API client</p>
</dd>
<dt><a href="#module_cbioportal-api-client">cbioportal-api-client</a></dt>
<dd></dd>
<dt><a href="#module_cbioportal-api-client/utils/convertResponse">cbioportal-api-client/utils/convertResponse</a><code>Promise</code></dt>
<dd><p>Converts tab delimited responses to JSON format</p>
</dd>
Expand All @@ -94,17 +93,35 @@ $ cbioportal-api-client getAlterationSummary -s gbm_tcga_cnaseq -p gbm_tcga_muta
</dl>
<a name="module_cbioportal-api-client"></a>
## cbioportal-api-client ⇒ <code>cbioPortal</code>
## cbioportal-api-client
* [cbioportal-api-client](#module_cbioportal-api-client)
* _exports_
* [⏏ exports.default(config)](#exp_module_cbioportal-api-client.default) ⇒ <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
* _inner_
* [~cbioPortal](#module_cbioportal-api-client..cbioPortal) : <code>Object</code>
* [.getTypesOfCancer()](#module_cbioportal-api-client..cbioPortal+getTypesOfCancer) ⇒ <code>Promise</code>
* [.getCancerStudies()](#module_cbioportal-api-client..cbioPortal+getCancerStudies) ⇒ <code>Promise</code>
* [.getGeneticProfiles(query)](#module_cbioportal-api-client..cbioPortal+getGeneticProfiles) ⇒ <code>Promise</code>
* [.getCaseLists(query)](#module_cbioportal-api-client..cbioPortal+getCaseLists) ⇒ <code>Promise</code>
* [.getProfileData(query)](#module_cbioportal-api-client..cbioPortal+getProfileData) ⇒ <code>Promise</code>
-----
<a name="exp_module_cbioportal-api-client.default"></a>
### cbioportal-api-client ⏏ exports.default(config) ⇒ <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
Creates a new cBio Portal API client
**See**: [cbioPortal](#module_cbioportal-api-client..cbioPortal)
**Kind**: exports method of <code>[cbioportal-api-client](#module_cbioportal-api-client)</code>
**Returns**: <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
| Param | Type | Description |
| --- | --- | --- |
| config | <code>Object</code> | Configuration options object. |
| config.requestOpts | <code>Object</code> | Override the request congfiguration object. |
**Example**
**Example**
Basic usage:
```javascript
Expand All @@ -118,24 +135,15 @@ cbioPortal.getCancerStudies()
});
```
* [cbioportal-api-client](#module_cbioportal-api-client) ⇒ <code>cbioPortal</code>
* [~cbioPortal](#module_cbioportal-api-client..cbioPortal) : <code>Object</code>
* [.getTypesOfCancer()](#module_cbioportal-api-client..cbioPortal+getTypesOfCancer) ⇒ <code>Promise</code>
* [.getCancerStudies()](#module_cbioportal-api-client..cbioPortal+getCancerStudies) ⇒ <code>Promise</code>
* [.getGeneticProfiles(query)](#module_cbioportal-api-client..cbioPortal+getGeneticProfiles) ⇒ <code>Promise</code>
* [.getCaseLists(query)](#module_cbioportal-api-client..cbioPortal+getCaseLists) ⇒ <code>Promise</code>
* [.getProfileData(query)](#module_cbioportal-api-client..cbioPortal+getProfileData) ⇒ <code>Promise</code>
-----
<a name="module_cbioportal-api-client..cbioPortal"></a>
### cbioportal-api-client~cbioPortal : <code>Object</code>
cbioPortal API Object Prototype. Used as the object prototype
when creating an API client object via the module factory method.
**Kind**: inner constant of <code>[cbioportal-api-client](#module_cbioportal-api-client)</code>
**See**: Use [CbioPortal()](#module_cbioportal-api-client) for object creation.
**Kind**: inner constant of <code>[cbioportal-api-client](#module_cbioportal-api-client)</code>
**See**: Use [CbioPortal()](#module_cbioportal-api-client) for object creation.
* [~cbioPortal](#module_cbioportal-api-client..cbioPortal) : <code>Object</code>
* [.getTypesOfCancer()](#module_cbioportal-api-client..cbioPortal+getTypesOfCancer) ⇒ <code>Promise</code>
Expand All @@ -151,19 +159,19 @@ when creating an API client object via the module factory method.
#### cbioPortal.getTypesOfCancer() ⇒ <code>Promise</code>
Retrieves a list of all the clinical types of cancer stored on the server.
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
-----
<a name="module_cbioportal-api-client..cbioPortal+getCancerStudies"></a>
#### cbioPortal.getCancerStudies() ⇒ <code>Promise</code>
Retrieves meta-data regarding cancer studies stored on the server.
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
-----
Expand All @@ -172,9 +180,9 @@ Retrieves meta-data regarding cancer studies stored on the server.
Retrieves meta-data regarding all genetic profiles, e.g.
mutation or copy number profiles, stored about a specific cancer study.
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code> - See fullfills/rejects
**Fulfills**: <code>Array</code> response data converted from TSV to JSON
| Param | Type | Description |
| --- | --- | --- |
Expand All @@ -192,8 +200,9 @@ For example, a within a particular study, only some cases may have sequence data
Multiple case lists may be associated with each cancer study, and this method enables you to retrieve meta-data regarding all of these case lists.
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Fulfill**: JSON formatted response
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code>
**Fulfill**: JSON formatted response
| Param | Type | Description |
| --- | --- | --- |
Expand All @@ -209,8 +218,9 @@ Retrieves genomic profile data for one or more genes.
**Note:** If you pass in multiple genetic profile IDs and multiple genes, the library will make multiple requests as the API does not support this type of query.
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Fulfill**: JSON formatted response
**Kind**: instance method of <code>[cbioPortal](#module_cbioportal-api-client..cbioPortal)</code>
**Returns**: <code>Promise</code>
**Fulfill**: JSON formatted response
| Param | Type | Description |
| --- | --- | --- |
Expand All @@ -226,7 +236,7 @@ Retrieves genomic profile data for one or more genes.
## cbioportal-api-client/utils/convertResponse ⇒ <code>Promise</code>
Converts tab delimited responses to JSON format
**Returns**: <code>Promise</code> - Resolves with the response JSON
**Returns**: <code>Promise</code> - Resolves with the response JSON
| Param | Type | Description |
| --- | --- | --- |
Expand All @@ -239,14 +249,14 @@ Converts tab delimited responses to JSON format
## cbioportal-api-client/utils/summarizeAlterations ⇒ <code>Promise</code>
Summarizes alterations for results
**Returns**: <code>Promise</code> - Resolves with the summary
**Fulfills**: <code>Object</code> Object with results, see example
**Returns**: <code>Promise</code> - Resolves with the summary
**Fulfills**: <code>Object</code> Object with results, see example
| Param | Type | Description |
| --- | --- | --- |
| dataSets | <code>Object</code> &#124; <code>Array</code> | Converted response dataset(s) |
**Example**
**Example**
Basic Usage:
```javascript
Expand Down
Binary file added docs/partials/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions docs/partials/shared/signature/sig-link-html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{#if name}}{{#sig no-gfm=true ~}}
{{{@depOpen}~}}
<a href="#{{{anchorName}}}">
{{~{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{~#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}~}}
</a>
{{~#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes html=true delimiter=" | " }}{{/if~}}
{{#if @suffix}} {{@suffix}}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
13 changes: 13 additions & 0 deletions docs/partials/shared/signature/sig-link-parent.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#if name}}{{#sig~}}
{{{@depOpen}~}}
[{{{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{#if (isClassMember)}}{{@parent~}}{{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{~#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}}}](#{{{anchorName}}})
{{~#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes delimiter=" &#124; " }}{{/if~}}
{{#if @suffix}} {{@suffix}}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
14 changes: 14 additions & 0 deletions docs/partials/shared/signature/sig-link.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
{{#if name}}{{#sig~}}
{{{@depOpen}~}}
[{{{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{#if @suffix}}{{@suffix}} {{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{~#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}}}](#{{{anchorName}}})
{{~#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes delimiter=" &#124; " }}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
15 changes: 15 additions & 0 deletions docs/partials/shared/signature/sig-name.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
{{#if name}}{{#sig~}}
{{{@depOpen}~}}
{{{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{@parent~}}
{{#if @suffix}} {{@suffix}} {{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}~}}
{{#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes delimiter=" &#124; " }}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
76 changes: 37 additions & 39 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,43 @@ import {
summarizeAlterations
} from './utils';

/**
* @module cbioportal-api-client
*/

/**
* Creates a new cBio Portal API client
*
* @example
*
* Basic usage:
*
* ```javascript
* import CbioPortal from 'cbioportal-api-client';
*
* const cbioPortal = CbioPortal();
*
* cbioPortal.getCancerStudies()
* .then(response => {
* console.log(response); // Prints array of cancer studies returned from API
* });
* ```
*
* @param {Object} config Configuration options object.
* @param {Object} config.requestOpts Override the request congfiguration object.
* @returns {module:cbioportal-api-client~cbioPortal}
*/
export default function CbioPortal ({ requestOpts = false } = {}) {
return Object.assign(Object.create(cbioPortal), {
requestOpts: _defaults(requestOpts, {
headers: {
'User-Agent': 'cbioportal-api-client.js/0.0.1'
},
uri: 'http://www.cbioportal.org/webservice.do'
})
});
}

/**
* parseArray
*
Expand All @@ -29,8 +66,6 @@ function parseArray (x) {
* cbioPortal API Object Prototype. Used as the object prototype
* when creating an API client object via the module factory method.
*
* @memberOf module:cbioportal-api-client
* @alias module:cbioportal-api-client~cbioPortal
* @see Use {@link module:cbioportal-api-client|CbioPortal()} for object creation.
* @type {Object}
*/
Expand Down Expand Up @@ -147,40 +182,3 @@ const cbioPortal = {
}

};

/**
* Creates a new cBio Portal API client
*
* @example
*
* Basic usage:
*
* ```javascript
* import CbioPortal from 'cbioportal-api-client';
*
* const cbioPortal = CbioPortal();
*
* cbioPortal.getCancerStudies()
* .then(response => {
* console.log(response); // Prints array of cancer studies returned from API
* });
* ```
*
* @module cbioportal-api-client
* @see {@link module:cbioportal-api-client~cbioPortal|cbioPortal}
* @param {Object} config Configuration options object.
* @param {Object} config.requestOpts Override the request congfiguration object.
* @returns {cbioPortal}
*/
function CbioPortal ({ requestOpts = false } = {}) {
return Object.assign(Object.create(cbioPortal), {
requestOpts: _defaults(requestOpts, {
headers: {
'User-Agent': 'cbioportal-api-client.js/0.0.1'
},
uri: 'http://www.cbioportal.org/webservice.do'
})
});
}

export default CbioPortal;
4 changes: 3 additions & 1 deletion lib/utils/convertResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Promise from 'bluebird';
import CsvParser from 'csv-parser';
import _map from 'lodash/map';
import _transform from 'lodash/transform';
import { Readable } from 'stream';
import { canUseDom } from 'fbjs/lib/ExecutionEnvironment';

const Readable = canUseDom ? require('stream-browserify').Readable : require('stream').Readable;

const copyNumberRegexp = /^.*#.*(?:COPY_NUMBER_ALTERATION)\n/mg;
const mutationRegexp = /^.*#.*(?:MUTATION_EXTENDED)\n/mg;
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"cbioportal-api-client": "./bin/cbioportal-api-client"
},
"scripts": {
"build": "npm run docs && npm run clean:dist && babel lib -d dist",
"build:dev": "nodemon -w lib --exec \"npm run docs && npm run clean:dist && babel lib -d dist\"",
"build": "npm run clean:dist && babel lib -d dist",
"build:dev": "nodemon -w lib --exec \"npm run clean:dist && babel lib -d dist\"",
"clean": "npm run clean:dist && npm run clean:coverage",
"clean:dist": "rimraf dist",
"clean:coverage": "rimraf coverage",
Expand Down Expand Up @@ -62,8 +62,10 @@
"commander": "^2.9.0",
"continuation-local-storage": "^3.1.4",
"csv-parser": "^1.9.2",
"fbjs": "^0.7.0",
"in-publish": "^2.0.0",
"lodash": "^4.0.0",
"request-promise": "^2.0.0"
"request-promise": "^2.0.0",
"stream-browserify": "^2.0.1"
}
}

0 comments on commit c669c50

Please sign in to comment.