-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from ducku/issues/377-refactor-api-interface
Implement API Interface
- Loading branch information
Showing
6 changed files
with
173 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
// Interface for handling function called from the tubemap frontend | ||
// Abstract class expecting different implmentations of the following functions | ||
// Substituting different subclasses should allow the functions to give the same result | ||
export class APIInterface { | ||
// Takes in and process a tube map view(viewTarget) from the tubemap container | ||
// Expects a object to be returned with the necessary information to draw a tubemap from vg | ||
// object should contain keys: graph, gam, region, coloredNodes | ||
async getChunkedData(viewTarget) { | ||
throw new Error("getChunkedData function not implemented"); | ||
} | ||
|
||
// Returns files used to determine what options are available in the track picker | ||
// Returns object with keys: files, bedFiles | ||
async getFilenames() { | ||
throw new Error("getFilenames function not implemented"); | ||
} | ||
|
||
// Takes in a bedfile path or a url pointing to a raw bed file | ||
// Returns object with key: bedRegions | ||
// bedRegions contains information extrapolated from each line of the bedfile | ||
async getBedRegions(bedFile) { | ||
throw new Error("getBedRegions function not implemented"); | ||
} | ||
|
||
// Takes in a graphFile path | ||
// Returns object with key: pathNames | ||
// Returns pathnames available in a graphfile | ||
async getPathNames(graphFile) { | ||
throw new Error("getPathNames function not implemented"); | ||
} | ||
|
||
// Expects a bed file(or url) and a chunk name | ||
// Attempts to download tracks associated with the chunk name from the bed file if it is a URL | ||
// Returns object with key: tracks | ||
// Returns tracks found from local directories as a tracks object | ||
async getChunkTracks(bedFile, chunk) { | ||
throw new Error("getChunkTracks function not implemented"); | ||
} | ||
} | ||
|
||
export default APIInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { fetchAndParse } from "./fetchAndParse.js"; | ||
import { APIInterface } from "./APIInterface.mjs"; | ||
|
||
export class ServerAPI extends APIInterface { | ||
constructor(apiUrl) { | ||
super(); | ||
this.apiUrl = apiUrl; | ||
} | ||
|
||
// Each function takes a cancelSignal to cancel the fetch request if we will unmount component | ||
|
||
async getChunkedData(viewTarget, cancelSignal) { | ||
const json = await fetchAndParse(`${this.apiUrl}/getChunkedData`, { | ||
signal: cancelSignal, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(viewTarget), | ||
}); | ||
return json; | ||
} | ||
|
||
async getFilenames(cancelSignal) { | ||
const json = await fetchAndParse(`${this.apiUrl}/getFilenames`, { | ||
signal: cancelSignal, | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
return json; | ||
} | ||
|
||
async getBedRegions(bedFile, cancelSignal) { | ||
const json = await fetchAndParse(`${this.apiUrl}/getBedRegions`, { | ||
signal: cancelSignal, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ bedFile }), | ||
}); | ||
return json; | ||
} | ||
|
||
async getPathNames(graphFile, cancelSignal) { | ||
const json = await fetchAndParse(`${this.apiUrl}/getPathNames`, { | ||
signal: cancelSignal, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ graphFile }), | ||
}); | ||
return json | ||
} | ||
|
||
async getChunkTracks(bedFile, chunk, cancelSignal) { | ||
const json = await fetchAndParse(`${this.apiUrl}/getChunkTracks`, { | ||
signal: cancelSignal, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ bedFile: bedFile, chunk: chunk }), | ||
}); | ||
return json; | ||
} | ||
} | ||
|
||
export default ServerAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters