Skip to content

Commit

Permalink
support "displayMode" for json genomes. Fixes #1308 (#1386)
Browse files Browse the repository at this point in the history
support "displayMode" for json genomes.  Fixes #1308
  • Loading branch information
jrobinso authored Sep 2, 2023
1 parent 89a3195 commit a060dab
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.fasta.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.fasta.FastaIndexedSequence;
import org.broad.igv.track.Track;
import org.broad.igv.track.TrackProperties;
import org.broad.igv.track.TribbleFeatureSource;
import org.broad.igv.ui.color.ColorUtilities;
import org.broad.igv.util.FileUtils;
Expand Down Expand Up @@ -110,27 +112,56 @@ public Genome loadGenome() throws IOException {
res.setFormat(format.getAsString().toLowerCase());
}

// JsonElement colorBy = obj.get("colorBy");
// if (altColor != null) {
// try {
// properties.colorBy(ColorUtilities.stringToColor(colorBy.toString()));
// } catch (Exception e) {
// log.error("Error parsing color string: " + altColor.toString(), e);
// }
// }

JsonElement infoURL = obj.get("infoURL");
if (infoURL != null) {
res.setFeatureInfoURL(infoURL.getAsString());
}


// Track properties
TrackProperties properties = new TrackProperties();
JsonElement color = obj.get("color");
if (color != null) {
try {
res.setColor(ColorUtilities.stringToColor(color.toString()));
properties.setColor(ColorUtilities.stringToColor(color.toString()));
} catch (Exception e) {
log.error("Error parsing color string: " + color.toString(), e);
log.error("Error parsing color string: " + color, e);
}
}
JsonElement altColor = obj.get("altColor");
if (altColor != null) {
try {
properties.setAltColor(ColorUtilities.stringToColor(altColor.toString()));
} catch (Exception e) {
log.error("Error parsing color string: " + altColor, e);
}
}
JsonElement displayMode = obj.get("displayMode");
if (displayMode != null) {
try {
Track.DisplayMode dp = Track.DisplayMode.valueOf(stripQuotes(displayMode.toString()));
properties.setDisplayMode(dp);
} catch (Exception e) {
log.error("Error parsing displayMode " + displayMode, e);
}
}

JsonElement vizwindow = obj.get("visibilityWindow");
if (vizwindow != null) {
res.setVisibilityWindow(obj.get("visibilityWindow").getAsInt());
properties.setFeatureVisibilityWindow(obj.get("visibilityWindow").getAsInt());
} else {
// If not explicitly set, assume whole chromosome viz window for annotations
res.setVisibilityWindow(-1);
}

JsonElement infoURL = obj.get("infoURL");
if (infoURL != null) {
res.setFeatureInfoURL(infoURL.getAsString());
properties.setFeatureVisibilityWindow(-1);
}
res.setTrackProperties(properties);

JsonElement indexedElement = obj.get("indexed");
JsonElement hiddenElement = obj.get("hidden");
Expand All @@ -139,7 +170,6 @@ public Genome loadGenome() throws IOException {
if (indexedElement != null) {
res.setIndexed(indexed);
}

if (hidden) {
if (indexed || trackIndex != null) {
log.warn("Hidden tracks cannot be indexed. Ignoring " + trackPath);
Expand All @@ -149,6 +179,7 @@ public Genome loadGenome() throws IOException {
} else {
tracks.add(res);
}

});
}

Expand Down Expand Up @@ -267,6 +298,15 @@ private void addToFeatureDB(List<ResourceLocator> locators, Genome genome) {
}
}

private String stripQuotes(String str) {
if(str.startsWith("\"")) {
return str.substring(1, str.length() - 1); // Assume also ends with
}
else {
return str;
}
}

public static class GenomeDescriptor {
String id;
String name;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,11 @@ public List<Track> load(ResourceLocator locator) throws DataLoadException {
track.setAttributeValue(Globals.TRACK_NAME_ATTRIBUTE, track.getName());
track.setAttributeValue(Globals.TRACK_DATA_FILE_ATTRIBUTE, fn);
track.setAttributeValue(Globals.TRACK_DATA_TYPE_ATTRIBUTE, track.getTrackType().toString());

TrackProperties properties = locator.getTrackProperties();
if(properties != null) {
track.setProperties(properties);
}
}
}
//revalidateTrackPanels();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/broad/igv/util/ResourceLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import htsjdk.tribble.Tribble;
import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.track.TrackProperties;

import java.awt.*;
import java.io.File;
Expand Down Expand Up @@ -104,12 +105,13 @@ public class ResourceLocator {
*/
public String format;


/**
* A UCSC style track line. Overrides value in file, if any.
*/
String trackLine; //

TrackProperties trackProperties;

/**
* Color for features or data. Somewhat redundant with trackLine.
*/
Expand Down Expand Up @@ -399,6 +401,13 @@ public String getTrackName() {
}
}

public TrackProperties getTrackProperties() {
return trackProperties;
}

public void setTrackProperties(TrackProperties trackProperties) {
this.trackProperties = trackProperties;
}

public void setName(String name) {
this.name = name;
Expand Down

0 comments on commit a060dab

Please sign in to comment.