Skip to content

Commit

Permalink
Wrap tracks from multi-track formats (seg, vcf, tdf, igv) in a panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Dec 6, 2023
1 parent 56b7d30 commit 606dff3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public void loadSession(InputStream inputStream, Session session, String session
locator.setTrackLine(trackLine);
// Alignment tracks must be loaded synchronously
if (isAlignmentFile(locator.getPath())) {
TrackPanel panel = igv.getPanelFor(locator);
if (panel == null) {
panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
}
TrackPanel panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
panel.addTracks(igv.load(locator));
} else {
aSync.add(locator);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/broad/igv/session/UCSCSessionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ public void loadSession(InputStream inputStream, Session session, String session
locator.setTrackLine(trackLine);
// Alignment tracks must be loaded synchronously
if (isAlignmentFile(locator.getPath())) {
TrackPanel panel = igv.getPanelFor(locator);
if (panel == null) {
panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
}
TrackPanel panel = igv.getTrackPanel(FEATURE_PANEL_NAME);
panel.addTracks(igv.load(locator));
} else {
aSync.add(locator);
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/org/broad/igv/track/AbstractTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public abstract class AbstractTrack implements Track {

protected DataRange dataRange;
private boolean showFeatureNames = DEFAULT_SHOW_FEATURE_NAMES;
private String panelName;

public AbstractTrack() {
}
Expand Down Expand Up @@ -740,7 +741,7 @@ public ContinuousColorScale getColorScale() {
} else {
colorScale = new ContinuousColorScale(min, max, minColor, c);
}
colorScale.setNoDataColor(PreferencesManager.getPreferences().getAsColor(Constants.NO_DATA_COLOR));
colorScale.setNoDataColor(PreferencesManager.getPreferences().getAsColor(NO_DATA_COLOR));
}
return colorScale;
}
Expand Down Expand Up @@ -1180,4 +1181,13 @@ public void unmarshalXML(Element element, Integer version) {
}
}

@Override
public void setPanelName(String panelName) {
this.panelName = panelName;
}

@Override
public String getPanelName() {
return panelName;
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/broad/igv/track/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ default NamedFeature search(String token) {
return null;
}

public void setPanelName(String panelName);

public String getPanelName();

default void repaint() {
IGV.getInstance().repaint(this);
}
Expand Down
47 changes: 35 additions & 12 deletions src/main/java/org/broad/igv/track/TrackLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ private void loadVCFWithSource(ResourceLocator locator, FeatureSource src, List<

VariantTrack t = new VariantTrack(locator, src, allSamples, enableMethylationRateSupport);

if (t.getAllSamples().size() > 10) {
// Create a new panel if the number of genotypes is greater than 10
String newPanelName = "Panel" + System.currentTimeMillis();
t.setPanelName(newPanelName);
}

// VCF tracks handle their own margin
t.setMargin(0);
newTracks.add(t);
Expand Down Expand Up @@ -533,7 +539,6 @@ private void loadGctFile(ResourceLocator locator, List<Track> newTracks, Genome
return;
}
}

ExpressionFileParser parser = null;
ExpressionDataset ds = null;
parser = new ExpressionFileParser(locator, null, genome);
Expand All @@ -550,13 +555,7 @@ private void loadGctFile(ResourceLocator locator, List<Track> newTracks, Genome
ds.setNormalized(true);
ds.setLogValues(true);

/*
* File outputFile = new File(IGV.DEFAULT_USER_DIRECTORY, file.getName() + ".h5");
* OverlappingProcessor proc = new OverlappingProcessor(ds);
* proc.setZoomMax(0);
* proc.process(outputFile.getAbsolutePath());
* loadH5File(outputFile, messages, attributeList, group);
*/
String newPanelName = "Panel" + System.currentTimeMillis();

// Counter for generating ID
TrackProperties trackProperties = ds.getTrackProperties();
Expand All @@ -565,6 +564,7 @@ private void loadGctFile(ResourceLocator locator, List<Track> newTracks, Genome
DatasetDataSource dataSource = new DatasetDataSource(trackName, ds, genome);
String trackId = path + "_" + trackName;
DataSourceTrack track = new DataSourceTrack(locator, trackId, trackName, dataSource);
track.setPanelName(newPanelName);
track.setRenderer(new HeatmapRenderer());
track.setProperties(trackProperties);
newTracks.add(track);
Expand Down Expand Up @@ -599,6 +599,7 @@ private void loadIGVFile(ResourceLocator locator, List<Track> newTracks, Genome
}
}

String newPanelName = "Panel" + System.currentTimeMillis();

String dsName = locator.getTrackName();
IGVDataset ds = new IGVDataset(locator, genome);
Expand All @@ -607,13 +608,15 @@ private void loadIGVFile(ResourceLocator locator, List<Track> newTracks, Genome
TrackProperties trackProperties = ds.getTrackProperties();
String path = locator.getPath();
TrackType type = ds.getType();
boolean multitrack = ds.getTrackNames().length > 1;
for (String trackName : ds.getTrackNames()) {

DatasetDataSource dataSource = new DatasetDataSource(trackName, ds, genome);
String trackId = path + "_" + trackName;
DataSourceTrack track = new DataSourceTrack(locator, trackId, trackName, dataSource);
if (multitrack) {
track.setPanelName(newPanelName);
}

// track.setRendererClass(HeatmapRenderer.class);
track.setTrackType(ds.getType());
track.setProperties(trackProperties);

Expand Down Expand Up @@ -766,14 +769,17 @@ public void loadTDFFile(ResourceLocator locator, List<Track> newTracks, Genome g
int trackNumber = 0;
String path = locator.getPath();
boolean multiTrack = reader.getTrackNames().length > 1;
String newPanelName = "Panel" + System.currentTimeMillis();

for (String heading : reader.getTrackNames()) {

String trackId = multiTrack ? path + "_" + heading : path;
String trackName = multiTrack ? heading : name;
final DataSource dataSource = new TDFDataSource(reader, trackNumber, heading, genome);
DataSourceTrack track = new DataSourceTrack(locator, trackId, trackName, dataSource);

if (multiTrack) {
track.setPanelName(newPanelName);
}
String displayName = (name == null || multiTrack) ? heading : name;
track.setName(displayName);
track.setTrackType(type);
Expand Down Expand Up @@ -896,8 +902,15 @@ private void loadAlignmentsTrack(ResourceLocator locator, List<Track> newTracks,
}
}

// Place associated tracks in a new panel (coverage, splice junction, alignment)

String newPanelName = "Panel" + System.currentTimeMillis();

AlignmentTrack alignmentTrack = new AlignmentTrack(locator, dataManager, genome); // parser.loadTrack(locator, dsName)
alignmentTrack.setPanelName(newPanelName);
alignmentTrack.setVisible(PreferencesManager.getPreferences().getAsBoolean(SAM_SHOW_ALIGNMENT_TRACK));

alignmentTrack.getCoverageTrack().setPanelName(newPanelName);
newTracks.add(alignmentTrack.getCoverageTrack());

// Precalculated coverage data (can be null)
Expand Down Expand Up @@ -931,6 +944,7 @@ private void loadAlignmentsTrack(ResourceLocator locator, List<Track> newTracks,
}

// Splice junction track
alignmentTrack.getSpliceJunctionTrack().setPanelName(newPanelName);
newTracks.add(alignmentTrack.getSpliceJunctionTrack());

alignmentTrack.init();
Expand Down Expand Up @@ -985,9 +999,12 @@ private void showMismatchSequenceNameMessage(String filename, Genome genome, Lis
*/
private void loadMutFile(ResourceLocator locator, List<Track> newTracks, Genome genome) throws IOException, TribbleIndexNotFoundException {

String newPanelName = "Panel" + System.currentTimeMillis();

MutationTrackLoader loader = new MutationTrackLoader();
List<FeatureTrack> mutationTracks = loader.loadMutationTracks(locator, genome);
for (FeatureTrack track : mutationTracks) {
track.setPanelName(newPanelName);
track.setTrackType(TrackType.MUTATION);
track.setRenderer(new MutationRenderer());
newTracks.add(track);
Expand Down Expand Up @@ -1020,20 +1037,25 @@ private void loadSegFile(ResourceLocator locator, List<Track> newTracks, Genome
* @param ds
*/
private void loadSegTrack(ResourceLocator locator, List<Track> newTracks, Genome genome, SegmentedDataSet ds) {

String path = locator.getPath();

TrackProperties props = null;
if (ds instanceof SegmentedAsciiDataSet) {
props = ((SegmentedAsciiDataSet) ds).getTrackProperties();
}

// The "freq" track. TODO - make this optional

String newPanelName = "Panel" + System.currentTimeMillis();

// The "freq" track.
if ((ds.getType() == TrackType.COPY_NUMBER || ds.getType() == TrackType.CNV) &&
ds.getSampleNames().size() > 1) {
FreqData fd = new FreqData(ds, genome);
String freqTrackId = path;
String freqTrackName = "CNV Summary";
CNFreqTrack freqTrack = new CNFreqTrack(locator, freqTrackId, freqTrackName, fd);
freqTrack.setPanelName(newPanelName);

if (props != null) {
freqTrack.setProperties(props);
Expand All @@ -1047,6 +1069,7 @@ private void loadSegTrack(ResourceLocator locator, List<Track> newTracks, Genome
String trackId = path + "_" + trackName;
SegmentedDataSource dataSource = new SegmentedDataSource(trackName, ds);
DataSourceTrack track = new DataSourceTrack(locator, trackId, trackName, dataSource);
track.setPanelName(newPanelName);
track.setRenderer(new HeatmapRenderer());
track.setTrackType(ds.getType());

Expand Down
51 changes: 9 additions & 42 deletions src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -1190,20 +1190,11 @@ public void addTracks(List<Track> tracks, PanelName panelName) {
public void addTracks(List<Track> tracks) {

if (tracks.size() > 0) {
String path = tracks.get(0).getResourceLocator().getPath();// locator.getPath();
Track representativeTrack = tracks.get(0);

// Get an appropriate panel. If its a VCF file create a new panel if the number of genotypes
// is greater than 10
TrackPanel panel = getPanelFor(representativeTrack);
if (path.endsWith(".vcf") || path.endsWith(".vcf.gz") ||
path.endsWith(".vcf4") || path.endsWith(".vcf4.gz")) {
Track t = tracks.get(0);
if (t instanceof VariantTrack && ((VariantTrack) t).getAllSamples().size() > 10) {
String newPanelName = "Panel" + System.currentTimeMillis();
panel = addDataPanel(newPanelName).getTrackPanel();
}
}
panel.addTracks(tracks);
}
}
Expand Down Expand Up @@ -1283,46 +1274,22 @@ 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(FEATURE_PANEL_NAME);
}

ResourceLocator locator = track.getResourceLocator();
if (locator != null) {
TrackPanel panel = getPanelFor(locator);
if (panel != null) {
return panel;
}
}
return getTrackPanel(FEATURE_PANEL_NAME);

}

/**
* Return a DataPanel appropriate for the resource type. This method should be considered deprecated in
* favor of getPanelFor(Track), however the UCSCSessionReader still uses this form.
*
* @param locator
* @return
*/
public TrackPanel getPanelFor(ResourceLocator locator) {

final String format = locator.getFormat();
if ("alist".equals(format)) {
return getVcfBamPanel();
} else if (PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY)) {
return getTrackPanel(FEATURE_PANEL_NAME);
} else if (TrackLoader.isAlignmentTrack(format)) {
String newPanelName = "Panel" + System.currentTimeMillis();
return addDataPanel(newPanelName).getTrackPanel();
} else if (isAnnotationFile(format)) {
final String panelName = track.getPanelName();

if (PreferencesManager.getPreferences().getAsBoolean(SHOW_SINGLE_TRACK_PANE_KEY)) {
return getTrackPanel(FEATURE_PANEL_NAME);
} else if (panelName != null) {
return this.getTrackPanel(panelName);
} else if ("alist".equals(format)) {
return getVcfBamPanel();
} else {
return null; // Can't determine from locator
return getTrackPanel(FEATURE_PANEL_NAME);
}

}


public Set<TrackType> getLoadedTypes() {
Set<TrackType> types = new HashSet();
for (Track t : getAllTracks()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/panel/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public synchronized TrackPanelScrollPane addDataPanel(String name) {

// Insert the new panel just before the feature panel, or at the end if there is no feature panel.
int featurePaneIdx = centerSplitPane.indexOfPane(featureTrackScrollPane);
if (featurePaneIdx > 0) {
if (featurePaneIdx >= 0) {
centerSplitPane.insertPane(sp, featurePaneIdx);
} else {
centerSplitPane.add(sp);
Expand Down

0 comments on commit 606dff3

Please sign in to comment.