Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating database NOT READY FOR REVIEW #1175

Draft
wants to merge 1 commit into
base: database
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
);

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}'`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Old namespace doesn't have timestamp so this would cause error

};

const buildNetworkGenesQuery = function (geneString) {
Expand All @@ -34,14 +41,18 @@
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Similar here, old namepsace doesn't have timestamp. Additionally, if we query from protein table, then we should check the timestamp from the protein table. If we query from gene table, then we should check the timestamp from the gene table.

(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};`;
};

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
Loading