Skip to content

Commit

Permalink
Added alteration summary shortcut command to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarks committed Jan 24, 2016
1 parent f4fd1eb commit e03d648
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 74 deletions.
73 changes: 15 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ $ cbioportal-api-client --help

Commands:

getCancerStudies get cancer study meta-data
getTypesOfCancer get clinical cancer types
getGeneticProfiles [options] get genetic profile data for a cancer study.
getCaseLists [options] get case lists stored for a specific cancer study.
getProfileData [options] get genomic profile data for one or more genes.
getCancerStudies get cancer study meta-data
getTypesOfCancer get clinical cancer types
getGeneticProfiles [options] get genetic profile data for a cancer study.
getCaseLists [options] get case lists stored for a specific cancer study.
getProfileData [options] get genomic profile data for one or more genes.
getAlterationSummary [options] summarize alterations for the profile data.

You can get usage info for specific commands using [command] --help

Expand All @@ -65,11 +66,16 @@ $ cbioportal-api-client --help

# example API call, sends JSON formatted response to stdout
$ cbioportal-api-client getProfileData -s gbm_tcga_cnaseq -p gbm_tcga_mutations -g TP53
# .... cut long JSON response

# summarizing alterations
$ cbioportal-api-client getAlterationSummary -s gbm_tcga_cnaseq -p gbm_tcga_mutations,gbm_tcga_gistic -g TP53,MDM2,MDM4
{"summary":{"genes":{"mdm2":{"mutated":1,"cna":9,"combined":10},"mdm4":{"mutated":0,"cna":10,"combined":10},"tp53":{"mutated":29,"cna":2,"combined":30}},"overall":47}}
```
---
## API Reference
# API Reference
## Modules
Expand All @@ -80,19 +86,8 @@ $ cbioportal-api-client getProfileData -s gbm_tcga_cnaseq -p gbm_tcga_mutations
<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>
<dt><a href="#module_cbioportal-api-client/utils/summarizeAlterations">cbioportal-api-client/utils/summarizeAlterations</a></dt>
<dd><p>Exports utility functions for summarizing gene alterations</p>
</dd>
</dl>
## Functions
<dl>
<dt><a href="#parseResponseMeta">parseResponseMeta(response, cmd)</a><code>Object</code></dt>
<dd><p>Prepare response meta for the converted JSON</p>
</dd>
<dt><a href="#maybeTransformArray">maybeTransformArray(n)</a><code>string</code></dt>
<dd><p>Transform an array to CSV</p>
<dt><a href="#module_cbioportal-api-client/utils/summarizeAlterations">cbioportal-api-client/utils/summarizeAlterations</a><code>Promise</code></dt>
<dd><p>Summarizes alterations for results</p>
</dd>
</dl>
Expand Down Expand Up @@ -239,17 +234,9 @@ Converts tab delimited responses to JSON format
-----
<a name="module_cbioportal-api-client/utils/summarizeAlterations"></a>
## cbioportal-api-client/utils/summarizeAlterations
Exports utility functions for summarizing gene alterations
-----
<a name="exp_module_cbioportal-api-client/utils/summarizeAlterations--module.exports"></a>
### module.exports(dataSets) ⇒ <code>Promise</code>
## cbioportal-api-client/utils/summarizeAlterations ⇒ <code>Promise</code>
Summarizes alterations for results
**Kind**: Exported function
**Returns**: <code>Promise</code> - Resolves with the summary
**Fulfills**: <code>Object</code> Object with results, see example
Expand All @@ -272,37 +259,7 @@ Example response object:
}
}
}
```
-----
<a name="parseResponseMeta"></a>
## parseResponseMeta(response, cmd) ⇒ <code>Object</code>
Prepare response meta for the converted JSON
**Kind**: global function
**Returns**: <code>Object</code> - Object with response meta and row meta
| Param | Type | Description |
| --- | --- | --- |
| response | <code>string</code> | Raw response from the server |
| cmd | <code>string</code> | API command |
-----
<a name="maybeTransformArray"></a>
## maybeTransformArray(n) ⇒ <code>string</code>
Transform an array to CSV
**Kind**: global function
| Param | Type |
| --- | --- |
| n | <code>mixed</code> |
-----
18 changes: 12 additions & 6 deletions docs/README.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ $ cbioportal-api-client --help

Commands:

getCancerStudies get cancer study meta-data
getTypesOfCancer get clinical cancer types
getGeneticProfiles [options] get genetic profile data for a cancer study.
getCaseLists [options] get case lists stored for a specific cancer study.
getProfileData [options] get genomic profile data for one or more genes.
getCancerStudies get cancer study meta-data
getTypesOfCancer get clinical cancer types
getGeneticProfiles [options] get genetic profile data for a cancer study.
getCaseLists [options] get case lists stored for a specific cancer study.
getProfileData [options] get genomic profile data for one or more genes.
getAlterationSummary [options] summarize alterations for the profile data.

You can get usage info for specific commands using [command] --help

Expand All @@ -65,10 +66,15 @@ $ cbioportal-api-client --help

# example API call, sends JSON formatted response to stdout
$ cbioportal-api-client getProfileData -s gbm_tcga_cnaseq -p gbm_tcga_mutations -g TP53
# .... cut long JSON response

# summarizing alterations
$ cbioportal-api-client getAlterationSummary -s gbm_tcga_cnaseq -p gbm_tcga_mutations,gbm_tcga_gistic -g TP53,MDM2,MDM4
{"summary":{"genes":{"mdm2":{"mutated":1,"cna":9,"combined":10},"mdm4":{"mutated":0,"cna":10,"combined":10},"tp53":{"mutated":29,"cna":2,"combined":30}},"overall":47}}
```

---
## API Reference
# API Reference
{{>main}}
16 changes: 15 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function apiRequest (cmd, query) {

return cbioPortal[cmd](query)
.then(response => {
process.stdout.write(JSON.stringify(response));
process.stdout.write(JSON.stringify(response) + '\n');
process.exit(0);
});
}
Expand Down Expand Up @@ -65,4 +65,18 @@ Program
gene_list: options.geneList
}));

Program
.command('getAlterationSummary')
.option('-s, --case-set <case_set_id>', 'specify the case list ID (required)')
.option('-p, --genetic-profile <genetic_profile_id>', 'One or more genetic profile IDs (required, separated by comma if more than one)')
.option('-g, --gene-list <gene_list>', 'One or more genes, specified as HUGO Gene Symbols or Entrez Gene IDs (required)')
.description('summarize alterations for the profile data.')
.action(options => apiRequest('getAlterationSummary', {
case_set_id: options.caseSet,
genetic_profile_id: options.geneticProfile,
gene_list: options.geneList
}));

Program.parse(process.argv);

if (!Program.args.length) Program.help();
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import _reduce from 'lodash/reduce';
import _defaults from 'lodash/defaults';
import {
convertResponse,
formatQuery
formatQuery,
summarizeAlterations
} from './utils';

/**
Expand Down Expand Up @@ -138,6 +139,11 @@ const cbioPortal = {
}

return this.get('ProfileData', { case_set_id, genetic_profile_id, gene_list });
},

getAlterationSummary ({ case_set_id, genetic_profile_id, gene_list }) {
return this.getProfileData({ case_set_id, genetic_profile_id, gene_list })
.then(results => summarizeAlterations(results));
}

};
Expand Down
1 change: 1 addition & 0 deletions lib/utils/convertResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function isPatient (string) {
/**
* Prepare response meta for the converted JSON
*
* @private
* @param {string} response Raw response from the server
* @param {string} cmd API command
* @return {Object} Object with response meta and row meta
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/formatQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _transform from 'lodash/transform';
/**
* Transform an array to CSV
*
* @private
* @param {mixed} n
* @return {string}
*/
Expand All @@ -16,6 +17,7 @@ function maybeTransformArray (n) {

/**
* Formats query params
* @private
*/
export default function convertResponse (query) {

Expand Down
10 changes: 2 additions & 8 deletions lib/utils/summarizeAlterations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import _flatten from 'lodash/flatten';
import _transform from 'lodash/transform';
import _flattenDeep from 'lodash/flattenDeep';

/**
* Exports utility functions for summarizing gene alterations
*
* @module cbioportal-api-client/utils/summarizeAlterations
*/

/**
* Reduce case ID iterator
*
Expand Down Expand Up @@ -113,9 +107,9 @@ function summarizeCopyNumberAlterations (cases = []) {
* }
* }
* }
*
*
* ```
*
* @module cbioportal-api-client/utils/summarizeAlterations
* @param {...Object|Array} dataSets Converted response dataset(s)
* @return {Promise} Resolves with the summary
* @fulfills {Object} Object with results, see example
Expand Down
61 changes: 61 additions & 0 deletions test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,64 @@ Test('getProfileData() - multiple genes AND multiple profiles', t => {
t.deepEquals(types.sort(), ['mutation_extended', 'copy_number_alteration'].sort());
});
});

Test('getAlterationSummary()', t => {

Nock('http://www.cbioportal.org')
.get('/webservice.do')
.query({
cmd: 'getProfileData',
case_set_id: 'gbm_tcga_cnaseq',
genetic_profile_id: 'gbm_tcga_mutations',
gene_list: 'tp53,mdm2,mdm4'
})
.replyWithFile(
200,
__dirname + '/data/gbm_tcga_mutations-tp53-mdm2-mdm4.tsv'
);

Nock('http://www.cbioportal.org')
.get('/webservice.do')
.query({
cmd: 'getProfileData',
case_set_id: 'gbm_tcga_cnaseq',
genetic_profile_id: 'gbm_tcga_gistic',
gene_list: 'tp53,mdm2,mdm4'
})
.replyWithFile(
200,
__dirname + '/data/gbm_tcga_gistic-tp53-mdm2-mdm4.tsv'
);

return cbioPortal.getAlterationSummary({
case_set_id: 'gbm_tcga_cnaseq',
genetic_profile_id: ['gbm_tcga_mutations', 'gbm_tcga_gistic'],
gene_list: ['tp53', 'mdm2', 'mdm4']
})
.then(result => {
t.deepEquals(result, {
summary: {
genes: {
tp53: {
mutated: 29,
cna: 2,
combined: 30
},
mdm2: {
mutated: 1,
cna: 9,
combined: 10
},
mdm4: {
mutated: 0,
cna: 10,
combined: 10
}
},
overall: 47
}
});

return true;
});
});

0 comments on commit e03d648

Please sign in to comment.