Skip to content

Commit

Permalink
Merge pull request #63 from KeithKelleher/master
Browse files Browse the repository at this point in the history
Support data downloads for lists and details pages
  • Loading branch information
tsheils authored Mar 31, 2021
2 parents de4fb4b + 99b55d7 commit 2431a76
Show file tree
Hide file tree
Showing 35 changed files with 2,385 additions and 1,377 deletions.
4 changes: 3 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
instance_class: F4
instance_class: F4_1G
runtime: nodejs10
automatic_scaling:
min_instances: 1
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "src/index.js",
"scripts": {
"test" : "node src/index.js & (sleep 10 && jest)",
"justTests": "jest",
"start" : "nodemon src/index.js",
"start:ci" : "tsc && node src/index.js",
"gcp-build" : "tsc -p ."
Expand Down
11 changes: 5 additions & 6 deletions src/TCRD.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function validRegex(pattern) {
try {
var re = new RegExp(pattern, 'i');
match = re.test('test pattern doesnt matter');
} catch {
} catch (e) {
return false;
}
return true;
Expand Down Expand Up @@ -866,7 +866,7 @@ and f.itype = ?`, [filter.order]));
for (var i in args.filter.facets) {
let f = args.filter.facets[i];
if ('type' == f.facet) {
q.whereRaw(`ppitypes REGEXP '${f.values.join("|")}'`);
q.whereRaw(`ppitypes REGEXP "${f.values.join('|')}"`);
} else {
q = q.whereIn(f.facet, f.values);
}
Expand All @@ -890,8 +890,7 @@ and NOT (a.ppitypes = 'STRINGDB' AND a.score < ${confidence})
and b1.target_id = ?`, [target.tcrdid]));

if (sort) {
q = q.orderBy([{column: 'a.p_int', order: 'desc'}, {column: 'a.score', order: 'desc'},
]);
q = q.orderBy([{column: 'a.p_int', order: 'desc'}, {column: 'a.score', order: 'desc'}]);
}

if (args.top) {
Expand Down Expand Up @@ -1788,9 +1787,9 @@ and c.target_id = ?`, [target.tcrdid]));
category: this.db.raw("group_concat(`category` separator '|')"),
reference_id: this.db.raw("group_concat(ifnull(`reference_id`,'') separator '|')")
})
.where("value", "like", `%${key}%`)
.where("value", "like", this.db.raw(`"%${key}%"`))
.groupBy("value")
.orderByRaw(`(case when value like '${key}%' then 1 else 2 end), length(value), count(*) desc`)
.orderByRaw(`(case when value like "${key}%" then 1 else 2 end), length(value), count(*) desc`)
.limit(20);
return q;
}
Expand Down
185 changes: 185 additions & 0 deletions src/__tests__/diseaseQueries/comprehensive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
const {DiseaseList} = require("../../models/disease/diseaseList");
const {tcrdConfig} = require('../../__utils/loadTCRDforTesting');
const TCRD = require('../../TCRD');

let tcrd = new TCRD(tcrdConfig);

beforeAll(() => {
return tcrd.tableInfo.loadPromise.then((res) => {
return;
});
});

describe('all the queries should be consistent with each other', function () {
test('Disease batches are a thing too', () => {
const diseaseList = ["asthma", "benign ependymoma"];
const fullList = new DiseaseList(tcrd);
const batchList = new DiseaseList(tcrd, {
batch: diseaseList
});

const batchListQuery = batchList.getListQuery();
const batchCountQuery = batchList.getCountQuery();
const fullTdlFacet = fullList.facetsToFetch.find(f => f.name == 'Target Development Level').getFacetQuery();
const batchTdlFacet = batchList.facetsToFetch.find(f => f.name == 'Target Development Level').getFacetQuery();

return Promise.all([batchCountQuery, batchTdlFacet, fullTdlFacet, batchListQuery]).then(res => {
const batchCount = res[0][0].count;
expect(batchCount).toBe(diseaseList.length);
const batchLength = res[3].length;
expect(batchLength).toBe(diseaseList.length);

const batchTdlCount = res[1].reduce((a, c) => a + c.value, 0);
const fullTdlCount = res[2].reduce((a, c) => a + c.value, 0);
expect(fullTdlCount).toBeGreaterThan(batchTdlCount);
expect(batchTdlCount).toBeGreaterThan(0);
});
});


test('All diseases query', () => {
const fullList = new DiseaseList(tcrd);
const filteredList = new DiseaseList(tcrd, {filter: {facets: [{facet: "Data Source", values: ["CTD"]}]}});

const fullCountQuery = fullList.getCountQuery();
const fullListQuery = fullList.getListQuery();
const fullTypeFacet = fullList.facetsToFetch.find(facet => facet.name === 'Target Development Level');
const fullTypeFacetQuery = fullTypeFacet.getFacetQuery();

const filteredCountQuery = filteredList.getCountQuery();
const filteredListQuery = filteredList.getListQuery();
const filteredTypeFacet = filteredList.facetsToFetch.find(facet => facet.name === 'Target Development Level');
const filteredTypeFacetQuery = filteredTypeFacet.getFacetQuery();
const filteredTypeConstraintQuery = filteredList.filteringFacets[0].getFacetConstraintQuery();

return Promise.all(
[fullCountQuery, fullListQuery, fullTypeFacetQuery,
filteredCountQuery, filteredListQuery, filteredTypeFacetQuery,
filteredTypeConstraintQuery])
.then(res => {
const fullCount = res[0][0].count;
const fullListLength = res[1].length;
expect(fullCount).toBe(fullListLength);
const fullTypeCount = res[2].reduce((a, c) => a + c.value, 0);
expect(fullTypeCount).toBeGreaterThanOrEqual(fullListLength);

const filteredCount = res[3][0].count;
const filteredListLength = res[4].length;
expect(filteredCount).toBe(filteredListLength);
const filteredTypeCount = res[5].reduce((a, c) => a + c.value, 0);
expect(filteredTypeCount).toBeGreaterThanOrEqual(filteredListLength);

const facetConstraintList = res[6].length;

expect(facetConstraintList).toBe(filteredListLength);
expect(fullCount).toBeGreaterThan(filteredCount);
expect(fullTypeCount).toBeGreaterThan(filteredTypeCount);

expect(fullCount).toBeGreaterThan(0);
expect(filteredCount).toBeGreaterThan(0);

console.log(fullCount);
console.log(filteredCount);
});
});


test('term search query', () => {
const fullList = new DiseaseList(tcrd, {top: 20000, filter: {term: "cancer"}});
const filteredList = new DiseaseList(tcrd, {
top: 20000,
filter: {term: "cancer", facets: [{facet: "Data Source", values: ["CTD"]}]}
});

const fullCountQuery = fullList.getCountQuery();
const fullListQuery = fullList.getListQuery();
const fullTypeFacet = fullList.facetsToFetch.find(facet => facet.name === 'Target Development Level');
const fullTypeFacetQuery = fullTypeFacet.getFacetQuery();

const filteredCountQuery = filteredList.getCountQuery();
const filteredListQuery = filteredList.getListQuery();
const filteredTypeFacet = filteredList.facetsToFetch.find(facet => facet.name === 'Target Development Level');
const filteredTypeFacetQuery = filteredTypeFacet.getFacetQuery();
const filteredTypeConstraintQuery = filteredList.filteringFacets[0].getFacetConstraintQuery();

return Promise.all(
[fullCountQuery, fullListQuery, fullTypeFacetQuery,
filteredCountQuery, filteredListQuery, filteredTypeFacetQuery,
filteredTypeConstraintQuery])
.then(res => {
const fullCount = res[0][0].count;
const fullListLength = res[1].length;
expect(fullCount).toBe(fullListLength);
const fullTypeCount = res[2].reduce((a, c) => a + c.value, 0);
expect(fullTypeCount).toBeGreaterThanOrEqual(fullListLength); // only true for TDL because of multiple targets associated with these diseases
// ideally they'd be equal and add up exactly like in the target / ligand test facets
const filteredCount = res[3][0].count;
const filteredListLength = res[4].length;
expect(filteredCount).toBe(filteredListLength);
const filteredTypeCount = res[5].reduce((a, c) => a + c.value, 0);
expect(filteredTypeCount).toBeGreaterThanOrEqual(filteredListLength);

const facetConstraintList = res[6].length;

// expect(facetConstraintList).toBe(filteredListLength);
expect(fullCount).toBeGreaterThan(filteredCount);
expect(fullTypeCount).toBeGreaterThan(filteredTypeCount);

expect(fullCount).toBeGreaterThan(0);
expect(filteredCount).toBeGreaterThan(0);

console.log(fullCount);
console.log(filteredCount);
});
});

test('associated target query', () => {
const fullList = new DiseaseList(tcrd, {top: 20000, filter: {associatedTarget: "DRD2"}});
const filteredList = new DiseaseList(tcrd, {
top: 20000,
filter: {associatedTarget: "DRD2", facets: [{facet: "Data Source", values: ["CTD"]}]}
});

const fullCountQuery = fullList.getCountQuery();
const fullListQuery = fullList.getListQuery();
const fullTypeFacet = fullList.facetsToFetch.find(facet => facet.name === 'Drug');
const fullTypeFacetQuery = fullTypeFacet.getFacetQuery();

const filteredCountQuery = filteredList.getCountQuery();
const filteredListQuery = filteredList.getListQuery();
const filteredTypeFacet = filteredList.facetsToFetch.find(facet => facet.name === 'Drug');
const filteredTypeFacetQuery = filteredTypeFacet.getFacetQuery();
const filteredTypeConstraintQuery = filteredList.filteringFacets[0].getFacetConstraintQuery();

return Promise.all(
[fullCountQuery, fullListQuery, fullTypeFacetQuery,
filteredCountQuery, filteredListQuery, filteredTypeFacetQuery,
filteredTypeConstraintQuery])
.then(res => {
const fullCount = res[0][0].count;
const fullListLength = res[1].length;
expect(fullCount).toBe(fullListLength);
const fullTypeCount = res[2].reduce((a, c) => a + c.value, 0);
// expect(fullTypeCount).toBeGreaterThanOrEqual(fullListLength); // not true for drugs because they are sparse

const filteredCount = res[3][0].count;
const filteredListLength = res[4].length;
expect(filteredCount).toBe(filteredListLength);
const filteredTypeCount = res[5].reduce((a, c) => a + c.value, 0);
// expect(filteredTypeCount).toBeGreaterThanOrEqual(filteredListLength);

const facetConstraintList = res[6].length;

// expect(facetConstraintList).toBe(filteredListLength);
expect(fullCount).toBeGreaterThan(filteredCount);
expect(fullTypeCount).toBeGreaterThan(filteredTypeCount);

expect(fullCount).toBeGreaterThan(0);
expect(filteredCount).toBeGreaterThan(0);

console.log(fullCount);
console.log(filteredCount);
});
});

});
4 changes: 2 additions & 2 deletions src/__tests__/graphql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const request = require('sync-request');
const tester = require('graphql-tester').tester;
testDirectory = './tests';

const PORT = process.env.PORT || 4000;
const PORT = process.env.PORT || 4444;
url = `http://localhost:${PORT}/graphql/`;

function postit(query) {
Expand Down Expand Up @@ -293,4 +293,4 @@ describe('GraphQL API Tests', function () {
expect(obj.errors[0].message).toBe(null);
}
});
});
});
Loading

0 comments on commit 2431a76

Please sign in to comment.