Skip to content

Commit 0427683

Browse files
authored
Merge pull request #158 from oliverfanderson/reg-degree
add regulatory degree
2 parents 6c0a290 + a80979a commit 0427683

File tree

8 files changed

+139
-46
lines changed

8 files changed

+139
-46
lines changed

client/src/components/Degree.jsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import React, { useState, useEffect } from "react";
33
// create component
44
export default function Degree(id) {
55
// create empty object to store query results
6-
// create empty object to store query results
7-
const [Degree, setDegree] = useState([]);
6+
const [physDegree, setPhysDegree] = useState([]);
7+
const [outDegree, setOutDegree] = useState([]);
8+
const [inDegree, setInDegree] = useState([]);
9+
810
useEffect(() => {
9-
fetch("/api/Degree", {
11+
fetch("/api/getPhysicalDegree", {
1012
// change to YOUR API call's URL
1113
method: "POST", // Change to GET if your call is a get request
1214
headers: {
@@ -20,8 +22,32 @@ export default function Degree(id) {
2022
.then(response => response.json())
2123
.then(data => {
2224
// console.log("Degree:", data[0]._fields[0]["low"])
23-
const Degree = data[0]._fields[0]["low"];
24-
setDegree(Degree);
25+
const physDegree = data[0]._fields[0]["low"];
26+
setPhysDegree(physDegree);
27+
})
28+
.catch((error) => {
29+
console.error('Error:', error);
30+
});
31+
}, [id]);
32+
33+
useEffect(() => {
34+
fetch("/api/getRegulatoryDegree", {
35+
// change to YOUR API call's URL
36+
method: "POST", // Change to GET if your call is a get request
37+
headers: {
38+
"Content-Type": "application/json",
39+
},
40+
body: JSON.stringify({
41+
// Example of json body request. need to match your POST request's parameters
42+
id: id
43+
}),
44+
})
45+
.then(response => response.json())
46+
.then(data => {
47+
const outDegree = data[0]._fields[0]["low"];
48+
setOutDegree(outDegree);
49+
const inDegree = data[0]._fields[1]["low"];
50+
setInDegree(inDegree);
2551
})
2652
.catch((error) => {
2753
console.error('Error:', error);
@@ -31,7 +57,9 @@ export default function Degree(id) {
3157

3258
return (
3359
<div>
34-
Protein Degree: {Degree}
60+
<h5 className="node-tab-text">Physical Degree: {physDegree}</h5>
61+
<h5 className="node-tab-text">Outward Regulatory Degree: {outDegree}</h5>
62+
<h5 className="node-tab-text">Inward Regulatory Degree: {inDegree}</h5>
3563
</div>
3664
)
3765
}

client/src/components/MotifTab.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function MotifTab({ nodeList }) {
1313
if (nodeList != undefined) {
1414
const fetchData = async () => {
1515
try {
16-
const response = await fetch("/api/Motif", {
16+
const response = await fetch("/api/getMotif", {
1717
method: "POST", // Change to GET if your call is a GET request
1818
headers: {
1919
"Content-Type": "application/json",

client/src/components/NodeTab.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export default function NodeTab({ currentNode, query, goTerm, predictionValue })
4848
Alternate Name(s): {currentNode.alt_name}
4949
</h5>
5050
)}
51-
<h5 className="node-tab-text">
52-
<Degree id={currentNode.id} />
53-
</h5>
51+
<Degree id={currentNode.id} />
5452
<h5 className="node-tab-text">
5553
Prediction Rank: {predictionValue.rank}
5654
</h5>

client/src/index.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,14 +1645,14 @@ select {
16451645
}
16461646
}
16471647

1648-
.interaction-container{
1648+
.interaction-container {
16491649
display: flex;
16501650
flex-direction: row;
16511651
align-items: center;
1652-
padding-left: 10px ;
1652+
padding-left: 10px;
16531653
}
16541654

1655-
.interaction-title{
1655+
.interaction-title {
16561656
/* border: 2px solid purple; */
16571657
/* width: 100px; */
16581658
display: inline

scripts/AncestralEdges.cypher

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,23 @@ MATCH (pr:protein{txid: "txid6239"})
6363
SET pr.degree = COUNT{(pr)-[:ProPro]-(:protein)};
6464
MATCH (pr:protein{txid: "txid559292"})
6565
SET pr.degree = COUNT{(pr)-[:ProPro]-(:protein)};
66+
MATCH (pr:protein{txid: "txid224308"})
67+
SET pr.regDegreeOut = COUNT{(pr)-[:Reg]->(:protein)};
68+
MATCH (pr:protein{txid: "txid7955"})
69+
SET pr.regDegreeOut = COUNT{(pr)-[:Reg]->(:protein)};
70+
MATCH (pr:protein{txid: "txid7227"})
71+
SET pr.regDegreeOut = COUNT{(pr)-[:Reg]->(:protein)};
72+
MATCH (pr:protein{txid: "txid6239"})
73+
SET pr.regDegreeOut = COUNT{(pr)-[:Reg]->(:protein)};
74+
MATCH (pr:protein{txid: "txid559292"})
75+
SET pr.regDegreeOut = COUNT{(pr)-[:Reg]->(:protein)};
76+
MATCH (pr:protein{txid: "txid224308"})
77+
SET pr.regDegreeIn = COUNT{(pr)<-[:Reg]-(:protein)};
78+
MATCH (pr:protein{txid: "txid7955"})
79+
SET pr.regDegreeIn = COUNT{(pr)<-[:Reg]-(:protein)};
80+
MATCH (pr:protein{txid: "txid7227"})
81+
SET pr.regDegreeIn = COUNT{(pr)<-[:Reg]-(:protein)};
82+
MATCH (pr:protein{txid: "txid6239"})
83+
SET pr.regDegreeIn = COUNT{(pr)<-[:Reg]-(:protein)};
84+
MATCH (pr:protein{txid: "txid559292"})
85+
SET pr.regDegreeIn = COUNT{(pr)<-[:Reg]-(:protein)};

server/routes/routes.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import ProteinFinderService from "../services/protein.finder.service.js";
1717
import GoFinderService from "../services/go.finder.service.js";
1818
import AvgDegreeService from "../services/avg.degree.service.js";
1919
import PGStats from "../services/pro.go.stats.service.js";
20-
import Degree from "../services/degree.service.js";
20+
import PhysicalDegree from "../services/physical.degree.service.js";
21+
import RegulatoryDegree from "../services/regulatory.degree.service.js";
2122
import MotifService from "../services/motif.service.js";
2223

2324
const router = new Router();
@@ -151,12 +152,11 @@ router.post("/getProGoStats", jsonParser, async (req, res, next) => {
151152
}
152153
});
153154

154-
155-
router.post("/Degree", jsonParser, async (req, res, next) => {
155+
router.post("/getPhysicalDegree", jsonParser, async (req, res, next) => {
156156
try {
157157
const data = req.body;
158158
const id = data.id.id;
159-
const DEG = new Degree(getDriver());
159+
const DEG = new PhysicalDegree(getDriver());
160160
const degrees = await DEG.getdegree(id);
161161
res.json(degrees);
162162
}
@@ -165,7 +165,20 @@ router.post("/Degree", jsonParser, async (req, res, next) => {
165165
}
166166
});
167167

168-
router.post("/Motif", jsonParser, async (req, res, next) => {
168+
router.post("/getRegulatoryDegree", jsonParser, async (req, res, next) => {
169+
try {
170+
const data = req.body;
171+
const id = data.id.id;
172+
const DEG = new RegulatoryDegree(getDriver());
173+
const degrees = await DEG.getDegree(id);
174+
res.json(degrees);
175+
}
176+
catch (e) {
177+
next(e);
178+
}
179+
});
180+
181+
router.post("/getMotif", jsonParser, async (req, res, next) => {
169182
try {
170183
const data = req.body;
171184
const nodeList = data.nodeList
@@ -230,10 +243,10 @@ router.post("/getQueryByPath", jsonParser, async (req, res, next) => {
230243
} else {
231244
//DO this to all GOterm
232245
let relType = ["ProGo"]
233-
if (ppi){
246+
if (ppi) {
234247
relType.push("ProProUndirected")
235248
}
236-
if (regulatory){
249+
if (regulatory) {
237250
relType.push("Reg")
238251
}
239252

@@ -316,10 +329,10 @@ router.post("/getQueryByNode", jsonParser, async (req, res, next) => {
316329
});
317330
} else {
318331
let relType = ["ProGo"]
319-
if (ppi){
332+
if (ppi) {
320333
relType.push("ProProUndirected")
321334
}
322-
if (regulatory){
335+
if (regulatory) {
323336
relType.push("Reg")
324337
}
325338
const allShortestPathsService = new AllShortestPathsService(
@@ -366,35 +379,35 @@ router.post("/getQueryByNode", jsonParser, async (req, res, next) => {
366379

367380
router.get('/call-flask', (req, res) => {
368381
const options = {
369-
hostname: 'localhost',
370-
port: 5000,
371-
path: '/test',
372-
method: 'GET'
382+
hostname: 'localhost',
383+
port: 5000,
384+
path: '/test',
385+
method: 'GET'
373386
};
374387

375388
const flaskReq = http.request(options, (flaskRes) => {
376-
let data = '';
377-
378-
// A chunk of data has been received.
379-
flaskRes.on('data', (chunk) => {
380-
data += chunk;
381-
});
382-
383-
// The whole response has been received. Print out the result.
384-
flaskRes.on('end', () => {
385-
try {
386-
const jsonData = JSON.parse(data);
387-
res.json(jsonData);
388-
} catch (error) {
389-
console.error('Error parsing JSON:', error);
390-
res.status(500).json({ message: 'Error parsing JSON from Flask API' });
391-
}
392-
});
389+
let data = '';
390+
391+
// A chunk of data has been received.
392+
flaskRes.on('data', (chunk) => {
393+
data += chunk;
394+
});
395+
396+
// The whole response has been received. Print out the result.
397+
flaskRes.on('end', () => {
398+
try {
399+
const jsonData = JSON.parse(data);
400+
res.json(jsonData);
401+
} catch (error) {
402+
console.error('Error parsing JSON:', error);
403+
res.status(500).json({ message: 'Error parsing JSON from Flask API' });
404+
}
405+
});
393406
});
394407

395408
flaskReq.on('error', (error) => {
396-
console.error('Error calling Flask API:', error);
397-
res.status(500).json({ message: 'Error calling Flask API' });
409+
console.error('Error calling Flask API:', error);
410+
res.status(500).json({ message: 'Error calling Flask API' });
398411
});
399412

400413
flaskReq.end();

server/services/Degree.service.js renamed to server/services/physical.degree.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class Degree {
1+
export default class PhysicalDegree {
22
/**
33
* @type {neo4j.Driver}
44
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default class RegulatoryDegree {
2+
/**
3+
* @type {neo4j.Driver}
4+
*/
5+
driver;
6+
7+
/**
8+
* The constructor expects an instance of the Neo4j Driver, which will be
9+
* used to interact with Neo4j.
10+
*
11+
* @param {neo4j.Driver} driver
12+
*/
13+
constructor(driver) {
14+
this.driver = driver;
15+
}
16+
17+
async getDegree(id) {
18+
const session = this.driver.session();
19+
const res = await session.executeRead((tx) =>
20+
tx.run(
21+
`
22+
match (pr:protein{id:$id})
23+
return pr.regDegreeOut as outDegree, pr.regDegreeIn as inDegree
24+
`,
25+
{
26+
id: id
27+
}
28+
)
29+
);
30+
const degree = res.records;
31+
await session.close();
32+
return degree;
33+
}
34+
}

0 commit comments

Comments
 (0)