Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formalize system of using 'none' in bedFile to fix left and right buttons without BED #402

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/components/HeaderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const CLEAR_STATE = {
pathNames: [],

tracks: {},
// BED file of regions to jump between. Regions may have pre-extracted chunks in the last column.
// If not used, may be undefined or may have the sting value "none".
bedFile: undefined,
region: "",
name: undefined,
Expand All @@ -94,6 +96,12 @@ const EMPTY_STATE = {
bedSelectOptions: [],
};

// Return true if file is set to a string file name or URL, and false if it is
// falsey or the "none" sentinel.
function isSet(file) {
return (file !== "none" && file);
}

// Creates track to be stored in ViewTarget
// Modify as the track system changes
// INPUT: file structure, see Types.ts
Expand Down Expand Up @@ -289,7 +297,7 @@ class HeaderForm extends Component {
initState = () => {
// Populate state with either viewTarget or the first example
let ds = this.props.defaultViewTarget ?? DATA_SOURCES[0];
const bedSelect = ds.bedFile ? ds.bedFile : "none";
const bedSelect = isSet(ds.bedFile) ? ds.bedFile : "none";
if (bedSelect !== "none") {
this.getBedRegions(bedSelect);
}
Expand Down Expand Up @@ -317,7 +325,7 @@ class HeaderForm extends Component {
setTrackFile = (type, index, file) => {
// Set the nth track of the given type to the given file.
// If there is no nth track of that type, create one.
// If the file is "none", remove that track.
// If the file is unset, remove that track.
this.setState((state) => {
console.log(
"Set file " +
Expand All @@ -340,13 +348,13 @@ class HeaderForm extends Component {
let track = state.tracks[key];
if (track.trackType === type) {
if (seenTracksOfType === index) {
if (file !== "none") {
if (isSet(file)) {
// We want to adjust it, so keep a modified copy of it
let newTrack = JSON.parse(JSON.stringify(track));
newTrack.trackFile = file;
newTracks[key] = newTrack;
}
// If the file is "none" we drop the track.
// If the file is unset we drop the track.
} else {
// We want to keep it as is
newTracks[key] = track;
Expand All @@ -364,7 +372,7 @@ class HeaderForm extends Component {
console.log(
"Saw " + seenTracksOfType + " tracks of type vs index " + index
);
if (seenTracksOfType === index && file !== "none") {
if (seenTracksOfType === index && isSet(file)) {
// We need to add this track
console.log("Create track at index " + (maxKey + 1));
newTracks[maxKey + 1] = createTrack({ type: type, name: file });
Expand All @@ -379,8 +387,8 @@ class HeaderForm extends Component {
};

getTrackFile = (tracks, type, index) => {
// Get the file used in the nth track of the gicen type, or "none" if no
// such track exists.
// Get the file used in the nth track of the given type, or the unset
// "none" sentinel if no such track exists.
let seenTracksOfType = 0;
for (const key in tracks) {
let track = tracks[key];
Expand Down Expand Up @@ -416,7 +424,7 @@ class HeaderForm extends Component {
const bedSelect = json.bedFiles.includes(state.bedSelect)
? state.bedSelect
: "none";
if (bedSelect !== "none") {
if (isSet(bedSelect)) {
this.getBedRegions(bedSelect);
}
for (const key in state.tracks) {
Expand Down Expand Up @@ -515,7 +523,7 @@ class HeaderForm extends Component {
DATA_SOURCES.forEach((ds) => {
if (ds.name === value) {
let bedSelect = "none";
if (ds.bedFile) {
if (isSet(ds.bedFile)) {
this.getBedRegions(ds.bedFile);
bedSelect = ds.bedFile;
} else {
Expand Down Expand Up @@ -648,7 +656,7 @@ class HeaderForm extends Component {
if (tracks) {
this.setState({ tracks: this.convertArrayToObject(tracks) });
console.log("New tracks have been applied");
} else if (this.state.bedFile && chunk) {
} else if (isSet(this.state.bedFile) && chunk) {
// Try to retrieve tracks from the server
const json = await this.api.getChunkTracks(
this.state.bedFile,
Expand Down Expand Up @@ -681,7 +689,7 @@ class HeaderForm extends Component {

// update path names
const graphFile = this.getTrackFile(newTracks, fileTypes.GRAPH, 0);
if (graphFile && graphFile !== "none") {
if (isSet(graphFile)) {
this.getPathNames(graphFile);
}
};
Expand All @@ -691,7 +699,7 @@ class HeaderForm extends Component {
const value = event.target.value;
this.setState({ [id]: value });

if (value !== "none") {
if (isSet(value)) {
this.getBedRegions(value);
}
this.setState({ bedFile: value });
Expand Down Expand Up @@ -737,15 +745,15 @@ class HeaderForm extends Component {
}

canGoLeft = (regionIndex) => {
if (this.state.bedFile){
if (isSet(this.state.bedFile)){
return (regionIndex > 0);
} else {
return true;
}
}

canGoRight = (regionIndex) => {
if (this.state.bedFile){
if (isSet(this.state.bedFile)){
if (!this.state.regionInfo["chr"]){
return false;
}
Expand All @@ -757,15 +765,15 @@ class HeaderForm extends Component {


handleGoRight = () => {
if (this.state.bedFile){
if (isSet(this.state.bedFile)){
this.jumpRegion(1);
} else {
this.budgeRegion(0.5);
}
};

handleGoLeft = () => {
if (this.state.bedFile){
if (isSet(this.state.bedFile)){
this.jumpRegion(-1);
} else {
this.budgeRegion(-0.5);
Expand Down
Loading