Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 18, 2024
1 parent e5fdf18 commit b9ff7df
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 72 deletions.
18 changes: 6 additions & 12 deletions src/main/java/org/broad/igv/feature/genome/Genome.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class Genome {

private static final int MAX_WHOLE_GENOME_LONG = 100;
private static Logger log = LogManager.getLogger(Genome.class);

GenomeConfig config;
private String id;
private String displayName;
private List<String> chromosomeNames;
Expand All @@ -94,7 +96,6 @@ public class Genome {
private String homeChromosome;
private String defaultPos;
private String nameSet;

private Hub hub;

public Genome(GenomeConfig config) throws IOException {
Expand Down Expand Up @@ -152,8 +153,8 @@ public Genome(GenomeConfig config) throws IOException {
}
}

// If list of chromosomes is specified use it for the whole genome view, and to prepopulate the
// ordered list of chromosomes.
// If ordered list of chromosome names is specified, use it for the whole genome view, and to prepopulate the
// ordered list of chromosome names.
this.chromosomeNames = new ArrayList<>();
Set<String> ordered = new HashSet<>();
if (config.getChromosomeOrder() != null) {
Expand All @@ -162,7 +163,7 @@ public Genome(GenomeConfig config) throws IOException {
ordered.addAll(this.longChromosomeNames);
}

// If we have chromosome information pre-populate the chromosome cache.
// If we have chromosome length information pre-populate the chromosome cache.
this.chromosomeMap = new HashMap<>();
if (chromosomeList != null) {
for (Chromosome c : chromosomeList) {
Expand All @@ -189,7 +190,6 @@ public Genome(GenomeConfig config) throws IOException {
chromosomeList.size() > 1 &&
longChromosomeNames.size() <= MAX_WHOLE_GENOME_LONG;


// Cytobands
if (config.getCytobands() != null) {
cytobandSource = new CytobandMap(config.getCytobands()); // Directly supplied, from .genome file
Expand All @@ -199,7 +199,6 @@ public Genome(GenomeConfig config) throws IOException {
cytobandSource = new CytobandMap(config.getCytobandURL());
}


// Chromosome aliases
if (config.getAliasURL() != null) {
chromAliasSource = (new ChromAliasFile(config.getAliasURL(), chromosomeNames));
Expand All @@ -215,7 +214,6 @@ public Genome(GenomeConfig config) throws IOException {
addChrAliases(config.getChromAliases());
}


// Set the default position.
if (showWholeGenomeView) {
homeChromosome = Globals.CHR_ALL;
Expand Down Expand Up @@ -263,10 +261,7 @@ private void addTracks(GenomeConfig config) {
ArrayList<ResourceLocator> tracks = new ArrayList<>();
ArrayList<ResourceLocator> hiddenTracks = new ArrayList<>();

List<TrackConfig> trackConfigs = config.getTracks();
if (trackConfigs == null) {
trackConfigs = config.getAnnotations();
}
List<TrackConfig> trackConfigs = config.getTrackConfigs();

if (trackConfigs != null) {

Expand Down Expand Up @@ -415,7 +410,6 @@ public String getDefaultPos() {
return defaultPos == null ? homeChromosome : defaultPos;
}


public Chromosome getChromosome(String name) {
String chrName = getCanonicalChrName(name);
if (chromosomeMap.containsKey(chrName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ public static File downloadGenome(GenomeConfig config, boolean downloadSequence,
config.setAliasURL(relativeDataDirectory + localFile.getName());
}

List<TrackConfig> trackConfigs = config.getTracks();
if (trackConfigs == null) trackConfigs = config.getAnnotations(); // alias
List<TrackConfig> trackConfigs = config.getTrackConfigs();

if (trackConfigs != null) {
for (TrackConfig trackConfig : trackConfigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ public ChromsizesLoader(String genomePath) {
}

/**
* Define a minimal genome from a chrom.sizes file. It is assumed (required) that the file follow the
* UCSC naming convention => [id].chrom.sizes
* Define a minimal genome from a chrom.sizes file.
*
* @return
* @throws IOException
*/
@Override
public Genome loadGenome() throws IOException {
int firstPeriodIdx = genomePath.indexOf('.');
String genomeId = genomePath.substring(0, firstPeriodIdx);
String genomeId = genomePath;
List<Chromosome> chromosomes = ChromSizesParser.parse(genomePath);
Genome newGenome = new Genome(genomeId, chromosomes);
return newGenome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public static GenomeLoader getLoader(String genomePath) throws IOException {
return new ChromsizesLoader(genomePath);
} else if (genomePath.endsWith(".json")) {
return new JsonGenomeLoader(genomePath);
} else if (genomePath.endsWith(".2bit")) {
GenomeConfig config = new GenomeConfig();
config.setTwoBitURL(genomePath);
config.setId(genomePath);
config.setName((HttpUtils.isRemoteURL(genomePath)) ?
Utilities.getFileNameFromURL(genomePath) :
(new File(genomePath)).getName());
return new GenomeObjectLoader(config);
} else if (genomePath.endsWith("hub.txt")) {
return new HubGenomeLoader(genomePath);
} else {
Expand All @@ -65,7 +57,7 @@ public static GenomeLoader getLoader(String genomePath) throws IOException {
String gziPath = genomePath + ".gzi";
String faiPath = genomePath + ".fai";
if (!(FileUtils.resourceExists(gziPath) && FileUtils.resourceExists(faiPath))) {
throw new GenomeException("IGV cannot readed gzipped fasta files.");
throw new GenomeException("IGV cannot read gzipped fasta files.");
}
}
return new FastaGenomeLoader(genomePath);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.io.IOException;
import java.util.*;

/**
* Loads a "genome" from a UCSC track hub
*/
public class HubGenomeLoader extends GenomeLoader {

String hubURL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Genome loadGenome() throws IOException {

// Load liftover "chain" files. This enables navigating by coordinates of another genome.
// Not a common option.

// JsonElement chains = config.chains;
// if (chains != null) {
// Map<String, Liftover> liftoverMap = new HashMap<>();
Expand Down Expand Up @@ -143,10 +142,7 @@ private GenomeConfig fixPaths(GenomeConfig config) {
if (config.getChromAliasBbURL() != null) {
config.setChromAliasBbURL(FileUtils.getAbsolutePath(config.getChromAliasBbURL(), genomePath));
}
List<TrackConfig> trackConfigs = config.getTracks();
if (trackConfigs == null) {
trackConfigs = config.getAnnotations();
}
List<TrackConfig> trackConfigs = config.getTrackConfigs();
if (trackConfigs != null) {
trackConfigs.forEach((TrackConfig trackConfig) -> {
if (trackConfig.getUrl() != null) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
import org.broad.igv.event.IGVEventBus;
import org.broad.igv.event.IGVEventObserver;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.GenomeDownloadUtils;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.feature.genome.ChromSizesUtils;
import org.broad.igv.track.AttributeManager;
import org.broad.igv.track.Track;
import org.broad.igv.ui.commandbar.GenomeSelectionDialog;
import org.broad.igv.ui.commandbar.HostedGenomeSelectionDialog;
import org.broad.igv.util.GoogleUtils;
import org.broad.igv.oauth.OAuthProvider;
import org.broad.igv.oauth.OAuthUtils;
Expand Down Expand Up @@ -428,13 +429,13 @@ private void addEncodeItems(List<JComponent> menuItems, String genomeId) {

JMenuItem otherSignalsItem = new JMenuItem();
otherSignalsItem.setAction(new BrowseEncodeAction("Other - Signals", 0, BrowseEncodeAction.Type.SIGNALS_OTHER, igv));
encodeMenuItems.add(otherSignalsItem);
encodeMenuItems.add(otherSignalsItem);

JMenuItem otherItem = new JMenuItem();
otherItem.setAction(new BrowseEncodeAction("Other (peaks, calls, ...)", 0, BrowseEncodeAction.Type.OTHER, igv));
encodeMenuItems.add(otherItem);

for(JComponent item : encodeMenuItems) {
for (JComponent item : encodeMenuItems) {
menuItems.add(item);
item.setVisible(EncodeTrackChooser.genomeSupported(genomeId));
}
Expand All @@ -451,7 +452,7 @@ private JMenu createGenomesMenu() {
JMenu menu = new JMenu("Genomes");

loadGenomeFromServerMenuItem = new JMenuItem("Select Hosted Genome...");
loadGenomeFromServerMenuItem.addActionListener(e -> GenomeSelectionDialog.selectHostedGenome());
loadGenomeFromServerMenuItem.addActionListener(e -> HostedGenomeSelectionDialog.selectHostedGenome());
loadGenomeFromServerMenuItem.setToolTipText(LOAD_GENOME_SERVER_TOOLTIP);
menu.add(loadGenomeFromServerMenuItem);

Expand All @@ -469,7 +470,7 @@ private JMenu createGenomesMenu() {

// If a file selection was made
if (file != null) {
Genome newGenome = GenomeManager.getInstance().loadGenome(file.getAbsolutePath());
GenomeManager.getInstance().loadGenome(file.getAbsolutePath());
}
} catch (Exception ex) {
MessageUtils.showErrorMessage(ex.getMessage(), ex);
Expand Down Expand Up @@ -1210,7 +1211,7 @@ public void receiveEvent(final IGVEvent event) {
final Genome genome = ((GenomeChangeEvent) event).genome();
final String genomeId = genome.getId();
encodeUCSCMenuItem.setVisible(EncodeTrackChooser.genomeSupportedUCSC(genomeId));
for(JComponent item : encodeMenuItems) {
for (JComponent item : encodeMenuItems) {
item.setVisible(EncodeTrackChooser.genomeSupported(genomeId));
}

Expand Down Expand Up @@ -1300,5 +1301,4 @@ public Foo() {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void actionPerformed(ActionEvent actionEvent) {
if (genomeListItem != null && genomeListItem.getPath() != null) {

if (genomeListItem == GenomeListItem.DOWNLOAD_ITEM) {
GenomeSelectionDialog.selectHostedGenome();
HostedGenomeSelectionDialog.selectHostedGenome();
} else {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
* Dialog box for selecting genomes. User can choose from a list,
* which is filtered according to text box input
*/
public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog {
public class HostedGenomeSelectionDialog extends org.broad.igv.ui.IGVDialog {

private static Logger log = LogManager.getLogger(GenomeSelectionDialog.class);
private static Logger log = LogManager.getLogger(HostedGenomeSelectionDialog.class);

private JTextField genomeFilter;
private JList<GenomeListItem> genomeList;
Expand All @@ -83,7 +83,7 @@ public static void selectHostedGenome() {
if (inputListItems == null) {
return;
}
GenomeSelectionDialog dialog = new GenomeSelectionDialog(IGV.getInstance().getMainFrame(), inputListItems);
HostedGenomeSelectionDialog dialog = new HostedGenomeSelectionDialog(IGV.getInstance().getMainFrame(), inputListItems);
UIUtilities.invokeAndWaitOnEventThread(() -> dialog.setVisible(true));

if (dialog.isCanceled()) {
Expand Down Expand Up @@ -137,11 +137,10 @@ private static void removeDotGenomeFile(String id) {
/**
* @param parent
*/
private GenomeSelectionDialog(java.awt.Frame parent, Collection<GenomeListItem> inputListItems) {
private HostedGenomeSelectionDialog(java.awt.Frame parent, Collection<GenomeListItem> inputListItems) {
super(parent);
initComponents();
initData(inputListItems);
downloadSequenceCB.setVisible(true);
}

private void initData(Collection<GenomeListItem> inputListItems) {
Expand Down Expand Up @@ -272,9 +271,9 @@ public void keyReleased(KeyEvent e) {
genomeList = new JList();
genomeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
genomeList.addListSelectionListener(e -> {
List<GenomeListItem> items = genomeList.getSelectedValuesList();
downloadSequenceCB.setEnabled(items != null && items.stream().allMatch(item -> GenomeDownloadUtils.isSequenceDownloadable(item)));
downloadAnnotationsCB.setEnabled(items != null && items.stream().allMatch(item -> GenomeDownloadUtils.isAnnotationsDownloadable(item)));
GenomeListItem item = genomeList.getSelectedValue();
downloadSequenceCB.setEnabled(item != null && GenomeDownloadUtils.isSequenceDownloadable(item));
downloadAnnotationsCB.setEnabled(item != null && GenomeDownloadUtils.isAnnotationsDownloadable(item));
});

JScrollPane scrollPane1 = new JScrollPane();
Expand Down

0 comments on commit b9ff7df

Please sign in to comment.