Skip to content

Commit

Permalink
Track hubs: restrict initial track selection list to Gene group if to…
Browse files Browse the repository at this point in the history
…tal track count is > 20
  • Loading branch information
jrobinso committed Jan 25, 2025
1 parent 606bb08 commit 4b4d02a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
* Loads a "genome" from a UCSC track hub
Expand Down Expand Up @@ -52,24 +53,33 @@ public Genome loadGenome() throws IOException {
// Check previous selections for this hub first
// TODO -- Maintain track order?
String key = "hub:" + this.hubURL;
final List<TrackConfigGroup> groupedTrackConfigurations = hub.getGroupedTrackConfigurations();

if (PreferencesManager.getPreferences().hasExplicitValue(key)) {
List<TrackConfig> selectedTracks = new ArrayList<>();
Set<String> selectedTrackNames = new HashSet<>(Arrays.asList(PreferencesManager.getPreferences().get(key).split(",")));
List<TrackConfigGroup> trackConfigGroups = hub.getGroupedTrackConfigurations();
for (TrackConfigGroup group : trackConfigGroups) {
for (TrackConfig trackConfig : group.tracks) {
if (selectedTrackNames.contains(trackConfig.getName())) {
selectedTracks.add(trackConfig);
}
}
}
selectedTracks.sort((o1, o2) -> o1.getOrder() - o2.getOrder());
List<TrackConfig> selectedTracks = groupedTrackConfigurations.stream()
.flatMap(group -> group.tracks.stream())
.filter(trackConfig -> selectedTrackNames.contains(trackConfig.getName()))
.sorted(Comparator.comparingInt(TrackConfig::getOrder))
.collect(Collectors.toList());
config.setTracks(selectedTracks);
}

// If running in interactive mode opend dialog to set tracks.
else if (IGV.hasInstance() && !Globals.isBatch() && !Globals.isHeadless() && !Globals.isTesting()) {
HubTrackSelectionDialog dlg = new HubTrackSelectionDialog(hub.getGroupedTrackConfigurations(), IGV.getInstance().getMainFrame());

int count = 0;
for(TrackConfigGroup g : groupedTrackConfigurations) {
count += g.tracks.size();
}

// If the total # of tracks is >= 20 filter to "Gene" groups, usually a single group
List<TrackConfigGroup> filteredGroups = count < 20 ?
groupedTrackConfigurations :
groupedTrackConfigurations.stream().filter(g -> g.label.startsWith("Gene")).collect(Collectors.toList());


HubTrackSelectionDialog dlg = new HubTrackSelectionDialog(filteredGroups, IGV.getInstance().getMainFrame());
dlg.setVisible(true);

List<TrackConfig> selectedTracks = dlg.getSelectedConfigs();
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/broad/igv/ucsc/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ public List<TrackConfigGroup> getGroupedTrackConfigurations() {
java.util.function.Function<Stanza, Boolean> filter = (stanza -> !stanza.name.equals("cytoBandIdeo"));
for (TrackConfig c : this.getTracksConfigs(filter)) {
String groupName = c.getGroup() != null ? c.getGroup() : "other";
if (!trackConfigMap.containsKey(groupName)) {
trackConfigMap.put(groupName, new ArrayList<>());
}
trackConfigMap.get(groupName).add(c);
trackConfigMap.computeIfAbsent(groupName, k -> new ArrayList<>()).add(c);
}

// Extract map of group names
Expand Down

0 comments on commit 4b4d02a

Please sign in to comment.