Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cytoscape/enrichment-map-webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrtannus committed Jun 3, 2024
2 parents 8840dc6 + 89ff049 commit ab41ede
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 121 deletions.
10 changes: 1 addition & 9 deletions src/client/components/network-editor/gene-list-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,8 @@ const GeneMetadataPanel = ({ controller, symbol, showSymbol }) => {
}
);

const queryNodes = useQuery(
['related-node-ids', symbol],
() => fetch(`/api/${controller.cy.data('id')}/${symbol}/nodes`)
.then(res => res.json())
.then(res => res.nodeIDs),
{ retry: false }
);

const data = queryGeneData.data;
const isLoading = queryGeneData.isLoading || queryNodes.isLoading;
const isLoading = queryGeneData.isLoading;

let error = queryGeneData.error;
let description, ncbiId;
Expand Down
64 changes: 4 additions & 60 deletions src/server/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class Datastore {
networkJson['_id'] = networkID.bson;
networkJson['networkIDStr'] = networkID.string;
networkJson['creationTime'] = new Date();

delete networkJson['summaryNetwork'];

if(networkName)
networkJson['networkName'] = networkName;
Expand Down Expand Up @@ -283,7 +285,6 @@ class Datastore {

// Create an initialize the documents in the GENE_RANKS_COLLECTION, used for quick lookups.
await this.createGeneRanksDocuments(networkID);
await this.mergeSummaryNodeIDsIntoGeneRanks(geneSetCollection, networkID);
await this.mergePathwayNamesIntoGeneRanks(geneSetCollection, networkID);

return geneListID.string;
Expand Down Expand Up @@ -311,51 +312,6 @@ class Datastore {
}


/**
* Update the documents in the geneRanks collection to add the 'summaryNodeIDs' field.
*/
async mergeSummaryNodeIDsIntoGeneRanks(geneSetCollection, networkID) {
await this.db
.collection(NETWORKS_COLLECTION)
.aggregate([
// Get the nodeIDs and the names of the Pathways they represent
{ $match: { _id: networkID.bson } },
{ $replaceWith: { path: "$summaryNetwork.elements.nodes.data" } },
{ $unwind: { path: "$path" } },
{ $replaceRoot: { newRoot: "$path" } },
{ $addFields: { splitNames: {
$cond: {
if: { $isArray: "$name" },
then: { $getField: "name" },
else: { $split: [ "$name", "," ] }
}
} } },
{ $unwind: { path: "$splitNames" } },

// Lookup the genes contained in each node
{ $lookup: {
from: geneSetCollection,
localField: "splitNames",
foreignField: "name",
as: "geneSet"
}},
{ $replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$geneSet", 0 ] }, "$$ROOT" ] } } },
{ $unwind: { path: "$genes" } },
{ $group: { _id: "$genes", nodeIDs: { $addToSet: "$id" } }},
{ $project: { _id: 0, gene: "$_id", nodeIDs: 1, networkID: networkID.bson } },

// Update the geneRanks collection
{ $merge: {
into: GENE_RANKS_COLLECTION,
on: [ "networkID", "gene" ],
whenNotMatched: "discard",
let: { nodeIDs: "$nodeIDs" },
whenMatched: [{ $addFields: { summaryNodeIDs: "$$nodeIDs" } }],
}
}
]).toArray();
}

/**
* Update the documents in the geneRanks collection to add the 'pathways' field.
*/
Expand Down Expand Up @@ -608,7 +564,7 @@ class Datastore {
.aggregate([
// Get the node data in the network
{ $match: { _id: networkID.bson } },
{ $replaceWith: { path: "$summaryNetwork.elements.nodes.data" } },
{ $replaceWith: { path: "$network.elements.nodes.data" } },
{ $unwind: { path: "$path" } },
{ $replaceRoot: { newRoot: "$path" } },
// Get the names
Expand Down Expand Up @@ -651,19 +607,6 @@ class Datastore {
}


/**
* Returns the IDs of nodes that contain the given gene.
*/
async getNodesContainingGene(networkIDString, geneName) {
const networkID = makeID(networkIDString);
return await this.db
.collection(GENE_RANKS_COLLECTION)
.findOne(
{ networkID: networkID.bson, gene: geneName },
{ projection: { _id: 0, nodeIDs: "$summaryNodeIDs" } }
);
}

/**
* Returns the values of the min and max ranks in the network.
*/
Expand Down Expand Up @@ -693,6 +636,7 @@ class Datastore {

if(geneSetNames === undefined || geneSetNames.length == 0) {
geneSetNames = await this.getNodeDataSetNames(networkID);
console.log("geneSetNames", geneSetNames);
}

const geneListWithRanks = await this.db
Expand Down
17 changes: 0 additions & 17 deletions src/server/routes/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,6 @@ http.get('/:netid/ranks', async function(req, res, next) {
}
});

/**
* Returns the IDs of nodes that contain the given gene.
*/
http.get('/:netid/:gene/nodes', async function(req, res, next) {
try {
const { netid, gene } = req.params;
const nodeIDs = await Datastore.getNodesContainingGene(netid, gene);
if(!nodeIDs) {
res.sendStatus(404);
} else {
res.send(JSON.stringify(nodeIDs));
}
} catch (err) {
next(err);
}
});


/*
* Returns the contents of multiple gene sets, including ranks.
Expand Down
35 changes: 0 additions & 35 deletions test/test_datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ describe('Gene Set Queries', () => {
it('gets a network', async () => {
const network = await Datastore.getNetwork(networkID, { nodeLimit: 100 });
expect(network.networkIDStr).to.eql(networkID);
expect(network.summaryNetwork.elements.nodes.length).to.eql(4);
expect(network.summaryNetwork.elements.edges.length).to.eql(2);
});

it('get a gene sets', async () => {
Expand Down Expand Up @@ -128,37 +126,4 @@ describe('Gene Set Queries', () => {
});
});

it('gets nodes for genes', async () => {
const lookup = async gene => {
const results = await Datastore.getNodesContainingGene(networkID, gene);
results.nodeIDs.sort();
return results;
};
{
const results = await lookup("AAA");
expect(results).to.eql({
nodeIDs: [
'3f9549bd-17f3-4625-88da-86f33794aac5',
'9aaa7dea-8353-4cb6-9e8b-dd0b52927821',
'aae5d32b-04ac-4aa7-a440-81843921e258',
'ccc53527-c85f-411d-8b96-bd317522b6a7',
]
});
} {
const results = await lookup("CCC");
expect(results).to.eql({
nodeIDs: [
'9aaa7dea-8353-4cb6-9e8b-dd0b52927821',
'ccc53527-c85f-411d-8b96-bd317522b6a7',
]
});
} {
const results = await lookup("LLL");
expect(results).to.eql({
nodeIDs: [
'aae5d32b-04ac-4aa7-a440-81843921e258',
]
});
}
});
});

0 comments on commit ab41ede

Please sign in to comment.