Skip to content

Commit

Permalink
combine "feature" and "data" panels
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Dec 6, 2023
1 parent ea9d595 commit 56b7d30
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 154 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/broad/igv/feature/genome/GenomeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
import java.util.*;
import java.util.List;

import static org.broad.igv.prefs.Constants.SHOW_SINGLE_TRACK_PANE_KEY;

/**
* @author jrobinso
*/
Expand Down Expand Up @@ -170,6 +168,8 @@ public void loadGenomeById(String genomeId) throws IOException {

loadGenome(genomePath); // monitor[0]);

IGV.getInstance().getMainPanel().removeEmptyPanels();

}


Expand Down Expand Up @@ -269,8 +269,7 @@ public void restoreGenomeTracks(Genome genome) {
// Fetch the gene track, defined by .genome files. In this format the genome data is encoded in the .genome file
FeatureTrack geneFeatureTrack = genome.getGeneTrack(); // Can be null
if (geneFeatureTrack != null) {
PanelName panelName = PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY) ?
PanelName.DATA_PANEL : PanelName.FEATURE_PANEL;
PanelName panelName = PanelName.FEATURE_PANEL;
geneFeatureTrack.setAttributeValue(Globals.TRACK_NAME_ATTRIBUTE, geneFeatureTrack.getName());
geneFeatureTrack.setAttributeValue(Globals.TRACK_DATA_FILE_ATTRIBUTE, "");
geneFeatureTrack.setAttributeValue(Globals.TRACK_DATA_TYPE_ATTRIBUTE, geneFeatureTrack.getTrackType().toString());
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/org/broad/igv/session/IGVSessionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@
public class IGVSessionReader implements SessionReader {

private static Logger log = LogManager.getLogger(IGVSessionReader.class);
private static String INPUT_FILE_KEY = "INPUT_FILE_KEY";
private static Map<String, String> attributeSynonymMap = new HashMap();
private static WeakReference<IGVSessionReader> currentReader;

private IGV igv;
private int version;
private String genomePath;
Expand Down Expand Up @@ -115,13 +113,11 @@ public class IGVSessionReader implements SessionReader {
attributeSynonymMap.put("TRACK NAME", "NAME");
}


public IGVSessionReader(IGV igv) {
this.igv = igv;
currentReader = new WeakReference<IGVSessionReader>(this);
}


/**
* @param inputStream
* @param session
Expand Down Expand Up @@ -174,9 +170,7 @@ public void loadSession(InputStream inputStream, Session session, String session
igv.setGroupByAttribute(session.getGroupTracksBy());
}

if (session.isRemoveEmptyPanels()) {
igv.getMainPanel().removeEmptyDataPanels();
}
igv.getMainPanel().removeEmptyPanels();

igv.resetOverlayTracks();

Expand Down Expand Up @@ -252,16 +246,6 @@ private void processRootNode(Session session, Node node, String sessionPath) {
}
}

String removeEmptyTracks = getAttribute(rootElement, "removeEmptyTracks");
if (removeEmptyTracks != null) {
try {
Boolean b = Boolean.parseBoolean(removeEmptyTracks);
session.setRemoveEmptyPanels(b);
} catch (Exception e) {
log.error("Error parsing removeEmptyTracks string: " + removeEmptyTracks, e);
}
}

session.setVersion(version);
NodeList elements = rootElement.getChildNodes();
process(session, elements, sessionPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.List;
import java.util.Map;

import static org.broad.igv.ui.IGV.DATA_PANEL_NAME;
import static org.broad.igv.ui.IGV.FEATURE_PANEL_NAME;

/**
* Class to parse an index aware session file
Expand Down Expand Up @@ -124,7 +124,7 @@ public void loadSession(InputStream inputStream, Session session, String session
if (isAlignmentFile(locator.getPath())) {
TrackPanel panel = igv.getPanelFor(locator);
if (panel == null) {
panel = igv.getTrackPanel(DATA_PANEL_NAME);
panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
}
panel.addTracks(igv.load(locator));
} else {
Expand Down Expand Up @@ -201,7 +201,7 @@ private void placeTracksInPanels(List<ResourceLocator> locatorPaths, Map<String,
for (ResourceLocator loc : locatorPaths) {
//TrackPanel panel = IGV.getInstance().getPanelFor(new ResourceLocator(path));
// If loading from an index aware session use a single panel
TrackPanel panel = igv.getTrackPanel(DATA_PANEL_NAME);
TrackPanel panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
String path = loc.getPath();
if (loadedTracks.containsKey(path)) {
panel.addTracks(loadedTracks.get(path));
Expand Down
63 changes: 0 additions & 63 deletions src/main/java/org/broad/igv/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public enum GeneListMode {
private TrackFilter filter;
private HashMap<String, String> preferences;
private HashMap<TrackType, ContinuousColorScale> colorScales;
private boolean removeEmptyPanels = false;
double[] dividerFractions = null;

/**
Expand Down Expand Up @@ -458,68 +457,6 @@ public void setHiddenAttributes(Set<String> attributes) {

}

public boolean isRemoveEmptyPanels() {
return removeEmptyPanels;
}

public void setRemoveEmptyPanels(boolean removeEmptyPanels) {
this.removeEmptyPanels = removeEmptyPanels;
}


static class Locus {
String chr;
int start;
int end;

Locus(String chr, int start, int end) {
this.chr = chr;
this.start = start;
this.end = end;
}

}


/**
* Return the start and end positions as a 2 element array for the input
* position string. UCSC conventions are followed for coordinates,
* specifically the internal representation is "zero" based (first base is
* numbered 0) but the display representation is "one" based (first base is
* numbered 1). Consequently, 1 is subtracted from the parsed positions
*/
private static int[] getStartEnd(String posString) {
try {
String[] posTokens = posString.split("-");
String startString = posTokens[0].replaceAll(",", "");
int start = Math.max(0, Integer.parseInt(startString)) - 1;

// Default value for end

int end = start + 1;
if (posTokens.length > 1) {
String endString = posTokens[1].replaceAll(",", "");
end = Integer.parseInt(endString);
}

if (posTokens.length == 1 || (end - start) < 10) {
int center = (start + end) / 2;
start = center - 20;
end = center + 20;
} else {
String endString = posTokens[1].replaceAll(",", "");

// Add 1 bp to end position t make it "inclusive"
end = Integer.parseInt(endString);
}

return new int[]{Math.min(start, end), Math.max(start, end)};
} catch (NumberFormatException numberFormatException) {
return null;
}

}

/**
* Allows access to the Observable that notifies of changes to the regions of interest
*
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/broad/igv/session/SessionWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ public String createXmlFromSession(Session session, File outputFile) throws Runt
globalElement.setAttribute(SessionAttribute.NEXT_AUTOSCALE_GROUP, String.valueOf(nextAutoscaleGroup));
}

if (session.isRemoveEmptyPanels()) {
globalElement.setAttribute("removeEmptyTracks", "true");
}

// Resource Files
writeResources(outputFile, globalElement, document);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/broad/igv/session/UCSCSessionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.List;
import java.util.Map;

import static org.broad.igv.ui.IGV.DATA_PANEL_NAME;
import static org.broad.igv.ui.IGV.FEATURE_PANEL_NAME;

/**
* Class to parse a UCSC session file
Expand Down Expand Up @@ -114,7 +114,7 @@ public void loadSession(InputStream inputStream, Session session, String session
if (isAlignmentFile(locator.getPath())) {
TrackPanel panel = igv.getPanelFor(locator);
if (panel == null) {
panel = igv.getTrackPanel(DATA_PANEL_NAME);
panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
}
panel.addTracks(igv.load(locator));
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ private void placeTracksInPanels(List<ResourceLocator> locatorPaths, Map<String,
for (ResourceLocator loc : locatorPaths) {
//TrackPanel panel = IGV.getInstance().getPanelFor(new ResourceLocator(path));
// If loading from UCSC use a single panel
TrackPanel panel = igv.getTrackPanel(IGV.DATA_PANEL_NAME);
TrackPanel panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
String path = loc.getPath();
if (loadedTracks.containsKey(path)) {
panel.addTracks(loadedTracks.get(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ private void okButtonActionPerformed(ActionEvent e) {
CombinedDataSource dataSource = (new CombinedDataSource(track0, track1, op));
CombinedDataTrack newTrack = new CombinedDataTrack(dataSource, id, name);


TrackMenuUtils.changeRendererClass(Arrays.asList(newTrack), track0.getRenderer().getClass());
newTrack.setDataRange(track0.getDataRange());
newTrack.setColorScale(track0.getColorScale());
IGV.getInstance().addTracks(Arrays.asList(newTrack), PanelName.DATA_PANEL);
IGV.getInstance().addTracks(Arrays.asList(newTrack), PanelName.FEATURE_PANEL);
this.setVisible(false);

}
Expand Down
55 changes: 23 additions & 32 deletions src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ public class IGV implements IGVEventObserver {
private static Logger log = LogManager.getLogger(IGV.class);
private static IGV theInstance;

public static final String DATA_PANEL_NAME = "DataPanel";
public static final String FEATURE_PANEL_NAME = "FeaturePanel";
// Cursors
public static Cursor fistCursor;
public static Cursor zoomInCursor;
public static Cursor zoomOutCursor;
public static Cursor dragNDropCursor;


public static final String FEATURE_PANEL_NAME = "FeatureTrackPanel";

// Window components
private Frame mainFrame;
Expand All @@ -114,14 +120,9 @@ public class IGV implements IGVEventObserver {
private StatusWindow statusWindow;

// Glass panes
Component glassPane;
GhostGlassPane dNdGlassPane;
private Component glassPane;
private GhostGlassPane dNdGlassPane;

// Cursors
public static Cursor fistCursor;
public static Cursor zoomInCursor;
public static Cursor zoomOutCursor;
public static Cursor dragNDropCursor;

/**
* Object to hold state that defines a user session. There is always a user session, even if not initialized
Expand All @@ -142,11 +143,11 @@ public class IGV implements IGVEventObserver {
// Vertical line that follows the mouse
private boolean rulerEnabled;

public static IGV createInstance(Frame frame, Main.IGVArgs igvArgs) {
public static IGV createInstance(Frame frame) {
if (theInstance != null) {
throw new RuntimeException("Only a single instance is allowed.");
}
theInstance = new IGV(frame, igvArgs);
theInstance = new IGV(frame);
return theInstance;
}

Expand All @@ -170,7 +171,7 @@ static void destroyInstance() {
/**
* Creates new IGV
*/
private IGV(Frame frame, Main.IGVArgs igvArgs) {
private IGV(Frame frame) {

theInstance = this;

Expand Down Expand Up @@ -838,7 +839,6 @@ public boolean isFilterShowAllTracks() {
* Add a new data panel set
*/
public TrackPanelScrollPane addDataPanel(String name) {

return contentPane.getMainPanel().addDataPanel(name);
}

Expand Down Expand Up @@ -1284,7 +1284,7 @@ public void load(final ResourceLocator locator, final TrackPanel panel) throws D
public TrackPanel getPanelFor(Track track) {

if (PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY)) {
return getTrackPanel(DATA_PANEL_NAME);
return getTrackPanel(FEATURE_PANEL_NAME);
}

ResourceLocator locator = track.getResourceLocator();
Expand All @@ -1294,12 +1294,8 @@ public TrackPanel getPanelFor(Track track) {
return panel;
}
}
return getTrackPanel(FEATURE_PANEL_NAME);

if (track.getClass() == FeatureTrack.class && !PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY))
return getTrackPanel(FEATURE_PANEL_NAME);
else {
return getTrackPanel(DATA_PANEL_NAME);
}
}

/**
Expand All @@ -1315,20 +1311,16 @@ public TrackPanel getPanelFor(ResourceLocator locator) {
if ("alist".equals(format)) {
return getVcfBamPanel();
} else if (PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY)) {
return getTrackPanel(DATA_PANEL_NAME);
return getTrackPanel(FEATURE_PANEL_NAME);
} else if (TrackLoader.isAlignmentTrack(format)) {
String newPanelName = "Panel" + System.currentTimeMillis();
return addDataPanel(newPanelName).getTrackPanel();
} else if (isAnnotationFile(format)) {
return getTrackPanel(FEATURE_PANEL_NAME);
} else {
if (format != null && format.equalsIgnoreCase("das")) {
return getTrackPanel(FEATURE_PANEL_NAME);
}
if (isAnnotationFile(format)) {
return getTrackPanel(FEATURE_PANEL_NAME);
} else {
return null; // Can't determine from locator
}
return null; // Can't determine from locator
}

}

public Set<TrackType> getLoadedTypes() {
Expand Down Expand Up @@ -1361,8 +1353,8 @@ public TrackPanel getVcfBamPanel() {
private boolean isAnnotationFile(String format) {
Set<String> annotationFormats = new HashSet<>(Arrays.asList("refflat", "ucscgene",
"genepred", "ensgene", "refgene", "gff", "gtf", "gff3", "embl", "bed", "gistic",
"bedz", "repmask", "dranger", "ucscsnp", "genepredext", "bigbed"));
return annotationFormats.contains(format);
"bedz", "repmask", "dranger", "ucscsnp", "genepredext", "bigbed", "das"));
return annotationFormats.contains(format.toLowerCase());
}


Expand Down Expand Up @@ -1652,8 +1644,7 @@ public void deleteTracks(Collection<? extends Track> tracksToRemove) {
*/
public void setSequenceTrack() {

TrackPanel panel = PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY) ?
getTrackPanel(DATA_PANEL_NAME) : getTrackPanel(FEATURE_PANEL_NAME);
TrackPanel panel = getTrackPanel(FEATURE_PANEL_NAME);
SequenceTrack newSeqTrack = new SequenceTrack("Reference sequence");
panel.addTrack(newSeqTrack);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void windowGainedFocus(WindowEvent windowEvent) {
SeekableStreamFactory.setInstance(IGVSeekableStreamFactory.getInstance());

// Start IGV's UI itself (frame) and other components
IGV igv = IGV.createInstance(frame, igvArgs);
IGV igv = IGV.createInstance(frame);

igv.startUp(igvArgs);

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/broad/igv/ui/PanelName.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* @api
*/
public enum PanelName {
FEATURE_PANEL(IGV.FEATURE_PANEL_NAME),
DATA_PANEL(IGV.DATA_PANEL_NAME);
FEATURE_PANEL(IGV.FEATURE_PANEL_NAME);

private final String panelName;

Expand Down
Loading

0 comments on commit 56b7d30

Please sign in to comment.