Skip to content

Commit

Permalink
Updated functions in network-dal.js and protein-dal.js to reflect new…
Browse files Browse the repository at this point in the history
… namespaces and addition of timestamp. need to test that queries work correctly
  • Loading branch information
ceciliazaragoza committed Feb 19, 2025
1 parent 2abe82e commit a0ab429
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
29 changes: 20 additions & 9 deletions server/dals/network-dal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ var sequelize = new Sequelize(
);

const buildNetworkSourceQuery = function () {
return "SELECT * FROM gene_regulatory_network.source ORDER BY time_stamp DESC;";
return `SELECT * FROM gene_regulatory_network.source
UNION ALL
SELECT * FROM gene_regulatory_network_new.source
ORDER BY time_stamp DESC;`;
};

const buildNetworkGeneFromSourceQuery = function (gene) {
const buildNetworkGeneFromSourceQuery = function (gene, timestamp) {
const namespace =
timestamp < new Date("2025-01-01")
? "gene_regulatory_network.gene"
: "gene_regulatory_network_new.gene";
return `SELECT DISTINCT gene_id, display_gene_id FROM
gene_regulatory_network.gene WHERE (gene.gene_id ='${gene}'
OR gene.display_gene_id ='${gene}')`;
${namespace} WHERE (gene.gene_id ='${gene}'
OR gene.display_gene_id ='${gene}') AND gene.time_stamp ='${timestamp}'`;

This comment has been minimized.

Copy link
@ntran18

ntran18 Feb 19, 2025

Collaborator

This would not work for old namespace because it doesn't have time_stamp

};

const buildNetworkGenesQuery = function (geneString) {
Expand All @@ -34,14 +41,18 @@ const buildNetworkGenesQuery = function (geneString) {
genes = `${genes.substring(0, genes.length - 4)}) AND (`;
geneList.forEach(x => genes += ( `(network.target_gene_id =\'${x}\') OR `));
return `${genes.substring(0, genes.length - 4)})`;

};

const buildGenerateNetworkQuery = function (genes, source, timestamp) {
return `SELECT DISTINCT regulator_gene_id, target_gene_id FROM
gene_regulatory_network.network WHERE
time_stamp='${timestamp}' AND source='${source}' AND
${buildNetworkGenesQuery(genes)} ORDER BY regulator_gene_id DESC;`;
const namespace =
timestamp < new Date("2025-01-01")
? "gene_regulatory_network.network"
: "gene_regulatory_network_new.network";
const annotation = timestamp < new Date("2025-01-01") ? "" : ", annotation_type";
return `SELECT DISTINCT regulator_gene_id, target_gene_id${annotation} FROM ${namespace}
WHERE time_stamp='${timestamp}' AND source='${source}' AND
${buildNetworkGenesQuery(genes)} ORDER BY regulator_gene_id DESC;`;

Check failure on line 55 in server/dals/network-dal.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Trailing spaces not allowed
};

const buildQueryByType = function (queryType, query) {
Expand Down
32 changes: 22 additions & 10 deletions server/dals/protein-dal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ var sequelize = new Sequelize(
);

const buildNetworkSourceQuery = function () {
return "SELECT * FROM protein_protein_interactions.source ORDER BY time_stamp DESC;";
return `SELECT * FROM protein_protein_interactions.source
UNION ALL
SELECT * FROM protein_protein_interactions_new.source
ORDER BY time_stamp DESC;`;
};

const buildNetworkFromGeneProteinQuery = function (geneProtein) {
const buildNetworkFromGeneProteinQuery = function (geneProtein, timestamp) {
const namespace =
timestamp < new Date("2025-01-01")
? "protein_protein_interactions"
: "protein_protein_interactions_new";
return `SELECT DISTINCT gene_id, display_gene_id, standard_name, length, molecular_weight, PI FROM
protein_protein_interactions.gene, protein_protein_interactions.protein WHERE
(LOWER(gene.gene_id)=LOWER('${geneProtein}') OR LOWER(gene.display_gene_id)=LOWER('${geneProtein}')
OR LOWER(protein.standard_name) =LOWER('${geneProtein}')) AND
LOWER(gene.gene_id) = LOWER(protein.gene_systematic_name);`;
${namespace}.gene, ${namespace}.protein WHERE
(LOWER(gene.gene_id)=LOWER('${geneProtein}') OR LOWER(gene.display_gene_id)=LOWER('${geneProtein}')
OR LOWER(protein.standard_name) =LOWER('${geneProtein}')) AND
LOWER(gene.gene_id) = LOWER(protein.gene_systematic_name) AND gene.time_stamp = ${timestamp};`;

This comment has been minimized.

Copy link
@ntran18

ntran18 Feb 19, 2025

Collaborator

I would say if query by protein table, then check the timestamp for protein table too. If query by the gene table, then check the timestamp from the gene table. Also the old namespace wouldn't have timestamp

};

const buildNetworkProteinsQuery = function (proteinString) {
Expand All @@ -40,10 +47,15 @@ const buildNetworkProteinsQuery = function (proteinString) {
};

const buildGenerateProteinNetworkQuery = function (proteins, timestamp, source) {
return `SELECT DISTINCT protein1, protein2 FROM
protein_protein_interactions.physical_interactions WHERE
physical_interactions.time_stamp='${timestamp}' AND physical_interactions.source='${source}' AND
${buildNetworkProteinsQuery(proteins)} ORDER BY protein1 DESC;`;
const namespace =
timestamp < new Date("2025-01-01")
? "protein_protein_interactions"
: "protein_protein_interactions_new";
const annotation =
timestamp < new Date("2025-01-01") ? "" : ", annotation_type";
return `SELECT DISTINCT protein1, protein2${annotation} FROM ${namespace}.physical_interactions
${namespace}.time_stamp='${timestamp}' AND ${namespace}.source='${source}' AND
${buildNetworkProteinsQuery(proteins)} ORDER BY protein1 DESC;`;
};

const buildQueryByType = function (query) {
Expand Down

1 comment on commit a0ab429

@ntran18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if you can add constants for different namespaces

Please sign in to comment.