@@ -12,11 +12,6 @@ import CytoscapeComponent from "react-cytoscapejs";
1212import cytoscape from "cytoscape" ;
1313import { cytoscapeStyle , layout } from "../assets/CytoscapeConfig" ;
1414import cola from "cytoscape-cola" ;
15- // import {
16- // cytoscapeTestElements,
17- // cytoscapeTest,
18- // cytoscapeTest2,
19- // } from "../assets/CytoscapeTestElements";
2015
2116// component imports
2217import QueryError from "./QueryError" ;
@@ -30,6 +25,7 @@ import StatisticsTab from "./StatisticsTab";
3025
3126// panel imports
3227import { Panel , PanelGroup , PanelResizeHandle } from "react-resizable-panels" ;
28+ import { fetchAvgDegree , getBasicStatistics } from "../tools/Statistics" ;
3329
3430export default function Query ( ) {
3531 const [ query , setQuery ] = useState ( {
@@ -67,6 +63,13 @@ export default function Query() {
6763 const [ activeModeButton , setActiveModeButton ] = useState ( "" ) ;
6864 const [ dataParsingStatus , setDataParsingStatus ] = useState ( false ) ;
6965 const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
66+ const [ rawData , setRawData ] = useState ( "" ) ;
67+ const [ networkStatistics , setNetworkStatistics ] = useState ( {
68+ nodeCount : null ,
69+ edgeCount : null ,
70+ pathCount : null ,
71+ avgNodeDegree : null ,
72+ } ) ;
7073
7174 const [ pageState , setPageState ] = useState ( 0 ) ;
7275 cytoscape . use ( cola ) ;
@@ -176,6 +179,31 @@ export default function Query() {
176179 }
177180 } , [ networkResult ] ) ;
178181
182+ //Once the network parsing has completed, get all the stats information of the subnetwork.
183+ useEffect ( ( ) => {
184+ if ( dataParsingStatus ) {
185+ //asyc function to get the average degree of subnetwork
186+ const getAvgDegree = async ( ) => {
187+ try {
188+ const avgNodeDegree = await fetchAvgDegree (
189+ networkResult ,
190+ query . species
191+ ) ;
192+ setNetworkStatistics ( ( prevState ) => ( {
193+ ...prevState ,
194+ avgNodeDegree : avgNodeDegree . toFixed ( 1 ) ,
195+ } ) ) ;
196+ } catch ( error ) {
197+ return Promise . reject (
198+ new Error ( `${ response . status } ${ response . statusText } ` )
199+ ) ;
200+ }
201+ } ;
202+ setNetworkStatistics ( getBasicStatistics ( networkResult , rawData , query ) ) ;
203+ getAvgDegree ( ) ;
204+ }
205+ } , [ dataParsingStatus ] ) ;
206+
179207 // Function for submitting the query
180208 async function handleSubmit ( e ) {
181209 setSidebarNode ( null ) ;
@@ -197,6 +225,7 @@ export default function Query() {
197225 // get the k shortest paths for the query
198226 e . preventDefault ( ) ;
199227 let network = null ;
228+ let rawData = null ;
200229 if ( query . mode == "path" ) {
201230 try {
202231 network = await fetch ( "/api/getQuery" , {
@@ -220,6 +249,7 @@ export default function Query() {
220249 }
221250 } )
222251 . then ( ( data ) => {
252+ rawData = data ;
223253 return NetworkParserPath ( data , query . protein , query . goTerm ) ;
224254 } ) ;
225255 } catch ( error ) {
@@ -253,6 +283,7 @@ export default function Query() {
253283 }
254284 } )
255285 . then ( ( data ) => {
286+ rawData = data ;
256287 return NetworkParserNode ( data , query . protein , query . k ) ;
257288 } ) ;
258289 } catch ( error ) {
@@ -261,11 +292,9 @@ export default function Query() {
261292 setHasError ( true ) ;
262293 setPageState ( 0 ) ;
263294 setIsLoading ( false ) ;
264-
265295 return ;
266296 }
267297 }
268-
269298 // get induced subgraph
270299 if ( network != null ) {
271300 let nodeList = { nodeList : network . nodeList } ;
@@ -293,6 +322,7 @@ export default function Query() {
293322 } )
294323 . then ( ( edgeData ) => {
295324 setNetworkResult ( EdgeDataParser ( network , edgeData ) ) ;
325+ setRawData ( rawData ) ;
296326 setDataParsingStatus ( true ) ;
297327 return EdgeDataParser ( network , edgeData ) ;
298328 } ) ;
@@ -715,7 +745,9 @@ export default function Query() {
715745 </ Panel >
716746 < PanelResizeHandle className = "panel-resize-handle" />
717747 < Panel defaultSize = { 40 } minSize = { 10 } >
718- < StatisticsTab > </ StatisticsTab >
748+ < StatisticsTab
749+ networkStatistics = { networkStatistics }
750+ > </ StatisticsTab >
719751 </ Panel >
720752 </ PanelGroup >
721753 </ Panel >
0 commit comments