From a21ea591fd71b3698191b7e3d907db5354f26451 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Thu, 7 Dec 2023 14:14:59 -0800 Subject: [PATCH 1/8] Preliminary work for this issue - setting up region parsing and determining if it exists --- src/common.mjs | 2 ++ src/components/HeaderForm.js | 47 +++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/common.mjs b/src/common.mjs index ae001cc8..553a7c5e 100644 --- a/src/common.mjs +++ b/src/common.mjs @@ -26,6 +26,8 @@ const removeCommas = (input) => { // or // { contig, start, distance } // +// a region string could look like: "17:1-100" +// // For distance, + is used as the coordinate separator. For start/end ranges, - is used. // The coordinates are set off from the contig by the last colon. // Commas in coordinates are removed. diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 3f4d6f09..7377ffc6 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -38,8 +38,25 @@ const CLEAR_STATE = { // File: The file name actually used (or undefined) bedSelect: "none", - // This tracks several arrays of BED region data, stored by data type, with + // This tracks several arrays (desc, chr, start, end) of BED region data, with // one entry in each array per region. + // desc: description of region, i.e. "region with no source graph available" + // chr: path in graph where the region is on, i.e. in ref:2000-3000, "ref" is the chr + // start: start of the region, i.e. in ref:2000-3000, 2000 is the start + // end: end of the region, i.e. in ref:2000-3000, 3000 is the end + // chunk: url/directory for preexisting cached chunk, or empty string if not available + // tracks: object full of tracks to apply when user selects region, or null + // so regionInfo might look like: + /* + { + chr: [ '17', '17' ], + start: [ '1', '1000' ], + end: [ '100', '1200' ], + desc: [ '17_1_100', '17_1000_1200' ], + chunk: [ '', '' ], + tracks: [ null, null ] + } + */ regionInfo: {}, pathNames: ["none"], @@ -510,6 +527,34 @@ class HeaderForm extends Component { return regionString; }; + // determine the current region: accepts a region string and returns the region index + /* + { + chr: [ '17', '17' ], + start: [ '1', '1000' ], + end: [ '100', '1200' ], + desc: [ '17_1_100', '17_1000_1200' ], + chunk: [ '', '' ], + tracks: [ null, null ] + } + 17:1-100 -> parse -> {contig: "17", start: 1, end: 100} -> 0 + 17:1000-1200 -> parse -> {contig: "17", start: 1000, end: 1200} -> 1 + 17:2000-3000 - cannot be found - return null + */ + + /* + function (region string){ + parse(region string) -> return {contig, start, end} + loop over chr in region info + determine if contig, start, end are present at the current index + if present: return index + return null + } + */ + + + + // In addition to a new region value, also takes tracks and chunk associated with the region // Update current track if the new tracks are valid // Otherwise check if the current bed file is a url, and if tracks can be fetched from said url From c253f854708ac7084a99d15eb145f136ba3c5026 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Tue, 9 Jan 2024 22:15:05 -0800 Subject: [PATCH 2/8] Wrote out function that determines region index and existence --- src/components/HeaderForm.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 7377ffc6..c65d2ebf 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -542,15 +542,27 @@ class HeaderForm extends Component { 17:2000-3000 - cannot be found - return null */ - /* - function (region string){ - parse(region string) -> return {contig, start, end} - loop over chr in region info - determine if contig, start, end are present at the current index - if present: return index - return null + /* + function (region string){ + parse(region string) -> return {contig, start, end} + loop over chr in region info + determine if contig, start, end are present at the current index + if present: return index + return null + } + */ + + determineRegionIndex = (regionString) => { + let parsedRegion = parseRegion(regionString); + for (let i = 0; i < this.state.regionInfo["chr"].length; i++){ + if ((this.state.regionInfo["start"][i] === parsedRegion[start]) + && (this.state.regionInfo["end"][i] === parsedRegion[end]) + && (this.state.regionInfo["chr"][i] === parsedRegion[contig])){ + return i; + } } - */ + return null; + } From 129a86ea671329c2c186a05da42ead5d46ae3a20 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Wed, 10 Jan 2024 21:38:12 -0800 Subject: [PATCH 3/8] added function that takes an index and creates a region string from data at the index --- src/components/HeaderForm.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index c65d2ebf..35f0bdd1 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -564,6 +564,16 @@ class HeaderForm extends Component { return null; } + // reverse of previous function + // assumes that index is valid in regionInfo + regionStringFromRegionIndex = (regionIndex) => { + let regionStart = this.state.regionInfo["start"][regionIndex]; + let regionEnd = this.state.regionInfo["start"][regionIndex]; + let regionContig = this.state.regionInfo["chr"][regionIndex]; + return regionContig + ":" + regionStart + "-" + regionEnd; + } + + // if null: use old behavior From 396c66830e0a752de5dc7c90feac1f52661ae101 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Fri, 12 Jan 2024 10:24:32 -0800 Subject: [PATCH 4/8] Added functions to take care of moving to next and previous regions of bed file upon user click of left and right buttons --- src/components/DataPositionFormRow.js | 4 ++ src/components/HeaderForm.js | 69 ++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/components/DataPositionFormRow.js b/src/components/DataPositionFormRow.js index f90c7470..c450f40c 100644 --- a/src/components/DataPositionFormRow.js +++ b/src/components/DataPositionFormRow.js @@ -82,6 +82,7 @@ class DataPositionFormRow extends Component { color="primary" id="goLeftButton" onClick={this.props.handleGoLeft} + disabled={this.props.uploadInProgress || !this.props.canGoLeft} > @@ -95,6 +96,7 @@ class DataPositionFormRow extends Component { color="primary" id="goRightButton" onClick={this.props.handleGoRight} + disabled={this.props.uploadInProgress || !this.props.canGoRight} > @@ -123,6 +125,8 @@ DataPositionFormRow.propTypes = { uploadInProgress: PropTypes.bool.isRequired, getCurrentViewTarget: PropTypes.func.isRequired, viewTargetHasChange: PropTypes.bool.isRequired, + canGoLeft: PropTypes.bool.isRequired, + canGoRight: PropTypes.bool.isRequired, }; export default DataPositionFormRow; diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 35f0bdd1..2701c6be 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -553,11 +553,19 @@ class HeaderForm extends Component { */ determineRegionIndex = (regionString) => { - let parsedRegion = parseRegion(regionString); + let parsedRegion; + try { + parsedRegion = parseRegion(regionString); + } catch(error) { + return null; + } + if (!this.state.regionInfo["chr"]){ + return null; + } for (let i = 0; i < this.state.regionInfo["chr"].length; i++){ - if ((this.state.regionInfo["start"][i] === parsedRegion[start]) - && (this.state.regionInfo["end"][i] === parsedRegion[end]) - && (this.state.regionInfo["chr"][i] === parsedRegion[contig])){ + if ((this.state.regionInfo["start"][i] === parsedRegion.start) + && (this.state.regionInfo["end"][i] === parsedRegion.end) + && (this.state.regionInfo["chr"][i] === parsedRegion.contig)){ return i; } } @@ -568,7 +576,7 @@ class HeaderForm extends Component { // assumes that index is valid in regionInfo regionStringFromRegionIndex = (regionIndex) => { let regionStart = this.state.regionInfo["start"][regionIndex]; - let regionEnd = this.state.regionInfo["start"][regionIndex]; + let regionEnd = this.state.regionInfo["end"][regionIndex]; let regionContig = this.state.regionInfo["chr"][regionIndex]; return regionContig + ":" + regionStart + "-" + regionEnd; } @@ -696,12 +704,57 @@ class HeaderForm extends Component { ); } + + /* Offset the region left or right by the given negative or positive fraction*/ + // offset: +1 or -1 + jumpRegion(offset) { + let regionIndex = this.determineRegionIndex(this.state.region) ?? 0; + if ((offset === -1 && this.canGoLeft(regionIndex)) || (offset === 1 && this.canGoRight(regionIndex))){ + regionIndex += offset; + } + let regionString = this.regionStringFromRegionIndex(regionIndex); + this.setState( + (state) => ({ + region: regionString, + }), + () => this.handleGoButton() + ); + } + + canGoLeft = (regionIndex) => { + if (this.state.bedFile){ + return (regionIndex > 0); + } else { + return true; + } + } + + canGoRight = (regionIndex) => { + if (this.state.bedFile){ + if (!this.state.regionInfo["chr"]){ + return false; + } + return (regionIndex < ((this.state.regionInfo["chr"].length) - 1)); + } else { + return true; + } + } + + handleGoRight = () => { - this.budgeRegion(0.5); + if (this.state.bedFile){ + this.jumpRegion(1); + } else { + this.budgeRegion(0.5); + } }; handleGoLeft = () => { - this.budgeRegion(-0.5); + if (this.state.bedFile){ + this.jumpRegion(-1); + } else { + this.budgeRegion(-0.5); + } }; showFileSizeAlert = () => { @@ -831,6 +884,8 @@ class HeaderForm extends Component { uploadInProgress={this.state.uploadInProgress} getCurrentViewTarget={this.props.getCurrentViewTarget} viewTargetHasChange={viewTargetHasChange} + canGoLeft={this.canGoLeft(this.determineRegionIndex(this.state.region))} + canGoRight={this.canGoRight(this.determineRegionIndex(this.state.region))} /> return ( From cf398a56035fcc4f7b0fdb57fba14041261a8d0a Mon Sep 17 00:00:00 2001 From: shreyasun Date: Fri, 12 Jan 2024 10:53:25 -0800 Subject: [PATCH 5/8] Made fixes to functions to allow for proper left/right button enabling/disabling based on available regions --- src/components/HeaderForm.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index e4615d5e..829b4c5e 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -554,11 +554,14 @@ class HeaderForm extends Component { return null; } if (!this.state.regionInfo["chr"]){ + console.log("this.state.regionInfo is null"); return null; } + console.log("Should be: ", parsedRegion); for (let i = 0; i < this.state.regionInfo["chr"].length; i++){ - if ((this.state.regionInfo["start"][i] === parsedRegion.start) - && (this.state.regionInfo["end"][i] === parsedRegion.end) + console.log("Current: start: ", this.state.regionInfo["start"][i], "end: ", this.state.regionInfo["end"][i], "chr: ", this.state.regionInfo["chr"][i]); + if ((parseInt(this.state.regionInfo["start"][i]) === parsedRegion.start) + && (parseInt(this.state.regionInfo["end"][i]) === parsedRegion.end) && (this.state.regionInfo["chr"][i] === parsedRegion.contig)){ return i; } From b2d657e03ab727e6cb3b7b07c33579f75ef4898d Mon Sep 17 00:00:00 2001 From: shreyasun Date: Mon, 22 Jan 2024 09:00:10 -0800 Subject: [PATCH 6/8] removed some comments / cleanup --- src/components/HeaderForm.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 829b4c5e..898781a0 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -547,6 +547,7 @@ class HeaderForm extends Component { */ determineRegionIndex = (regionString) => { + console.log("state:", this.state); let parsedRegion; try { parsedRegion = parseRegion(regionString); @@ -554,12 +555,9 @@ class HeaderForm extends Component { return null; } if (!this.state.regionInfo["chr"]){ - console.log("this.state.regionInfo is null"); return null; } - console.log("Should be: ", parsedRegion); for (let i = 0; i < this.state.regionInfo["chr"].length; i++){ - console.log("Current: start: ", this.state.regionInfo["start"][i], "end: ", this.state.regionInfo["end"][i], "chr: ", this.state.regionInfo["chr"][i]); if ((parseInt(this.state.regionInfo["start"][i]) === parsedRegion.start) && (parseInt(this.state.regionInfo["end"][i]) === parsedRegion.end) && (this.state.regionInfo["chr"][i] === parsedRegion.contig)){ @@ -578,10 +576,7 @@ class HeaderForm extends Component { return regionContig + ":" + regionStart + "-" + regionEnd; } - // if null: use old behavior - - // In addition to a new region value, also takes tracks and chunk associated with the region // Update current track if the new tracks are valid // Otherwise check if the current bed file is a url, and if tracks can be fetched from said url From 8fad40ea7a5ce3284b7c28deaad55e1ddf11f0a1 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Mon, 22 Jan 2024 09:00:59 -0800 Subject: [PATCH 7/8] working on some new tests for the determineRegionIndex and regionStringFromRegionIndex --- src/components/HeaderForm.test.js | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/components/HeaderForm.test.js diff --git a/src/components/HeaderForm.test.js b/src/components/HeaderForm.test.js new file mode 100644 index 00000000..5010b55f --- /dev/null +++ b/src/components/HeaderForm.test.js @@ -0,0 +1,66 @@ +import { regionStringFromRegionIndex } from "./HeaderForm"; +import { parseRegion } from "../common.mjs"; + +const determineRegionIndexTest = (regionString, regionInfo) => { + let parsedRegion; + try { + parsedRegion = parseRegion(regionString); + } catch(error) { + return null; + } + if (!regionInfo["chr"]){ + return null; + } + for (let i = 0; i < regionInfo["chr"].length; i++){ + if ((parseInt(regionInfo["start"][i]) === parsedRegion.start) + && (parseInt(regionInfo["end"][i]) === parsedRegion.end) + && (regionInfo["chr"][i] === parsedRegion.contig)){ + return i; + } + } + return null; +} + +// const regionStringFromRegionIndex = (regionString, regionInfo) => { + +// test for determineRegionIndex and regionStringFromRegionIndex +describe("determine regionIndex and corresponding strings for various region inputs", () => { + // TEST #1 + it("determine regionIndex and regionString for input of ref:2000-3000", async () => { + let regionInfo = { + chr: [ 'ref', 'ref' ], + start: [ '1000', '2000' ], + end: [ '2000', '3000' ], + desc: [ '17_1_100', 'ref_2000_3000' ], + chunk: [ '', '' ], + tracks: [ null, null ] + } + let regionString = "ref:2000-3000"; + let regionIndex = determineRegionIndexTest(regionString, regionInfo); + expect(regionIndex).toBe(1); + //console.log("regionStringFromRegionIndex(1): ", regionStringFromRegionIndex(regionIndex)); + //expect(regionStringFromRegionIndex(regionIndex)).toBe("ref:2000-3000"); + }) + // TEST #2 + it("determine regionIndex and regionString for input of ref:4000-5000", async () => { + let regionInfo = { + chr: [ '17', 'ref', '17', 'ref', '17', 'ref' ], + start: [ '100', '200', '2000', '3000', '4000', '5000' ], + end: [ '200', '300', '3000', '4000', '5000', '6000' ], + desc: [ '17_100_200', '17_200_300', 'ref_2000_3000', 'ref_3000_4000', 'ref_4000_5000', 'ref_5000_6000' ], + chunk: [ '', '', '', '', '', '', '' ], + tracks: [ null, null, null, null, null, null ] + } + let regionString = "17:4000-5000"; + let regionIndex = determineRegionIndexTest(regionString, regionInfo); + expect(regionIndex).toBe(4); + //console.log("regionStringFromRegionIndex(1): ", regionStringFromRegionIndex(regionIndex)); + //expect(regionStringFromRegionIndex(regionIndex)).toBe("ref:2000-3000"); + }) +}); + + +// test for determineRegionIndex and regionStringFromRegionIndex +describe("determine regionIndex for input of ref:2000-3000", () => { + +}); \ No newline at end of file From 256454ca9354616de28e095c74768cf67f498b57 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Tue, 23 Jan 2024 08:55:56 -0800 Subject: [PATCH 8/8] completed test for determineRegionIndex and regionStringFromRegionIndex functions, and modified original functions to accept a regionInfo argument --- src/components/HeaderForm.js | 138 +++++++++++++++++------------- src/components/HeaderForm.test.js | 74 ++++++++-------- 2 files changed, 115 insertions(+), 97 deletions(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 898781a0..14bf7b8a 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -188,6 +188,77 @@ function viewTargetsEqual(currViewTarget, nextViewTarget) { return true; } +/* determine the current region: accepts a region string and returns the region index + + example of regionInfo: + { + chr: [ '17', '17' ], + start: [ '1', '1000' ], + end: [ '100', '1200' ], + desc: [ '17_1_100', '17_1000_1200' ], + chunk: [ '', '' ], + tracks: [ null, null ] + } + + examples: + if the regionString is "17:1-100", it would be parsed into {contig: "17", start: 1, end: 100} -> 0 + if the regionString is "17:1000-1200", it would be parsed into {contig: "17", start: 1000, end: 1200} -> 1 + if the regionString is "17:2000-3000", it cannot be found - return null + + The function uses this approach to find the regionIndex given regionString and regionInfo: + function (region string){ + parse(region string) -> return {contig, start, end} + loop over chr in region info + determine if contig, start, end are present at the current index + if present: return index + return null + } +*/ +export const determineRegionIndex = (regionString, regionInfo) => { + let parsedRegion; + try { + parsedRegion = parseRegion(regionString); + } catch(error) { + return null; + } + if (!regionInfo["chr"]){ + return null; + } + for (let i = 0; i < regionInfo["chr"].length; i++){ + if ((parseInt(regionInfo["start"][i]) === parsedRegion.start) + && (parseInt(regionInfo["end"][i]) === parsedRegion.end) + && (regionInfo["chr"][i] === parsedRegion.contig)){ + return i; + } + } + return null; +} + +/* + This function takes in a regionIndex and regionInfo, and reconstructs a regionString from them + assumes that index is valid in regionInfo + + example of regionInfo: + { + chr: [ '17', '17' ], + start: [ '1', '1000' ], + end: [ '100', '1200' ], + desc: [ '17_1_100', '17_1000_1200' ], + chunk: [ '', '' ], + tracks: [ null, null ] + } + + example of regionIndex: 0 + + example of regionString: "17:1-100" +*/ +export const regionStringFromRegionIndex = (regionIndex, regionInfo) => { + let regionStart = regionInfo["start"][regionIndex]; + let regionEnd = regionInfo["end"][regionIndex]; + let regionContig = regionInfo["chr"][regionIndex]; + return regionContig + ":" + regionStart + "-" + regionEnd; +} + class HeaderForm extends Component { state = EMPTY_STATE; componentDidMount() { @@ -521,61 +592,8 @@ class HeaderForm extends Component { return regionString; }; - // determine the current region: accepts a region string and returns the region index - /* - { - chr: [ '17', '17' ], - start: [ '1', '1000' ], - end: [ '100', '1200' ], - desc: [ '17_1_100', '17_1000_1200' ], - chunk: [ '', '' ], - tracks: [ null, null ] - } - 17:1-100 -> parse -> {contig: "17", start: 1, end: 100} -> 0 - 17:1000-1200 -> parse -> {contig: "17", start: 1000, end: 1200} -> 1 - 17:2000-3000 - cannot be found - return null - */ - - /* - function (region string){ - parse(region string) -> return {contig, start, end} - loop over chr in region info - determine if contig, start, end are present at the current index - if present: return index - return null - } - */ - - determineRegionIndex = (regionString) => { - console.log("state:", this.state); - let parsedRegion; - try { - parsedRegion = parseRegion(regionString); - } catch(error) { - return null; - } - if (!this.state.regionInfo["chr"]){ - return null; - } - for (let i = 0; i < this.state.regionInfo["chr"].length; i++){ - if ((parseInt(this.state.regionInfo["start"][i]) === parsedRegion.start) - && (parseInt(this.state.regionInfo["end"][i]) === parsedRegion.end) - && (this.state.regionInfo["chr"][i] === parsedRegion.contig)){ - return i; - } - } - return null; - } - - // reverse of previous function - // assumes that index is valid in regionInfo - regionStringFromRegionIndex = (regionIndex) => { - let regionStart = this.state.regionInfo["start"][regionIndex]; - let regionEnd = this.state.regionInfo["end"][regionIndex]; - let regionContig = this.state.regionInfo["chr"][regionIndex]; - return regionContig + ":" + regionStart + "-" + regionEnd; - } - + + // In addition to a new region value, also takes tracks and chunk associated with the region // Update current track if the new tracks are valid @@ -704,11 +722,11 @@ class HeaderForm extends Component { /* Offset the region left or right by the given negative or positive fraction*/ // offset: +1 or -1 jumpRegion(offset) { - let regionIndex = this.determineRegionIndex(this.state.region) ?? 0; + let regionIndex = determineRegionIndex(this.state.region, this.state.regionInfo) ?? 0; if ((offset === -1 && this.canGoLeft(regionIndex)) || (offset === 1 && this.canGoRight(regionIndex))){ regionIndex += offset; } - let regionString = this.regionStringFromRegionIndex(regionIndex); + let regionString = regionStringFromRegionIndex(regionIndex, this.state.regionInfo); this.setState( (state) => ({ region: regionString, @@ -854,11 +872,13 @@ class HeaderForm extends Component { uploadInProgress={this.state.uploadInProgress} getCurrentViewTarget={this.props.getCurrentViewTarget} viewTargetHasChange={viewTargetHasChange} - canGoLeft={this.canGoLeft(this.determineRegionIndex(this.state.region))} - canGoRight={this.canGoRight(this.determineRegionIndex(this.state.region))} + canGoLeft={this.canGoLeft(determineRegionIndex(this.state.region, this.state.regionInfo))} + canGoRight={this.canGoRight(determineRegionIndex(this.state.region, this.state.regionInfo))} /> ); + + return (
diff --git a/src/components/HeaderForm.test.js b/src/components/HeaderForm.test.js index 5010b55f..a3e570e3 100644 --- a/src/components/HeaderForm.test.js +++ b/src/components/HeaderForm.test.js @@ -1,32 +1,10 @@ -import { regionStringFromRegionIndex } from "./HeaderForm"; -import { parseRegion } from "../common.mjs"; +import { determineRegionIndex, regionStringFromRegionIndex } from "./HeaderForm.js"; -const determineRegionIndexTest = (regionString, regionInfo) => { - let parsedRegion; - try { - parsedRegion = parseRegion(regionString); - } catch(error) { - return null; - } - if (!regionInfo["chr"]){ - return null; - } - for (let i = 0; i < regionInfo["chr"].length; i++){ - if ((parseInt(regionInfo["start"][i]) === parsedRegion.start) - && (parseInt(regionInfo["end"][i]) === parsedRegion.end) - && (regionInfo["chr"][i] === parsedRegion.contig)){ - return i; - } - } - return null; -} - -// const regionStringFromRegionIndex = (regionString, regionInfo) => { // test for determineRegionIndex and regionStringFromRegionIndex -describe("determine regionIndex and corresponding strings for various region inputs", () => { +describe("determine regionIndex and corresponding region strings for various region inputs", () => { // TEST #1 - it("determine regionIndex and regionString for input of ref:2000-3000", async () => { + it("determine regionIndex and regionString for smaller regionInfo lists", async () => { let regionInfo = { chr: [ 'ref', 'ref' ], start: [ '1000', '2000' ], @@ -36,13 +14,12 @@ describe("determine regionIndex and corresponding strings for various region inp tracks: [ null, null ] } let regionString = "ref:2000-3000"; - let regionIndex = determineRegionIndexTest(regionString, regionInfo); + let regionIndex = determineRegionIndex(regionString, regionInfo); expect(regionIndex).toBe(1); - //console.log("regionStringFromRegionIndex(1): ", regionStringFromRegionIndex(regionIndex)); - //expect(regionStringFromRegionIndex(regionIndex)).toBe("ref:2000-3000"); + expect(regionStringFromRegionIndex(regionIndex, regionInfo)).toBe("ref:2000-3000"); }) // TEST #2 - it("determine regionIndex and regionString for input of ref:4000-5000", async () => { + it("determine regionIndex and regionString for larger regionInfo lists", async () => { let regionInfo = { chr: [ '17', 'ref', '17', 'ref', '17', 'ref' ], start: [ '100', '200', '2000', '3000', '4000', '5000' ], @@ -52,15 +29,36 @@ describe("determine regionIndex and corresponding strings for various region inp tracks: [ null, null, null, null, null, null ] } let regionString = "17:4000-5000"; - let regionIndex = determineRegionIndexTest(regionString, regionInfo); + let regionIndex = determineRegionIndex(regionString, regionInfo); expect(regionIndex).toBe(4); - //console.log("regionStringFromRegionIndex(1): ", regionStringFromRegionIndex(regionIndex)); - //expect(regionStringFromRegionIndex(regionIndex)).toBe("ref:2000-3000"); + expect(regionStringFromRegionIndex(regionIndex, regionInfo)).toBe("17:4000-5000"); + }) + // TEST #3 + it("determine regionIndex to be null for input of region not found in regionInfo", async () => { + let regionInfo = { + chr: [ '17', 'ref', '17', 'ref', '17', 'ref' ], + start: [ '100', '200', '2000', '3000', '4000', '5000' ], + end: [ '200', '300', '3000', '4000', '5000', '6000' ], + desc: [ '17_100_200', '17_200_300', 'ref_2000_3000', 'ref_3000_4000', 'ref_4000_5000', 'ref_5000_6000' ], + chunk: [ '', '', '', '', '', '', '' ], + tracks: [ null, null, null, null, null, null ] + } + let regionString = "17:5000-7000"; + let regionIndex = determineRegionIndex(regionString, regionInfo); + expect(regionIndex).toBe(null); + }) + // TEST #4 + it("determine regionIndex and regionString to be null given empty regionInfo", async () => { + let regionInfo = { + chr: [], + start: [], + end: [], + desc: [], + chunk: [], + tracks: [] + } + let regionString = "17:5000-7000"; + let regionIndex = determineRegionIndex(regionString, regionInfo); + expect(regionIndex).toBe(null); }) }); - - -// test for determineRegionIndex and regionStringFromRegionIndex -describe("determine regionIndex for input of ref:2000-3000", () => { - -}); \ No newline at end of file