From 5039460b1da05190338acf8ca0a0c2304557a466 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Mon, 26 Feb 2024 09:20:41 -0800 Subject: [PATCH 1/3] added new function to convert array to object --- src/components/HeaderForm.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index ca0282d5..3f168ef6 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -598,6 +598,16 @@ class HeaderForm extends Component { } return null; } + + // Function to convert array to object, where the key would be the index and the value + // would be the value at the array index + convertArrayToObject = (array) => { + obj = new Object(); + for(let i = 0; i < array.length; i++){ + obj[i] = array[i]; + } + return obj; + } // Adopt a new region // Update the region description @@ -651,7 +661,8 @@ class HeaderForm extends Component { this.setState((laterState) => { if (laterState.region === coords) { // The user still has the same region selected, so apply the tracks we now have - return { tracks: json.tracks }; + console.log("json tracks: ", json.tracks) + return this.convertArrayToObject(json.tracks);//{ tracks: json.tracks }; } // Otherwise, don't apply the downloaded tracks, because they are no longer relevant. // TODO: Save the downloaded tracks in case the user selects the region again? From a92e7ba36789754b8db2008d40bdca0e9250b49c Mon Sep 17 00:00:00 2001 From: shreyasun Date: Tue, 27 Feb 2024 08:49:39 -0800 Subject: [PATCH 2/3] Accomodated carriage returns in bed file contents --- src/server.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.mjs b/src/server.mjs index 46f611bf..ed80e4d8 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -1753,7 +1753,7 @@ async function getBedRegions(bed) { bed_data = fs.readFileSync(bed).toString(); } - lines = bed_data.split("\n"); + lines = bed_data.split(/\r?\n/); lines.map(function (line) { let records = line.split("\t"); From b7f802a178ef402d76a0f0c1777051c2b69013f3 Mon Sep 17 00:00:00 2001 From: shreyasun Date: Wed, 28 Feb 2024 09:20:52 -0800 Subject: [PATCH 3/3] Added more instances of changing tracks array to object --- src/components/HeaderForm.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/HeaderForm.js b/src/components/HeaderForm.js index 3f168ef6..7b0e7c6c 100644 --- a/src/components/HeaderForm.js +++ b/src/components/HeaderForm.js @@ -602,7 +602,7 @@ class HeaderForm extends Component { // Function to convert array to object, where the key would be the index and the value // would be the value at the array index convertArrayToObject = (array) => { - obj = new Object(); + let obj = {}; for(let i = 0; i < array.length; i++){ obj[i] = array[i]; } @@ -646,7 +646,7 @@ class HeaderForm extends Component { // Override current tracks with new tracks from chunk dir if (tracks) { - this.setState({ tracks: tracks }); + this.setState({ tracks: this.convertArrayToObject(tracks) }); console.log("New tracks have been applied"); } else if (this.state.bedFile && chunk) { // Try to retrieve tracks from the server @@ -662,7 +662,7 @@ class HeaderForm extends Component { if (laterState.region === coords) { // The user still has the same region selected, so apply the tracks we now have console.log("json tracks: ", json.tracks) - return this.convertArrayToObject(json.tracks);//{ tracks: json.tracks }; + return {tracks: this.convertArrayToObject(json.tracks)}; } // Otherwise, don't apply the downloaded tracks, because they are no longer relevant. // TODO: Save the downloaded tracks in case the user selects the region again?