Skip to content

Commit

Permalink
Merge pull request #17 from KeithKelleher/main
Browse files Browse the repository at this point in the history
framework updates
  • Loading branch information
KeithKelleher authored Sep 20, 2024
2 parents b280c65 + 007ca95 commit e35e280
Show file tree
Hide file tree
Showing 8 changed files with 859 additions and 253 deletions.
7 changes: 7 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import express, {Application, Request, Response} from 'express';
import {ping, sample} from "./models/endpoints";
// @ts-ignore
import {predictions} from "./data_sources/kinase-cancer-predictions/index"
import {interactorScores} from "./data_sources/pairwise-relationship-data";
import {coexpressionData} from "./data_sources/coexpression-data";

const app: Application = express()

const port: number = 3001
Expand All @@ -13,6 +16,10 @@ app.get("/sample?*", (req: Request, res: Response) => sample(req, res));

app.get("/predictions?*", (req: Request, res: Response) => predictions(req, res));

app.get("/interactorScores?*", (req: Request, res: Response) => interactorScores(req, res));

app.get("/coexpressionData?*", (req: Request, res: Response) => coexpressionData(req, res));

app.listen(port, function () {
console.log(`App is listening on port ${port} !`)
});
109 changes: 109 additions & 0 deletions data_sources/coexpression-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {Request, Response} from "express";
import {setHeaders} from "../../models/endpoints";
import url from "url";
import querystring from "querystring";
import PairwiseService from "../pairwise-relationship-data/pairwiseService";
import {PredictionSet} from "../../models/prediction";
import {getMinimalCitation} from "../../models/modelData";

function formatCancerSpecificData(data: any) {
const ps = new PredictionSet("Cancer Specific Coexpression", "Protein", "",
"", 1, 0, null, "Coexpressed Target",
["Data Source", "Cancer Type", "Coexpressed Target"]);
Object.entries(data).forEach((match: any) => {
{
match = match[1];
let dataSource = match.dataDesc.id.split("|")[0];
let cancerType = match.dataDesc.id.split("|")[1];
if (match && match.posGenes) {
match.posGenes.forEach((gene: any) => {
const extraFields: any =
{
identifier: [
{
"@type": "PropertyValue",
"name": "Data Source",
"value": dataSource
},
{
"@type": "PropertyValue",
"name": "Cancer Type",
"value": cancerType
}
],
};
ps.addPrediction(gene, "", null, extraFields);
});
}
}
})
return ps;
}

function formatTissueSpecificData(data: any) {
const ps = new PredictionSet("Tissue Specific Coexpression", "Protein", "",
"", 1, 0, null, "Coexpressed Target",
["Data Source", "Tissue", "Coexpressed Target"]);
Object.entries(data).forEach((match: any) => {
{
match = match[1];
let dataSource = match.dataDesc.id.split("|")[0];
let tissue = match.dataDesc.id.split("|")[1];
if (match && match.posGenes) {
match.posGenes.forEach((gene: any) => {
const extraFields: any =
{
identifier: [
{
"@type": "PropertyValue",
"name": "Data Source",
"value": dataSource
}, {
"@type": "PropertyValue",
"name": "Tissue",
"value": tissue
}],
};
ps.addPrediction(gene, "", null, extraFields);
})
}
}
})
ps.addCitation(getMinimalCitation(37333417));
return ps;
}

export async function coexpressionData(req: Request, res: Response): Promise<any>{
setHeaders(res);
const parsedUrl = url.parse(req.url);
const queryMap = querystring.parse(parsedUrl.query);
if (queryMap.target) {
const targetQuery = queryMap.target.toString();
const csDataDescriptions: any = PairwiseService.getAllDataDescs('TCGA', 'Gene_Coexpression');
const tsDataDescriptions: any = PairwiseService.getAllDataDescs('GTEx', 'Gene_Coexpression');

return Promise.all([csDataDescriptions, tsDataDescriptions]).then((dataDescriptionResults: any[]) => {
const csDataDescIds = dataDescriptionResults[0].map((o: any) => Object(o.id));
const tsDataDescIds = dataDescriptionResults[1].map((o: any) => Object(o.id));

const csPairwiseSearch = PairwiseService.searchTermSecondaryPathways(
{
"genes": [targetQuery],
"dataDescs": csDataDescIds
});
const tsPairwiseSearch = PairwiseService.searchTermSecondaryPathways(
{
"genes": [targetQuery],
"dataDescs": tsDataDescIds
});
return Promise.all([csPairwiseSearch, tsPairwiseSearch]).then((pwSearchResults: any[]) => {
const csPs = formatCancerSpecificData(pwSearchResults[0]);
const tsPs = formatTissueSpecificData(pwSearchResults[1]);
res.end(JSON.stringify([tsPs.asJSON(), csPs.asJSON()]));
})
});
}
res.end("No Protein Provided!");
}

exports.coexpressionData = coexpressionData;
40 changes: 40 additions & 0 deletions data_sources/pairwise-relationship-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Request, Response} from "express";
import {setHeaders} from "../../models/endpoints";
import querystring from "querystring";
import PairwiseService from "./pairwiseService";
import url from "url";
import {PredictionSet} from "../../models/prediction";
import {getMinimalCitation} from "../../models/modelData";

export async function interactorScores(req: Request, res: Response): Promise<any> {
setHeaders(res);
const parsedUrl = url.parse(req.url);
const queryMap = querystring.parse(parsedUrl.query);

if (queryMap.target) {
const targetQuery = queryMap.target.toString();
const score = +queryMap.score || 0.5;
try {
await PairwiseService.getInteractorScoresForTerm(targetQuery, score)
.then(data => {
const ps = new PredictionSet("Reactome Functional Interactions (FIs)", "Protein", "FI Score",
"Score of how likely two proteins are to interact with each other functionally",
1, 0, null, "FI Partner");
Object.entries(data).forEach((intScore: any) => {
{
intScore = intScore[1]
ps.addPrediction(intScore.gene, "", intScore.score);
}
})
ps.addCitation(getMinimalCitation(37333417));
res.end(JSON.stringify([ps.asJSON()]))
});
return;
} catch (err) {
console.error(err);
}
}
res.end("No Protein Provided!");
}

exports.interactorScores = interactorScores;
53 changes: 53 additions & 0 deletions data_sources/pairwise-relationship-data/pairwiseService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import axios from "axios";

class PairwiseService {
static getInteractorScoresForTerm(term: string, cutoff: number) {
return new Promise((resolve, reject) => {
axios
.get(`https://idg.reactome.org/idgpairwise/relationships/combinedScoreGenesForTerm/${term}`)
.then((res) => {
resolve(
Object.entries(res.data).map(([gene, score]) => ({
gene: gene,
score: score,
// @ts-ignore
})).filter(({score}) => score >= cutoff)
);
})
.catch((err) => {
reject(err);
});
});
}

static searchTermSecondaryPathways(postData: {}) {
return new Promise((resolve, reject) => {
axios
.post(`https://idg.reactome.org/idgpairwise/pairwise/term/false`, postData)
.then((res) => {
resolve(res.data);
})
.catch((err) => {
reject(err);
});
});
}

static getAllDataDescs(provenance: string, dataType: string) {
return new Promise((resolve, reject) => {
axios
.get(`https://idg.reactome.org/idgpairwise/datadesc`)
.then((res) => {
resolve(
res.data.filter((desc: any) =>
desc.provenance === provenance &&
desc.dataType === dataType))
})
.catch((err) => {
reject(err);
});
});
}
}

export default PairwiseService;
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const endpoints = require("./models/endpoints");
const kinasecancer = require("./data_sources/kinase-cancer-predictions/index")
const interactorScores = require("./data_sources/pairwise-relationship-data/index");
const coexpressionData = require("./data_sources/coexpression-data/index");

exports.ping = endpoints.ping;
exports.sample = endpoints.sample;
exports.predictions = kinasecancer.predictions;
exports.predictions = kinasecancer.predictions;
exports.interactorScores = interactorScores.interactorScores;
exports.coexpressionData = coexpressionData.coexpressionData;
7 changes: 5 additions & 2 deletions models/prediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class PredictionSet {
confMin: number;
style: "table" | "card";
citation: any;
facetFields: string[];

predictions: Prediction[] = [];

Expand All @@ -33,14 +34,15 @@ export class PredictionSet {
confMax: number,
confMin: number,
style: "table" | "card" = "table",
alternateName?: string) {
alternateName?: string, facetFields: string[] = ['confidence']) {
this.name = name;
this.schemaType = schemaType;
this.confidenceName = confidenceName;
this.confidenceDescription = confidenceDescription;
this.confMax = confMax;
this.confMin = confMin;
this.style = style;
this.facetFields = facetFields;
if (alternateName) {
this.alternateName = alternateName;
}
Expand Down Expand Up @@ -70,7 +72,8 @@ export class PredictionSet {
"description": this.confidenceDescription,
"maxValue": this.confMax,
"minValue": this.confMin
}
},
"facetFields": this.facetFields
};
if (this.alternateName) {
predictionObj.alternateName = this.alternateName;
Expand Down
Loading

0 comments on commit e35e280

Please sign in to comment.