Skip to content

Commit

Permalink
Merge pull request #64 from KeithKelleher/master
Browse files Browse the repository at this point in the history
TIGA, UNIIs, TCRD upgrade
  • Loading branch information
tsheils authored Apr 26, 2021
2 parents 2431a76 + db2d35c commit d218611
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 106 deletions.
13 changes: 8 additions & 5 deletions pharos_database_transforms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ Here's what that looks like for our AWS server
USER = 'ncats'
PWORD = '<set password, don't commit it to a repo!>'
```
4. Run the pharos specific transformations
* Run these python files at the terminal, they will use credentials from credentials.py to update the database
4. Run the pharos specific transformations
* all of these have been moved to pharos-etl repo, go there to do the knex migrations
The only one here that you might want to do is the lychi one if the drug tables have changed
* ~~Run these python files at the terminal, they will use credentials from credentials.py to update the database~~
* First
* ~~First~~
* create indices and columns necessary for pharos
```
python executeSQLfile.py tcrd-create-indexes.sql
```
* Second
* Populate lychi_h4 keys for all ligands and drugs
* write smiles to files
Expand All @@ -67,7 +70,7 @@ Here's what that looks like for our AWS server
python lychi-set.py
```
* Later
* ~~Later~~
* create and populate the table that hold the lists of IDG targets
```
python executeSQLfile.py tcrd-create-idg-lists.sql
Expand Down Expand Up @@ -98,7 +101,7 @@ Here's what that looks like for our AWS server
```
python tcrd-create-generif-pubmed-map.py
```
* Later still
* ~~Later still~~
* create mapping between data sources and all the targets, diseases, and ligands we have data from there for
```
python tcrd-create-datasource-table.py
Expand Down
14 changes: 10 additions & 4 deletions src/TCRD.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ OR b.id = (SELECT protein_id FROM xref where xtype = 'Ensembl' and value = ? lim
and b.geneid=?`, [args.geneid]));
}

if (args.protein_id) {
return this.db.select(this.db.raw(TARGET_SQL + `
and b.id=?`, [args.protein_id]));
}

return this.db.select(this.db.raw(TARGET_SQL + `
and a.id = ?`, [args.tcrdid]));
}
Expand Down Expand Up @@ -973,7 +978,7 @@ and b.target_id = ?`, [target.tcrdid]));
}

let q = this.db.select(this.db.raw(p + ` as name,
avg(a.attr_cdf) as value
avg(a.attr_cdf) as value, group_concat(distinct concat(b.name,'!',b.url) order by b.name separator '|') as sources
from hgram_cdf a, gene_attribute_type b, t2tc c
where a.protein_id = c.protein_id
and c.target_id = ?
Expand Down Expand Up @@ -1724,7 +1729,8 @@ a.*,b.parent_id from do a, do_parent b where a.doid = b.doid`));
getDTO(args) {
let matches = [];
if (args.dtoid) {
let n = this.dto[args.dtoid];
const dtoFormat = args.dtoid.replace('_',':');
let n = this.dto[dtoFormat];
while (n) {
matches.push(n);
n = n.parent;
Expand All @@ -1751,7 +1757,7 @@ and b.target_id = ?`, [target.tcrdid]));

getTINXForTarget(target, args) {
let q = this.db.select(this.db.raw(`
a.*,b.doid, b.score as novelty, a.id as tinxid
a.*, b.doid, b.score as novelty
from tinx_importance a, tinx_disease b, t2tc c`));

let sort = true;
Expand All @@ -1763,7 +1769,7 @@ match(b.name,b.summary) against(? in boolean mode)`, [t]));
sort = false;
}
}
q = q.andWhere(this.db.raw(`a.disease_id = b.id
q = q.andWhere(this.db.raw(`a.doid = b.doid
and a.protein_id = c.protein_id
and c.target_id = ?`, [target.tcrdid]));

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/targetQueries/comprehensive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ describe('all the queries should be consistent with each other', function () {
});

test('Similarity query', () => {
const fullList = new TargetList(tcrd, {top:1000000, filter: {similarity: "(Q6P1J9, GWAS)"}});
const filteredList = new TargetList(tcrd, {filter: {similarity: "(Q6P1J9, GWAS)", facets: [{facet: "Target Development Level", values: ["Tclin"]}]}});
const fullList = new TargetList(tcrd, {top:1000000, filter: {similarity: "(DRD2, GWAS)"}});
const filteredList = new TargetList(tcrd, {filter: {similarity: "(DRD2, GWAS)", facets: [{facet: "Target Development Level", values: ["Tclin"]}]}});

const fullCountQuery = fullList.getCountQuery();
const fullListQuery = fullList.getListQuery();
Expand Down
6 changes: 3 additions & 3 deletions src/db_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//
const cred = {
DBHOST: 'tcrd.ncats.io',
DBNAME: 'tcrd684',
CONFIGDB: 'pharos_config_prod',
DBNAME: 'tcrd6110',
USER: 'tcrd',
PWORD: ''
PWORD: '',
CONFIGDB: 'pharos_config_prod',
};
module.exports.cred = cred;
4 changes: 2 additions & 2 deletions src/models/DataModelList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export abstract class DataModelList implements IBuildable {
return query;
};

getListQuery() {
getListQuery(innerJoinAll: boolean = false) {
let dataFields: FieldInfo[];
if (this.fields && this.fields.length > 0) {
dataFields = this.GetDataFields('list');
Expand All @@ -172,7 +172,7 @@ export abstract class DataModelList implements IBuildable {

const queryDefinition = QueryDefinition.GenerateQueryDefinition(this, dataFields);

const query = queryDefinition.generateBaseQuery(false);
const query = queryDefinition.generateBaseQuery(innerJoinAll);

this.addFacetConstraints(query, this.filteringFacets);
this.addModelSpecificFiltering(query, true, this.dataFields.map(f => f.table));
Expand Down
3 changes: 2 additions & 1 deletion src/models/databaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class DatabaseTable {
["protein-target", ["t2tc"]],
["protein-ncats_idg_list_type", ["ncats_idg_list"]],
["protein-ncats_ligands", ["ncats_ligand_activity", "target", "t2tc"]],
["protein-ncats_ligand_activity", ["target", "t2tc"]]
["protein-ncats_ligand_activity", ["target", "t2tc"]],
["protein-drgc_resource", ["target", "t2tc"]]
]);

static getRequiredLinks(table1: string, table2: string): string[] | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/models/disease/diseaseList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DiseaseList extends DataModelList {
importance:knex.raw('(tinx_importance.score)')
})
.join(doidList.as('idList'), 'idList.did', 'tinx_disease.doid')
.where(knex.raw('tinx_importance.disease_id = tinx_disease.id'))
.where(knex.raw('tinx_importance.doid = tinx_disease.doid'))
.andWhere(knex.raw('tinx_importance.protein_id = t2tc.protein_id'))
.andWhere(knex.raw('tinx_importance.protein_id = tinx_novelty.protein_id'))
.andWhere(knex.raw('t2tc.target_id = target.id'));
Expand Down
4 changes: 2 additions & 2 deletions src/models/queryDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class QueryDefinition {
return dataTable.tableName === this.buildable.rootTable && dataTable.alias === this.buildable.rootTable;
}

generateBaseQuery(forFacet: boolean){
generateBaseQuery(innerJoinAll: boolean){
const buildableObj = this.buildable;
let rootTableObject = this.getRootTable();
if (rootTableObject == undefined) {
Expand All @@ -161,7 +161,7 @@ export class QueryDefinition {
return;
}
let joinFunction = 'leftJoin';
if(forFacet || this.buildable.tableNeedsInnerJoin(dataTable)){
if(innerJoinAll || this.buildable.tableNeedsInnerJoin(dataTable)){
joinFunction = 'join';
}
let leftTable = rootTableObject;
Expand Down
13 changes: 13 additions & 0 deletions src/models/target/targetDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ export class TargetDetails{
.orderBy(['startResidue', 'endResidue']);
return query;
}

static LD2JSON(ldObject: any){
const jsonObject: any = {};
for (const prop in ldObject) {
if (ldObject[prop]['@value']) {
jsonObject[prop] = ldObject[prop]['@value'];
}
else if (ldObject[prop]['rdfs:label']) {
jsonObject[prop] = ldObject[prop]['rdfs:label'];
}
}
return jsonObject;
}
}
Loading

0 comments on commit d218611

Please sign in to comment.