Skip to content

Commit

Permalink
Update with most recent pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
logmosier committed Apr 3, 2018
2 parents 9b364cc + 11622cc commit 8709caf
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 109 deletions.
1 change: 0 additions & 1 deletion src/client/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const databases = [
['3DMET', 'http://identifiers.org/3dmet/', ''],
['Chemical Component Dictionary', 'http://identifiers.org/pdb-ccd/', ''],
['CAS', 'http://identifiers.org/cas/', ''],
['Pathway Commons','/view?uri=http://pathwaycommons.org/pc2/',''],
['HPRD',' http://identifiers.org/hprd/',''],
['RefSeq',' http://identifiers.org/refseq/',''],
['NCBI Gene','http://identifiers.org/ncbigene/',''],
Expand Down
34 changes: 20 additions & 14 deletions src/client/common/cy/tooltips/format-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const h = require('hyperscript');
const classNames = require('classnames');
const _ = require('lodash');
const config = require('../../config');
const queryString = require('query-string');

//Handle standard name related metadata fields
const standardNameHandler = (pair) => makeTooltipItem(pair[1], 'Name: ');
Expand Down Expand Up @@ -41,17 +42,17 @@ const databaseHandler = (pair, expansionFunction) => {
};

//Handle interaction/Detailed views related fields
const interactionHandlerTrim =(pair, expansionFunction) => {
const interactionHandlerTrim =(pair, expansionFunction, title) => {
let maxViews=8;
const expansionLink = pair[1].length>maxViews? h('div.more-link', { onclick: () => expansionFunction(pair[0]) }, 'more »'):'';
if (pair[1].length < 1) { return h('div.error'); }
return generateDetailedViewList(sortByDatabaseId(pair[1]), pair[1].length>maxViews, expansionLink,maxViews);
return generateDetailedViewList(sortByDatabaseId(pair[1]), pair[1].length>maxViews, expansionLink,maxViews,title);
};
const interactionHandler =(pair, expansionFunction) => {
const interactionHandler =(pair, expansionFunction, title) => {
let maxViews=8;
const expansionLink = pair[1].length>maxViews? h('div.more-link', { onclick: () => expansionFunction(pair[0]) }, '« less'):'';
if (pair[1].length < 1) { return h('div.error'); }
return generateDetailedViewList(sortByDatabaseId(pair[1]),false, expansionLink,maxViews);
return generateDetailedViewList(sortByDatabaseId(pair[1]),false, expansionLink,maxViews,title);
};

//Handle publication related fields
Expand Down Expand Up @@ -103,7 +104,7 @@ const metaDataKeyMap = new Map()
* Sample Input : parseMetadata(['Standard Name', 'TP53'])
* Sample Output : <div class='fake-paragraph'><div class='field-name'></div></div>
*/
function parseMetadata(pair, trim = true, expansionFunction) {
function parseMetadata(pair, trim = true, expansionFunction, title) {
const doNotRender = ['Data Source', 'Data SourceTrim', 'Display Name'];
let key = pair[0];

Expand All @@ -114,7 +115,7 @@ function parseMetadata(pair, trim = true, expansionFunction) {

let handler = metaDataKeyMap.get(key);
if (handler) {
return handler(pair, expansionFunction);
return handler(pair, expansionFunction, title);
}
else if (!(trim) && !doNotRender.includes(key)) {
return defaultHandler(pair);
Expand Down Expand Up @@ -294,7 +295,7 @@ function generateIdList(dbIdObject, trim) {
* Sample Input : generateDBLink('Reactome', 'R-HSA-59544', true)
* Sample Output : <div class="fake-spacer"><a class="db-link-single-ref" href="http://identifiers.org/reactome/R-HSA-59544" target="_blank">Reactome</a></div>
*/
function generateDBLink(dbName, dbId, isDbVisible, otherName) {
function generateDBLink(dbName, dbId, isDbVisible) {
//Get base url for dbid
let db = config.databases;
let className = '';
Expand All @@ -307,7 +308,7 @@ function generateDBLink(dbName, dbId, isDbVisible, otherName) {
if (isDbVisible) {
className = '-single-ref';
}
let label = otherName ? otherName :(isDbVisible ? dbName :dbId);
let label = isDbVisible ? dbName :dbId;

//Build reference url
if (link.length === 1 && link[0][1]) {
Expand Down Expand Up @@ -430,17 +431,22 @@ function generateDatabaseList(sortedArray, trim, expansionLink) {
//Generate list
let renderValue = sortedArray.map(item => [generateIdList(item, trim)], this);

return formatRenderValue(sortedArray,renderValue,expansionLink,trim,true,'Links');
return formatRenderValue(sortedArray, renderValue, expansionLink, trim, true, 'Links');
}

function generateDetailedViewList(sortedArray, trim, expansionLink,maxViews) {
let name = sortedArray[0].database;
function generateDetailedViewList(sortedArray, trim, expansionLink, maxViews, title) {
let list = sortedArray[0].ids;
if(trim){list=list.slice(0,maxViews);}
//Generate list
let renderValue = list.map((data,index) => [generateDBLink(name, data, true,'Interaction '+(index+1))],this);

return formatRenderValue(sortedArray,renderValue,expansionLink,trim,false,'Detailed Views');
let renderValue = list.map((data,index) => [h('div.fake-spacer',
h('a.db-link' ,{
href:'/view?',
search: queryString.stringify({uri:'http://pathwaycommons.org/pc2/'+data, title:title, removeInfoMenu:true}),
target: '_blank',
}, 'Interaction '+(index+1))
)]);

return formatRenderValue(sortedArray, renderValue, expansionLink, trim, false, 'Detailed Views');
}

function formatRenderValue(sortedArray, renderValue, expansionLink, trim, list,name){
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/cy/tooltips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MetadataTip {
if (!(this.data)) { this.data = []; }
return h('div.tooltip-image', [
h('div.tooltip-heading', this.name),
h('div.tooltip-internal', h('div', (data).map(item => formatContent.parseMetadata(item, true, expandFunction)), this))
h('div.tooltip-internal', h('div', (data).map(item => formatContent.parseMetadata(item, true, expandFunction, this.name)), this))
]);
}

Expand All @@ -111,7 +111,7 @@ class MetadataTip {
if (!(this.data)) { this.data = []; }
return h('div.tooltip-image', [
h('div.tooltip-heading', this.name),
h('div.tooltip-internal', h('div', (data).map(item => formatContent.parseMetadata(item, !this.isExpanded(item[0]), getExpansionFunction(item)), this)))
h('div.tooltip-internal', h('div', (data).map(item => formatContent.parseMetadata(item, !this.isExpanded(item[0]), getExpansionFunction(item), this.name), this)))
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/features/interactions/filter-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InteractionsFilterMenu extends React.Component {
[
h('div',{className:classNames(type,'interaction-filter-legend')}),
h('h3.button-label',type),
h('i', {className: classNames('common-icon-button','material-icons',{ 'common-icon-button-active': !clicked})}, clicked ? 'close':'check')
h('i', {className: classNames('common-icon-button','material-icons','icon-cutoff',{ 'common-icon-button-active': !clicked})}, clicked ? 'close':'check')
]
));
return h('div',[
Expand Down
1 change: 0 additions & 1 deletion src/client/features/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Search extends React.Component {
genes: state.query.q.trim(),
target: 'UNIPROT',
};

this.setState({
landingLoading: true
});
Expand Down
9 changes: 7 additions & 2 deletions src/client/features/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ class View extends React.Component {

ServerAPI.getGraphAndLayout(query.uri, 'latest').then(networkJSON => {
const layoutConfig = getLayoutConfig(networkJSON.layout);
const componentConfig = _.merge({}, BaseNetworkView.config, { useSearchBar: true});
if(query.removeInfoMenu){
BaseNetworkView.config.toolbarButtons.splice(
_.findIndex(BaseNetworkView.config.toolbarButtons, entry=>entry.id==='showInfo'),1
);
}

const componentConfig = _.merge({},BaseNetworkView.config, { useSearchBar: true});
this.setState({
componentConfig: componentConfig,
layoutConfig: layoutConfig,
networkJSON: networkJSON.graph,
networkMetadata: {
uri: query.uri,
name: _.get(networkJSON, 'graph.pathwayMetadata.title.0', 'Unknown Network'),
name: query.title || _.get(networkJSON, 'graph.pathwayMetadata.title.0', 'Unknown Network'),
datasource: _.get(networkJSON, 'graph.pathwayMetadata.dataSource.0', 'Unknown Data Source'),
comments: networkJSON.graph.pathwayMetadata.comments,
organism: networkJSON.graph.pathwayMetadata.organism
Expand Down
4 changes: 0 additions & 4 deletions src/client/services/server-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ const ServerAPI = {
return fetch(`/api/gene-query?${qs.stringify(query)}`, defaultFetchOpts).then(res => res.json());
},

findUniprotId(query){
return fetch(`/pc-client/uniprotIdSearch?${qs.stringify(query)}`, defaultFetchOpts).then(res => res.json());
},

getProteinInformation(uniprotId){
return fetch(`https://www.ebi.ac.uk/proteins/api/proteins?offset=0&accession=${uniprotId}`,defaultFetchOpts).then(res => res.json());
},
Expand Down
32 changes: 25 additions & 7 deletions src/server/enrichment-map/emap/generateGraphInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,30 @@ const _ = require('lodash');

// input ["GO:1902275", "GO:2001252", "GO:1905269", "GO:0051053"]
// returns a cytoscape object
const generateGraphInfo = (pathwayIdList) => {
const generateGraphInfo = (pathwayIdList, cutoff = 0.375, JCWeight, OCWeight) => {
if (cutoff < 0 || cutoff > 1) { throw new Error('ERROR: cutoff out of range [0, 1]');}
if (isNaN(Number(cutoff))) { throw new Error('ERROR: cutoff is not a number'); }

if (JCWeight < 0 || JCWeight > 1) {
throw new Error('ERROR: JCWeight out of range [0, 1]');
}
if (OCWeight < 0 || OCWeight > 1) {
throw new Error('ERROR: OCWeight out of range [0, 1]');
}
if (JCWeight != undefined && isNaN(Number(JCWeight))) {throw new Error('ERROR: JCWeight should be a number');}
if (OCWeight != undefined && isNaN(Number(OCWeight))) {throw new Error('ERROR: OCWeight should be a number');}
if (OCWeight != undefined && JCWeight != undefined && Number(OCWeight) + Number(JCWeight) != 1) {
throw new Error('ERROR: OCWeight + JCWeight should be 1');
}
if (JCWeight === undefined && OCWeight === undefined) {
JCWeight = 0.5;
OCWeight = 0.5;
} else if (JCWeight === undefined) {
JCWeight = 1 - OCWeight;
} else if (OCWeight === undefined) {
OCWeight = 1 - JCWeight;
}

// check unrecognized and duplicates, modify pathwayIdList
const unrecognized = [];
for (let i = 0; i < pathwayIdList.length; ++i) {
Expand Down Expand Up @@ -48,7 +71,7 @@ const generateGraphInfo = (pathwayIdList) => {
_.forEach(nodeInfo, node => {
elements.push({ data: { id: node.pathwayId } });
});
const edgeInfo = generateEdgeInfo(pathwayIdList);
const edgeInfo = generateEdgeInfo(pathwayIdList, JCWeight, cutoff);
_.forEach(edgeInfo, edge => {
const sourceIndex = 0;
const targetIndex = 1;
Expand All @@ -71,8 +94,3 @@ const generateGraphInfo = (pathwayIdList) => {


module.exports = { generateGraphInfo };

//simple testing
//console.log(generateGraphInfo(["GO:1902275", "GO:2001252", "GO:1905269"]));
// const result = generateGraphInfo(["GO:1902275", "GO:2001252", "GO:1905269"]);
// console.log(JSON.stringify(result));
4 changes: 2 additions & 2 deletions src/server/enrichment-map/emap/generateInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const fetchPathwayInfo = (pathwayList) => {
// {edgeId: "GO:1902275_GO:0051053", intersection: [gene1], similarity: 0.1},
// {edgeId: "GO:2001252_GO:0051053", intersection: [gene1], similarity: 0.1}]
// cutoff = 0.375 unless specified
const generateEdgeInfo = (pathwayIdList, cutoff = 0.375) => {
return filterEdges(pathwayListGraph(fetchPathwayInfo(pathwayIdList)), cutoff);
const generateEdgeInfo = (pathwayIdList, JCWeight, cutoff = 0.375) => {
return filterEdges(pathwayListGraph(fetchPathwayInfo(pathwayIdList), JCWeight), cutoff);
};


Expand Down
8 changes: 4 additions & 4 deletions src/server/enrichment-map/emap/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const _ = require('lodash');
// JC/OC calculation
// output: JSON object
// {edgeId: pathwayxyz_pathwayabc, intersection: [gene1, gene3], similarity: 0.6}
const pathwayPairGraph = (pathway1, pathway2) => {
const pathwayPairGraph = (pathway1, pathway2, JCWeight) => {
let intersectionCount = 0;
const intersection = [];
_.forEach(pathway1.genes, gene => {
Expand All @@ -18,7 +18,7 @@ const pathwayPairGraph = (pathway1, pathway2) => {
}
});
// JC/OC calculation
const similarity = 0.5*(intersectionCount/(pathway1.genes.length+pathway2.genes.length-intersectionCount))+0.5*(intersectionCount/Math.min(pathway1.genes.length, pathway2.genes.length));
const similarity = JCWeight*(intersectionCount/(pathway1.genes.length+pathway2.genes.length-intersectionCount))+(1-JCWeight)*(intersectionCount/Math.min(pathway1.genes.length, pathway2.genes.length));
return {edgeId: pathway1.pathwayId+'_'+pathway2.pathwayId, intersection: intersection, similarity: similarity};
};

Expand All @@ -35,11 +35,11 @@ const pathwayPairGraph = (pathway1, pathway2) => {
// {edgeId: "pathway2_pathway3", intersection: [], similarity: 0.1},
// {edgeId: "pathway2_pathway4", intersection: [], similarity: 0.1},
// {edgeId: "pathway3_pathway4", intersection: [gene1], similarity: 0.1}]
const pathwayListGraph = (pathwayList) => {
const pathwayListGraph = (pathwayList, JCWeight) => {
const ret = [];
for (let i = 0; i < pathwayList.length; ++i) {
for (let j = i + 1; j < pathwayList.length; ++j) {
ret.push(pathwayPairGraph(pathwayList[i], pathwayList[j]));
ret.push(pathwayPairGraph(pathwayList[i], pathwayList[j], JCWeight));
}
}
return ret;
Expand Down
21 changes: 11 additions & 10 deletions src/server/enrichment-map/enrichment/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const defaultSetting = {
"threshold_algo": "fdr",
"domain_size_type": "annotated",
"custbg": [],
"custbg_cb": 0,
"sf_GO:BP": 1,
"sf_REAC": 1,
};
Expand All @@ -55,24 +54,26 @@ const enrichment = (query, userSetting) => {
const minSetSizeVal = Number(formData.min_set_size);
const maxSetSizeVal = Number(formData.max_set_size);
const thresholdAlgoVal = formData.threshold_algo;
const custbgCbVal = Number(formData.custbg_cb);
if (orderedQueryVal != 0 && orderedQueryVal != 1) {
throw new Error('ERROR: orderedQuery should be 1 or 0');
reject(new Error('ERROR: orderedQuery should be 1 or 0'));
}
if (isNaN(userThrVal) || userThrVal > 1 || userThrVal < 0) {
throw new Error('ERROR: userThrVal should be a number [0, 1]')
reject(new Error('ERROR: userThrVal should be a number [0, 1]'));
}
if (isNaN(minSetSizeVal)) {
throw new Error('ERROR: minSetSize should be a number')
reject(new Error('ERROR: minSetSize should be a number'));
}
if (minSetSizeVal < 0) {
reject(new Error('ERROR: minSetSize should be >= 0'));
}
if (isNaN(maxSetSizeVal)) {
throw new Error('ERROR: maxSetSize should be a number');
reject(new Error('ERROR: maxSetSize should be a number'));
}
if (thresholdAlgoVal != 'analytical' && thresholdAlgoVal != 'bonferroni' && thresholdAlgoVal != 'fdr') {
throw new Error('ERROR: thresholdAlgoVal should be one of analytical, bonferroni, fdr');
if (maxSetSizeVal < minSetSizeVal) {
reject(new Error('ERROR: maxSetSize should be >= minSetSize'));
}
if (custbgCbVal != 0 && custbgCbVal != 1) {
throw new Error('ERROR: custbgCb should be 1 or 0')
if (thresholdAlgoVal != 'analytical' && thresholdAlgoVal != 'bonferroni' && thresholdAlgoVal != 'fdr') {
reject(new Error('ERROR: thresholdAlgoVal should be one of analytical, bonferroni, fdr'));
}

request.post({ url: gProfilerURL, formData: formData }, (err, httpResponse, gProfilerResponse) => {
Expand Down
5 changes: 3 additions & 2 deletions src/server/enrichment-map/gene-validator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const validatorGconvert = (query, userOptions) => {
const promise = new Promise((resolve, reject) => {
const formData = _.assign({}, defaultOptions, userOptions, { query: query });
formData.organism = formData.organism.toLowerCase();
formData.target = convertGConvertNames(formData.target.toUpperCase());
const initialTarget = formData.target.toUpperCase();
formData.target = convertGConvertNames(initialTarget);
const invalidInfo = {invalidTarget: '', invalidOrganism: ''};
if (!validOrganism.includes(formData.organism)) {
invalidInfo.invalidOrganism = formData.organism;
Expand Down Expand Up @@ -79,7 +80,7 @@ const validatorGconvert = (query, userOptions) => {
}
});

const ret = { options: {target: formData.target, organism: formData.organism}, unrecognized: unrecognized, duplicate: duplicate, geneInfo: geneInfo };
const ret = { options: {target: initialTarget, organism: formData.organism}, unrecognized: unrecognized, duplicate: duplicate, geneInfo: geneInfo };
resolve(ret);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/enrichment-map/gene-validator/validityInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ const validOrganism = ['aaegypti',
'vvinifera',
'zmays'];

const validTarget = ['ENSG', 'HGNC', 'HGNC_ACC', 'UNIPROTSWISSPROT', 'ENTREZGENE', 'ENTREZGENE_ACC'];
const validTarget = ['ENSG', 'HGNC', 'HGNC_ACC', 'UNIPROTSWISSPROT', 'ENTREZGENE_ACC'];

module.exports = {validOrganism, validTarget};
1 change: 0 additions & 1 deletion src/server/pathway-commons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const PathwayCommonsService = {
};

PathwayCommonsService.querySearch = _.memoize(search.querySearch, query => JSON.stringify(query));
PathwayCommonsService.uniprotIdSearch = _.memoize(search.uniprotIdSearch, query => JSON.stringify(query));
PathwayCommonsService.datasources = _.memoize(datasources);

// expose core cpath2 client api
Expand Down
21 changes: 1 addition & 20 deletions src/server/pathway-commons/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,4 @@ const querySearch = async (query) => {
return [];
};

const uniprotIdSearch = async (query) => {
const queries = await (processPhrase(sanitize(query.q.trim())));
const filteredQueries = queries.filter(entry=>entry.includes('xrefid'));
if(!_.isEmpty(filteredQueries)){
const searchResult = await search()
.query(query) //input query string
.q(filteredQueries)
.format('json')
.fetch();
const searchSuccess = searchResult != null
if (searchSuccess && searchResult.searchHit.length > 0) {
const filteredResults = searchResult.searchHit.filter(hit =>
hit.uri.startsWith('http://identifiers.org/uniprot/')
);
return filteredResults.map(hit=>_.last(hit.uri.split('/'))); //Parses and returns the Uniprot id
}
}
return [];
};
module.exports = {querySearch:querySearch,uniprotIdSearch:uniprotIdSearch};
module.exports = {querySearch};
4 changes: 0 additions & 4 deletions src/server/routes/pc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ router.get('/querySearch', function (req, res) {
pc.querySearch(req.query).then(r => res.json(r));
});

router.get('/uniprotIdSearch',function (req, res) {
pc.uniprotIdSearch(req.query).then(r => res.json(r));
});

router.get('/:path', function (req, res) {
res.redirect('http://www.pathwaycommons.org/pc2/' + req.params.path + '?' + qs.stringify(req.query));
});
Expand Down
Loading

0 comments on commit 8709caf

Please sign in to comment.