diff --git a/src/main/java/org/broad/igv/batch/CommandExecutor.java b/src/main/java/org/broad/igv/batch/CommandExecutor.java index 29e4c38be0..ee1c8daa9c 100755 --- a/src/main/java/org/broad/igv/batch/CommandExecutor.java +++ b/src/main/java/org/broad/igv/batch/CommandExecutor.java @@ -643,7 +643,7 @@ private String genome(String param1) { String genomePath = resolveFileReference(genomeID); try { - GenomeManager.getInstance().loadGenome(genomePath, null); + GenomeManager.getInstance().loadGenome(genomePath); } catch (IOException e) { result = "ERROR: Could not load genome: " + genomeID; MessageUtils.showMessage(result); diff --git a/src/main/java/org/broad/igv/batch/CommandListener.java b/src/main/java/org/broad/igv/batch/CommandListener.java index 74999ce1de..5445dd42eb 100755 --- a/src/main/java/org/broad/igv/batch/CommandListener.java +++ b/src/main/java/org/broad/igv/batch/CommandListener.java @@ -37,7 +37,6 @@ import org.broad.igv.ui.IGV; import org.broad.igv.ui.util.MessageUtils; import org.broad.igv.ui.util.UIUtilities; -import org.broad.igv.util.LongRunningTask; import org.broad.igv.util.StringUtils; import java.awt.*; @@ -377,14 +376,7 @@ private String processGet(String command, Map params, CommandExe if (command.equals("/")) { if (params.containsKey("hubURL")) { - final String hubURL = URLDecoder.decode(params.get("hubURL")); // what if not encoded? Usually its not - LongRunningTask.submit(() -> { - try { - GenomeManager.getInstance().loadGenome(hubURL, null); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); + GenomeManager.getInstance().loadGenome(URLDecoder.decode(params.get("hubURL"))); } } else if (command.equals("/load")) { String file = null; diff --git a/src/main/java/org/broad/igv/feature/genome/GenomeManager.java b/src/main/java/org/broad/igv/feature/genome/GenomeManager.java index 040050da0a..bc1ccfe88d 100644 --- a/src/main/java/org/broad/igv/feature/genome/GenomeManager.java +++ b/src/main/java/org/broad/igv/feature/genome/GenomeManager.java @@ -54,13 +54,10 @@ import org.broad.igv.track.Track; import org.broad.igv.ui.IGV; import org.broad.igv.ui.PanelName; +import org.broad.igv.ui.WaitCursorManager; import org.broad.igv.ui.commandbar.GenomeListManager; import org.broad.igv.ui.panel.FrameManager; -import org.broad.igv.ui.panel.ReferenceFrame; -import org.broad.igv.ui.util.MessageUtils; -import org.broad.igv.ui.util.ProgressBar; -import org.broad.igv.ui.util.ProgressMonitor; -import org.broad.igv.ui.util.UIUtilities; +import org.broad.igv.ui.util.*; import org.broad.igv.ui.util.download.Downloader; import org.broad.igv.util.FileUtils; import org.broad.igv.util.HttpUtils; @@ -73,13 +70,10 @@ import java.net.SocketException; import java.net.URL; import java.net.URLDecoder; -import java.sql.Ref; import java.util.*; import java.util.List; import static org.broad.igv.prefs.Constants.SHOW_SINGLE_TRACK_PANE_KEY; -import static org.broad.igv.ui.IGV.DATA_PANEL_NAME; -import static org.broad.igv.ui.IGV.FEATURE_PANEL_NAME; /** * @author jrobinso @@ -156,45 +150,45 @@ public void setCurrentGenome(Genome genome) { public void loadGenomeById(String genomeId) throws IOException { - final Genome currentGenome = getCurrentGenome(); if (currentGenome != null && genomeId.equals(currentGenome.getId())) { return; // Already loaded } - // If genomeId is a file path load it + String genomePath = null; if (org.broad.igv.util.ParsingUtils.fileExists(genomeId)) { - loadGenome(genomeId, null); - + genomePath = genomeId; } else { - final ProgressMonitor[] monitor = {new ProgressMonitor()}; - final ProgressBar.ProgressDialog[] progressDialog = new ProgressBar.ProgressDialog[1]; - UIUtilities.invokeAndWaitOnEventThread(() -> { - progressDialog[0] = ProgressBar.showProgressDialog(IGV.getInstance().getMainFrame(), "Loading Genome...", monitor[0], false); - }); - - try { - GenomeListItem item = genomeListManager.getGenomeListItem(genomeId); - if (item == null) { - MessageUtils.showMessage("Could not locate genome with ID: " + genomeId); - } else { - loadGenome(item.getPath(), monitor[0]); - } - } finally { - UIUtilities.invokeOnEventThread(() -> { - progressDialog[0].setVisible(false); - }); + GenomeListItem item = genomeListManager.getGenomeListItem(genomeId); + if (item == null) { + MessageUtils.showMessage("Could not locate genome with ID: " + genomeId); + return; + } else { + genomePath = item.getPath(); } } + + loadGenome(genomePath); // monitor[0]); + } - public Genome loadGenome(String genomePath, ProgressMonitor monitor) throws IOException { + /** + * The main load method -- loads a genome from a file or url path. Note this is a long running operation and + * should not be done on the Swing event thread as it will block the UI. + * + * @param genomePath + * @return + * @throws IOException + */ + public Genome loadGenome(String genomePath) throws IOException { + + WaitCursorManager.CursorToken cursorToken = null; try { log.info("Loading genome: " + genomePath); - - if (monitor != null) { - UIUtilities.invokeAndWaitOnEventThread(() -> monitor.fireProgress(25)); + if (IGV.hasInstance()) { + IGV.getInstance().setStatusBarMessage("Loading genome"); + cursorToken = WaitCursorManager.showWaitCursor(); } // Clear Feature DB @@ -215,9 +209,6 @@ public Genome loadGenome(String genomePath, ProgressMonitor monitor) throws IOEx log.error("Failed to load user defined alias", e); } - if (monitor != null) { - monitor.fireProgress(25); - } if (IGV.hasInstance()) { IGV.getInstance().resetSession(null); @@ -247,6 +238,11 @@ public Genome loadGenome(String genomePath, ProgressMonitor monitor) throws IOEx } catch (SocketException e) { throw new RuntimeException("Server connection error", e); + } finally { + if (IGV.hasInstance()) { + IGV.getInstance().setStatusBarMessage(""); + WaitCursorManager.removeWaitCursor(cursorToken); + } } } @@ -267,7 +263,7 @@ public void loadGenomeAnnotations(Genome genome) { } catch (DataLoadException e) { log.error("Error loading genome annotations", e); } - }// + } genome.setAnnotationTracks(annotationTracks); } restoreGenomeTracks(genome); @@ -324,91 +320,12 @@ public void restoreGenomeTracks(Genome genome) { * Delete .genome files from the cache directory */ public void clearGenomeCache() { - File[] files = DirectoryManager.getGenomeCacheDirectory().listFiles(); for (File file : files) { if (file.getName().toLowerCase().endsWith(Globals.GENOME_FILE_EXTENSION)) { file.delete(); } } - - } - - /** - * Create a genome archive (.genome) file. - * - * @param genomeFile - * @param cytobandFileName A File path to a file that contains cytoband data. - * @param refFlatFileName A File path to a gene file. - * @param fastaFileName A File path to a FASTA file, a .gz file containing a - * single FASTA file, or a directory containing ONLY FASTA files. - * (relative to the .genome file to be created) where the sequence data for - * the new genome will be written. - * @param genomeDisplayName The unique user-readable name of the new genome. - * @param genomeId The id to be assigned to the genome. - * @param monitor A ProgressMonitor used to track progress - null, - * if no progress updating is required. - * @return GenomeListItem - * @throws FileNotFoundException - */ - public GenomeListItem defineGenome(File genomeFile, - String cytobandFileName, - String refFlatFileName, - String fastaFileName, - String chrAliasFileName, - String genomeDisplayName, - String genomeId, - javax.swing.ProgressMonitor monitor) - throws IOException { - - File refFlatFile = null; - File cytobandFile = null; - File chrAliasFile = null; - - if (genomeFile != null) { - PreferencesManager.getPreferences().setLastGenomeImportDirectory(genomeFile.getParentFile()); - } - - if ((cytobandFileName != null) && (cytobandFileName.trim().length() != 0)) { - cytobandFile = new File(cytobandFileName); - } - - if ((refFlatFileName != null) && (refFlatFileName.trim().length() != 0)) { - refFlatFile = new File(refFlatFileName); - } - - if ((chrAliasFileName != null) && (chrAliasFileName.trim().length() != 0)) { - chrAliasFile = new File(chrAliasFileName); - } - - if (monitor != null) monitor.setProgress(25); - - (new GenomeImporter()).createGenomeArchive(genomeFile, genomeId, - genomeDisplayName, fastaFileName, refFlatFile, cytobandFile, chrAliasFile); - - if (monitor != null) monitor.setProgress(75); - - GenomeListItem newItem = new GenomeListItem(genomeDisplayName, genomeFile.getAbsolutePath(), genomeId); - genomeListManager.addGenomeItem(newItem, true); - - if (monitor != null) monitor.setProgress(100); - - return newItem; - - } - - /** - * Specific to Broad Amazon servers -- use S3 downwload rather than cloudfront - * - * @param path - * @return - */ - private String convertToS3(String path) { - if (path.startsWith("http://igvdata") || path.startsWith("https://igvdata")) { - return path.replaceFirst("igvdata", "igv"); - } else { - return path; - } } public String getGenomeId() { @@ -426,54 +343,6 @@ public Genome getCurrentGenome() { return currentGenome; } - /** - * Given a directory, looks for all .genome files, - * and outputs a list of these genomes suitable for parsing by IGV. - * Intended to be run on server periodically. - * - * @param inDir Directory in which all genome files live - * @param rootPath The path to be prepended to file names (e.g. http://igvdata.broadinstitute.org) - * @param outPath Path to output file, where we will write the results - */ - public void generateGenomeList(File inDir, String rootPath, String outPath) { - File[] genomeFiles = inDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - if (name == null) return false; - return name.toLowerCase().endsWith(".genome"); - } - }); - - PrintWriter writer; - try { - writer = new PrintWriter(outPath); - } catch (FileNotFoundException e) { - log.error("Error opening " + outPath); - e.printStackTrace(); - return; - } - - - GenomeDescriptor descriptor; - for (File f : genomeFiles) { - String curLine = ""; - try { - descriptor = GenomeDescriptor.parseGenomeArchiveFile(f); - curLine += descriptor.getName(); - curLine += "\t" + rootPath + "/" + f.getName(); - curLine += "\t" + descriptor.getId(); - } catch (IOException e) { - log.error("Error parsing genome file. Skipping " + f.getAbsolutePath()); - log.error(e); - continue; - } - writer.println(curLine); - } - - writer.close(); - - } - public boolean downloadGenome(GenomeListItem item, boolean downloadSequence) { diff --git a/src/main/java/org/broad/igv/feature/genome/GenomeUtils.java b/src/main/java/org/broad/igv/feature/genome/GenomeUtils.java index 002e93cc42..8fcb7143ee 100644 --- a/src/main/java/org/broad/igv/feature/genome/GenomeUtils.java +++ b/src/main/java/org/broad/igv/feature/genome/GenomeUtils.java @@ -91,7 +91,7 @@ public static void updateChromSizes(String genomeListPath, File directory) throw System.out.println("Updating " + genomeID); String genomePath = tokens[1]; try { - Genome genome = GenomeManager.getInstance().loadGenome(genomePath, null); + Genome genome = GenomeManager.getInstance().loadGenome(genomePath); System.out.println(genome.getId()); exportChromSizes(directory, genome); diff --git a/src/main/java/org/broad/igv/session/IGVSessionReader.java b/src/main/java/org/broad/igv/session/IGVSessionReader.java index 7bb9a29134..f009a94855 100644 --- a/src/main/java/org/broad/igv/session/IGVSessionReader.java +++ b/src/main/java/org/broad/igv/session/IGVSessionReader.java @@ -225,13 +225,13 @@ private void processRootNode(Session session, Node node, String sessionPath) { GenomeListItem item = GenomeListManager.getInstance().getGenomeListItem(genomeId); if (item != null) { genomePath = item.getPath(); - GenomeManager.getInstance().loadGenome(item.getPath(), null); + GenomeManager.getInstance().loadGenome(item.getPath()); } else { genomePath = genomeId; if (!FileUtils.isRemote(genomePath) && !ParsingUtils.fileExists(genomePath)) { genomePath = getAbsolutePath(genomeId, sessionPath); } - GenomeManager.getInstance().loadGenome(genomePath, null); + GenomeManager.getInstance().loadGenome(genomePath); } } catch (IOException e) { MessageUtils.showErrorMessage("Error loading genome: " + genomeId, e); diff --git a/src/main/java/org/broad/igv/tools/FeatureSearcher.java b/src/main/java/org/broad/igv/tools/FeatureSearcher.java deleted file mode 100644 index dc8261c139..0000000000 --- a/src/main/java/org/broad/igv/tools/FeatureSearcher.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.broad.igv.tools; - -import org.broad.igv.logging.*; -import org.broad.igv.feature.genome.Genome; -import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.track.FeatureSource; -import org.broad.igv.track.FeatureTrack; -import org.broad.igv.ui.panel.FrameManager; -import org.broad.igv.ui.panel.ReferenceFrame; -import org.broad.igv.ui.util.IndefiniteProgressMonitor; -import htsjdk.tribble.Feature; - -import java.io.IOException; -import java.util.Iterator; - -/** - * Used for searching for the next feature, given a source. - * We simply call getFeature on that source repeatedly over stepped windows - * until we find something - * User: jacob - * Date: 2013-Feb-21 - */ -public class FeatureSearcher implements Runnable { - - private static Logger log = LogManager.getLogger(FeatureSearcher.class); - - private FeatureTrack track = null; - private FeatureSource source = null; - - private static final int DEFAULT_SEARCH_INCREMENT = 100000; - - /** - * After searching a window, the increment over which to move. - * If smaller than searchWindowSize, it will be a sliding search with overlap. - * If larger, there will be gaps. Make negative to search backwards - */ - private int searchIncrement = DEFAULT_SEARCH_INCREMENT; - - /** - * The window size over which to search, in base pairs - */ - private int searchWindowSize = searchIncrement; - - private volatile Iterator result = null; - - private volatile boolean isRunning = false; - private volatile boolean wasCancelled = false; - private volatile boolean done = false; - - private final Genome genome; - private String chr; - private int start; - private int end; - private IndefiniteProgressMonitor monitor; - - public FeatureSearcher(FeatureSource source, Genome genome, String chr, int start){ - this(source, genome, chr, start, null); - } - - /** - * - * @param source FeatureSource which we are searching - * @param genome - * @param chr - * @param start - * @param monitor Optional (may be null) - */ - public FeatureSearcher(FeatureSource source, Genome genome, String chr, int start, IndefiniteProgressMonitor monitor){ - assert source != null; - this.source = source; - this.genome = genome; - this.monitor = monitor; - this.initSearchCoords(chr, start); - } - - private void initSearchCoords(String chr, int start){ - this.chr = chr; - this.start = start; - this.end = start + searchWindowSize; - } - - private void incrementSearchCoords(){ - this.start += searchIncrement; - int maxCoord = Integer.MAX_VALUE - searchWindowSize; - int minCoord = 0; - - if(this.genome != null){ - maxCoord = genome.getChromosome(chr).getLength(); - } - - boolean outsideBounds = start >= maxCoord || start < minCoord; - - - if (outsideBounds) { - String lastChr = chr; - chr = null; - if(genome != null){ - if(start >= maxCoord){ - chr = genome.getNextChrName(lastChr); - }else if(start < minCoord){ - chr = genome.getPrevChrName(lastChr); - } - } - - if (chr == null) { - //No next chromosome, done searching - start = end = -1; - this.cancel(); - return; - } else { - maxCoord = genome.getChromosome(chr).getLength(); - start = searchIncrement > 0 ? minCoord : maxCoord - searchWindowSize; - } - } - this.end = start + searchWindowSize; - this.end = Math.min(this.end, maxCoord); - } - - private Iterator getFeatures(String chr, int start, int end) throws IOException{ - if(track != null) return track.getFeatures(chr, start, end).iterator(); - if(source != null) return source.getFeatures(chr, start, end); - throw new IllegalStateException("Have no FeatureTrack or FeatureSource from which to get features"); - } - - /** - * Signal the searcher to stop. Note that stopping may not be instantaneous - */ - public void cancel(){ - this.wasCancelled = true; - } - - public boolean isDone(){ - return this.done; - } - - public Iterator getResult(){ - if(this.isRunning) return null; - return this.result; - } - - /** - * Set the search increment, can be either positive or negative (to search backwards). - * Also sets the searchWindowSize - * @param searchIncrement - */ - public void setSearchIncrement(int searchIncrement) { - if(this.isRunning) throw new IllegalStateException("Cannot set search increment while searching"); - this.searchIncrement = searchIncrement; - this.searchWindowSize = Math.abs(searchIncrement); - this.end = this.start + this.searchWindowSize; - } - - @Override - public void run() { - isRunning = true; - Iterator rslt = null; - int counter = 0; - int updateInterval = 20 * (int) (DEFAULT_SEARCH_INCREMENT / (1.0 * searchIncrement) ); - //Keep updateInterval above 0 - updateInterval = Math.max(updateInterval, 100); - - if(this.monitor != null){ - this.monitor.start(); - } - - while(isRunning && !wasCancelled){ - try { - if(this.monitor != null){ - if(counter == 0){ - String status = String.format("Searching: %s:%d-%d", chr, start, end); - this.monitor.updateStatus(status); - } - counter = (counter + 1) % updateInterval; - } - rslt = getFeatures(chr, start, end); - if(rslt != null && rslt.hasNext()){ - //Found something - this.result = rslt; - break; - }else{ - //Didn't find anything, keep going - incrementSearchCoords(); - } - } catch (IOException e) { - log.error("Error searching for feature", e); - break; - } - } - this.isRunning = false; - this.done = true; - if(this.monitor != null){ - this.monitor.stop(); - } - } - - /** - * Listener for handling search result - */ - public static interface IFeatureFound{ - void processResult(Iterator searchResult); - } - - public static class GotoFeatureHandler implements IFeatureFound{ - @Override - public void processResult(Iterator searchResult) { - ReferenceFrame frame = FrameManager.getDefaultFrame(); - Feature f = searchResult.next(); - - String chr = GenomeManager.getInstance().getCurrentGenome().getCanonicalChrName(f.getChr()); - double newCenter = f.getStart(); - if (!chr.equals(frame.getChrName())) { - // Switch chromosomes. We have to do some tricks to maintain the same resolution scale. - double range = frame.getEnd() - frame.getOrigin(); - int newOrigin = (int) Math.max(newCenter - range / 2, 0); - int newEnd = (int) (newOrigin + range); - frame.jumpTo(chr, newOrigin, newEnd); - } else { - frame.centerOnLocation(newCenter); - } - } - } -} diff --git a/src/main/java/org/broad/igv/tools/IgvTools.java b/src/main/java/org/broad/igv/tools/IgvTools.java index 6c21709e19..9c023d60ef 100644 --- a/src/main/java/org/broad/igv/tools/IgvTools.java +++ b/src/main/java/org/broad/igv/tools/IgvTools.java @@ -466,13 +466,7 @@ void run(String[] argv) { String ofile = nonOptionArgs[2]; Boolean pairOption = (Boolean) parser.getOptionValue(pairedCoverageOpt, false); BamToBed.convert(new File(ifile), new File(ofile), pairOption); - } else if (command.equalsIgnoreCase(CMD_GEN_GENOME_LIST)) { - //Generate a genomes.txt list file based on a directory - //TODO Probably a better place for this. Users won't generally use it - File inDir = new File(ifile); - GenomeManager manager = GenomeManager.getInstance(); - manager.generateGenomeList(inDir, nonOptionArgs[2], nonOptionArgs[3]); - } else if (command.equalsIgnoreCase(CMD_CONTACTS)) { + } else if (command.equalsIgnoreCase(CMD_CONTACTS)) { PairedUtils.extractInteractions(ifile, nonOptionArgs[2], Integer.parseInt(nonOptionArgs[3])); } else if (command.equalsIgnoreCase(CMD_DISCORDANT)) { PairedUtils.extractUnexpectedPairs(ifile, nonOptionArgs[2]); @@ -1166,7 +1160,7 @@ public static Genome loadGenome(String genomeFileOrID) throws IOException { } } - genome = genomeManager.loadGenome(genomeFile.getAbsolutePath(), null); + genome = genomeManager.loadGenome(genomeFile.getAbsolutePath()); if (genome == null) { throw new PreprocessingException("Error loading: " + genomeFileOrID); } diff --git a/src/main/java/org/broad/igv/track/DataSourceTrack.java b/src/main/java/org/broad/igv/track/DataSourceTrack.java index cad8e8c3f8..67b488d120 100644 --- a/src/main/java/org/broad/igv/track/DataSourceTrack.java +++ b/src/main/java/org/broad/igv/track/DataSourceTrack.java @@ -68,10 +68,10 @@ public void setDatasource(DataSource dataSource) { this.dataSource = dataSource; if (this.dataSource != null) { setTrackType(dataSource.getTrackType()); - List scores = this.dataSource.getSummaryScoresForRange(Globals.CHR_ALL, -1, -1, 0); - if (scores.size() > 0) { - initScale(dataSource, scores); - } + // List scores = this.dataSource.getSummaryScoresForRange(Globals.CHR_ALL, -1, -1, 0); + // if (scores.size() > 0) { + // initScale(dataSource, scores); + // } } } diff --git a/src/main/java/org/broad/igv/track/FeatureTrackUtils.java b/src/main/java/org/broad/igv/track/FeatureTrackUtils.java index 6a3462f9f8..5b564f998b 100644 --- a/src/main/java/org/broad/igv/track/FeatureTrackUtils.java +++ b/src/main/java/org/broad/igv/track/FeatureTrackUtils.java @@ -25,20 +25,10 @@ package org.broad.igv.track; +import htsjdk.tribble.Feature; import org.broad.igv.feature.genome.Genome; import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.tools.FeatureSearcher; -import org.broad.igv.ui.IGV; -import org.broad.igv.ui.util.CancellableProgressDialog; -import org.broad.igv.ui.util.IndefiniteProgressMonitor; -import org.broad.igv.ui.util.ProgressMonitor; -import org.broad.igv.util.LongRunningTask; -import htsjdk.tribble.Feature; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; diff --git a/src/main/java/org/broad/igv/ui/IGV.java b/src/main/java/org/broad/igv/ui/IGV.java index b0ad43ec92..ba879a4fda 100644 --- a/src/main/java/org/broad/igv/ui/IGV.java +++ b/src/main/java/org/broad/igv/ui/IGV.java @@ -1219,31 +1219,41 @@ public void addTracks(List tracks, ResourceLocator locator) { */ public List load(ResourceLocator locator) throws DataLoadException { - TrackLoader loader = new TrackLoader(); - Genome genome = GenomeManager.getInstance().getCurrentGenome(); - List newTracks = loader.load(locator, genome); - if (newTracks.size() > 0) { - for (Track track : newTracks) { - String fn = locator.getPath(); - int lastSlashIdx = fn.lastIndexOf("/"); - if (lastSlashIdx < 0) { - lastSlashIdx = fn.lastIndexOf("\\"); - } - if (lastSlashIdx > 0) { - fn = fn.substring(lastSlashIdx + 1); - } - 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()); + try { + if (IGV.hasInstance()) { + IGV.getInstance().setStatusBarMessage3("Loading " + locator.getPath()); + } - TrackProperties properties = locator.getTrackProperties(); - if (properties != null) { - track.setProperties(properties); + TrackLoader loader = new TrackLoader(); + Genome genome = GenomeManager.getInstance().getCurrentGenome(); + List newTracks = loader.load(locator, genome); + if (newTracks.size() > 0) { + for (Track track : newTracks) { + String fn = locator.getPath(); + int lastSlashIdx = fn.lastIndexOf("/"); + if (lastSlashIdx < 0) { + lastSlashIdx = fn.lastIndexOf("\\"); + } + if (lastSlashIdx > 0) { + fn = fn.substring(lastSlashIdx + 1); + } + 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(); + return newTracks; + } finally { + if (IGV.hasInstance()) { + IGV.getInstance().setStatusBarMessage3(""); + } } - //revalidateTrackPanels(); - return newTracks; } @@ -1943,26 +1953,27 @@ public void run() { log.debug("Loading session data"); } - final IndefiniteProgressMonitor indefMonitor = new IndefiniteProgressMonitor(); - final ProgressBar.ProgressDialog progressDialog2 = ProgressBar.showProgressDialog(mainFrame, "Loading session data", indefMonitor, false); - indefMonitor.start(); - - if (log.isDebugEnabled()) { log.debug("Calling restore session"); } if (igvArgs.getSessionFile() != null) { - boolean success = false; - if (HttpUtils.isRemoteURL(igvArgs.getSessionFile())) { - boolean merge = false; - success = loadSession(igvArgs.getSessionFile(), igvArgs.getLocusString()); - } else { - File sf = new File(igvArgs.getSessionFile()); - if (sf.exists()) { - success = loadSession(sf.getAbsolutePath(), igvArgs.getLocusString()); + IGV.getInstance().setStatusBarMessage3("Loading " + igvArgs.getSessionFile()); + boolean success; + try { + success = false; + if (HttpUtils.isRemoteURL(igvArgs.getSessionFile())) { + boolean merge = false; + success = loadSession(igvArgs.getSessionFile(), igvArgs.getLocusString()); + } else { + File sf = new File(igvArgs.getSessionFile()); + if (sf.exists()) { + success = loadSession(sf.getAbsolutePath(), igvArgs.getLocusString()); + } } + } finally { + IGV.getInstance().setStatusBarMessage3(""); } if (!success) { String genomeId = preferences.getDefaultGenome(); @@ -2049,11 +2060,6 @@ public void run() { contentPane.getCommandBar().selectGenome(genomeId); } } - - - indefMonitor.stop(); - closeWindow(progressDialog2); - } UIUtilities.invokeAndWaitOnEventThread(() -> { diff --git a/src/main/java/org/broad/igv/ui/IGVMenuBar.java b/src/main/java/org/broad/igv/ui/IGVMenuBar.java index 68b9e264c8..33506e8872 100644 --- a/src/main/java/org/broad/igv/ui/IGVMenuBar.java +++ b/src/main/java/org/broad/igv/ui/IGVMenuBar.java @@ -429,7 +429,7 @@ public void actionPerformed(ActionEvent event) { // If a file selection was made if (file != null) { - GenomeManager.getInstance().loadGenome(file.getAbsolutePath(), null); + GenomeManager.getInstance().loadGenome(file.getAbsolutePath()); } } catch (Exception e) { MessageUtils.showErrorMessage(e.getMessage(), e); diff --git a/src/main/java/org/broad/igv/ui/action/LoadFromURLMenuAction.java b/src/main/java/org/broad/igv/ui/action/LoadFromURLMenuAction.java index abe5acd4aa..06012cd408 100644 --- a/src/main/java/org/broad/igv/ui/action/LoadFromURLMenuAction.java +++ b/src/main/java/org/broad/igv/ui/action/LoadFromURLMenuAction.java @@ -33,12 +33,8 @@ import org.broad.igv.feature.genome.load.HubGenomeLoader; import org.broad.igv.logging.*; import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.util.GoogleUtils; -import org.broad.igv.prefs.Constants; -import org.broad.igv.prefs.PreferencesManager; import org.broad.igv.session.SessionReader; import org.broad.igv.ui.IGV; -import org.broad.igv.ui.IGVMenuBar; import org.broad.igv.ui.util.LoadFromURLDialog; import org.broad.igv.ui.util.MessageUtils; import org.broad.igv.util.AmazonUtils; @@ -90,7 +86,7 @@ public void actionPerformed(ActionEvent e) { if (inputs.length == 1 && HubGenomeLoader.isHubURL(inputs[0])) { LongRunningTask.submit(() -> { try { - GenomeManager.getInstance().loadGenome(inputs[0], null); + GenomeManager.getInstance().loadGenome(inputs[0]); } catch (IOException ex) { log.error("Error loading tack hub", ex); MessageUtils.showMessage("Error loading track hub: " + ex.getMessage()); @@ -147,7 +143,7 @@ else if (inputs.length == 1 && SessionReader.isSessionFile(inputs[0])) { url = url.trim(); try { checkURLs(new String[]{url}); - GenomeManager.getInstance().loadGenome(url, null); + GenomeManager.getInstance().loadGenome(url); } catch (Exception e1) { MessageUtils.showMessage("Error loading genome: " + e1.getMessage()); } diff --git a/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java b/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java index fe1333874e..96302500c3 100644 --- a/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java +++ b/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java @@ -99,9 +99,6 @@ private void loadGenomeListItem(final GenomeListItem genomeListItem) { final Runnable runnable = new Runnable() { - org.broad.igv.ui.util.ProgressMonitor monitor; - ProgressBar.ProgressDialog progressDialog; - public void run() { if (genomeListItem != null && genomeListItem.getPath() != null) { @@ -114,11 +111,6 @@ public void run() { return; } - UIUtilities.invokeAndWaitOnEventThread(() -> { - monitor = new org.broad.igv.ui.util.ProgressMonitor(); - progressDialog = ProgressBar.showProgressDialog(IGV.getInstance().getMainFrame(), "Loading Genome...", monitor, false); - }); - try { GenomeManager.getInstance().loadGenomeById(genomeListItem.getId()); } catch (GenomeServerException e) { @@ -139,9 +131,7 @@ public void run() { log.error("Error initializing genome", e); } } finally { - if (progressDialog != null) { - UIUtilities.invokeOnEventThread(() -> progressDialog.setVisible(false)); - } + } } @@ -257,7 +247,7 @@ public static void loadGenomeFromServer() { if (firstItem != null) { try { - GenomeManager.getInstance().loadGenome(firstItem.getPath(), null); + GenomeManager.getInstance().loadGenome(firstItem.getPath()); // If the user has previously defined this genome, remove it. GenomeListManager.getInstance().removeUserDefinedGenome(firstItem.getId()); diff --git a/src/main/java/org/broad/igv/ui/panel/DataPanelContainer.java b/src/main/java/org/broad/igv/ui/panel/DataPanelContainer.java index d1956cf1eb..b06b0358a4 100644 --- a/src/main/java/org/broad/igv/ui/panel/DataPanelContainer.java +++ b/src/main/java/org/broad/igv/ui/panel/DataPanelContainer.java @@ -234,7 +234,7 @@ public void drop(DropTargetDropEvent event) { if(HubGenomeLoader.isHubURL(obj)) { LongRunningTask.submit(() -> { try { - GenomeManager.getInstance().loadGenome(obj, null); + GenomeManager.getInstance().loadGenome(obj); } catch (IOException e) { MessageUtils.showMessage("Error loading track hub: " + e.getMessage()); } diff --git a/src/main/java/org/broad/igv/ui/util/CancellableProgressDialog.java b/src/main/java/org/broad/igv/ui/util/CancellableProgressDialog.java deleted file mode 100644 index 4ef6c14b2b..0000000000 --- a/src/main/java/org/broad/igv/ui/util/CancellableProgressDialog.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Created by JFormDesigner on Wed Mar 13 11:24:25 EDT 2013 - */ - -package org.broad.igv.ui.util; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -/** - * @author Jacob Silterra - */ -public class CancellableProgressDialog extends org.broad.igv.ui.IGVDialog { - public CancellableProgressDialog(Frame owner) { - super(owner); - initComponents(); - } - - public CancellableProgressDialog(Dialog owner) { - super(owner); - initComponents(); - } - - private void cancelButtonActionPerformed(ActionEvent e) { - setVisible(false); - } - - private void initComponents() { - // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents - // Generated using JFormDesigner non-commercial license - dialogPane = new JPanel(); - contentPanel = new JPanel(); - permText = new JLabel(); - vSpacer1 = new JPanel(null); - statusText = new JLabel(); - progressBar = new JProgressBar(); - buttonBar = new JPanel(); - hSpacer1 = new JPanel(null); - button = new JButton(); - hSpacer2 = new JPanel(null); - - //======== this ======== - setAlwaysOnTop(true); - Container contentPane = getContentPane(); - contentPane.setLayout(new BorderLayout()); - - //======== dialogPane ======== - { - dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); - dialogPane.setLayout(new BorderLayout()); - - //======== contentPanel ======== - { - contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); - contentPanel.add(permText); - - //---- vSpacer1 ---- - vSpacer1.setMaximumSize(new Dimension(12, 10)); - contentPanel.add(vSpacer1); - - //---- statusText ---- - statusText.setText("..."); - contentPanel.add(statusText); - contentPanel.add(progressBar); - } - dialogPane.add(contentPanel, BorderLayout.CENTER); - - //======== buttonBar ======== - { - buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); - buttonBar.setLayout(new GridLayout(1, 3)); - buttonBar.add(hSpacer1); - - //---- button ---- - button.setText("Cancel"); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - cancelButtonActionPerformed(e); - } - }); - buttonBar.add(button); - buttonBar.add(hSpacer2); - } - dialogPane.add(buttonBar, BorderLayout.SOUTH); - } - contentPane.add(dialogPane, BorderLayout.CENTER); - pack(); - setLocationRelativeTo(getOwner()); - // JFormDesigner - End of component initialization //GEN-END:initComponents - } - - // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables - // Generated using JFormDesigner non-commercial license - private JPanel dialogPane; - private JPanel contentPanel; - private JLabel permText; - private JPanel vSpacer1; - private JLabel statusText; - private JProgressBar progressBar; - private JPanel buttonBar; - private JPanel hSpacer1; - private JButton button; - private JPanel hSpacer2; - // JFormDesigner - End of variables declaration //GEN-END:variables - - public JProgressBar getProgressBar() { - return progressBar; - } - - public void addButtonActionListener(ActionListener cancelActionListener) { - button.addActionListener(cancelActionListener); - } - - public void setStatus(final String status) { - Runnable updater = new Runnable() { - @Override - public void run() { - statusText.setText(status); - } - }; - UIUtilities.invokeOnEventThread(updater); - } - - public void setPermText(final String perm){ - Runnable updater = new Runnable() { - @Override - public void run() { - permText.setText(perm); - } - }; - UIUtilities.invokeOnEventThread(updater); - } - - - /** - * Create a show a progress dialog with a single button (default text "Cancel") - * @param dialogsParent - * @param title - * @param buttonActionListener The {@code ActionListener} to be called when the button is pressed. - * @param autoClose Whether to automatically close the dialog when it's finished - * @param monitor Optional (may be null). Status text is updated based on monitor.updateStatus - * @return - */ - public static CancellableProgressDialog showCancellableProgressDialog(Frame dialogsParent, - String title, final - ActionListener buttonActionListener, - final boolean autoClose, ProgressMonitor monitor){ - final CancellableProgressDialog progressDialog = new CancellableProgressDialog(dialogsParent); - - progressDialog.setTitle(title); - progressDialog.addButtonActionListener(buttonActionListener); - - if(monitor != null && monitor instanceof IndefiniteProgressMonitor) progressDialog.getProgressBar().setIndeterminate(true); - - if(monitor != null){ - monitor.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(ProgressMonitor.STATUS_PROPERTY)) { - progressDialog.setStatus("" + evt.getNewValue()); - } else if (evt.getPropertyName().equals(ProgressMonitor.PROGRESS_PROPERTY) && (Integer) evt.getNewValue() >= 100) { - progressDialog.button.setText("Done"); - if(autoClose){ - progressDialog.button.doClick(1); - } - }else if (evt.getPropertyName().equals(ProgressMonitor.PROGRESS_PROPERTY)) { - progressDialog.getProgressBar().setValue((Integer) evt.getNewValue()); - } - } - }); - } - - progressDialog.setVisible(true); - progressDialog.toFront(); - - return progressDialog; - } - -} diff --git a/src/main/java/org/broad/igv/ui/util/IndefiniteProgressMonitor.java b/src/main/java/org/broad/igv/ui/util/IndefiniteProgressMonitor.java deleted file mode 100644 index 0b207b93ec..0000000000 --- a/src/main/java/org/broad/igv/ui/util/IndefiniteProgressMonitor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.broad.igv.ui.util; - -import java.util.Timer; -import java.util.TimerTask; - -/** - * @author jrobinso - */ -public class IndefiniteProgressMonitor extends ProgressMonitor { - - int cycleTime; - Timer timer; - - private static final int DEFAULT_CYCLE_TIME = 60; - - public IndefiniteProgressMonitor(){ - this(DEFAULT_CYCLE_TIME); - } - - private IndefiniteProgressMonitor(int cycleTime) { - this.cycleTime = cycleTime; - timer = new Timer(); - setReady(true); - } - - public void start() { - timer.schedule(new CycleTask(), 0, 1000); - } - - public void stop() { - timer.cancel(); - UIUtilities.invokeOnEventThread(() ->fireProgressChange(100)); - } - - class CycleTask extends TimerTask { - - boolean stop = false; - int progress = 0; - int progressIncrement = 0; - int direction = 1; - long lastTime = System.currentTimeMillis(); - - @Override - public void run() { - - - UIUtilities.invokeOnEventThread(() -> fireProgressChange(progressIncrement)); - - - long t = System.currentTimeMillis(); - progressIncrement = (int) (direction * (t - lastTime) / (10 * cycleTime)); - progress += progressIncrement; - if (progress >= 90) { - progress = 99; - direction = -1; - } else if (progress < - 0) { - progress = 1; - direction = 1; - } - lastTime = t; - } - } -} diff --git a/src/test/java/org/broad/igv/batch/CommandExecutorTest.java b/src/test/java/org/broad/igv/batch/CommandExecutorTest.java index c10dc56652..d2bc983405 100755 --- a/src/test/java/org/broad/igv/batch/CommandExecutorTest.java +++ b/src/test/java/org/broad/igv/batch/CommandExecutorTest.java @@ -106,7 +106,7 @@ public static int checkIsSorted(List tracks, RegionOfInterest roi, Region public void setUp() throws Exception { super.setUp(); Globals.setBatch(true); - GenomeManager.getInstance().loadGenome(TestUtils.defaultGenome, null); + GenomeManager.getInstance().loadGenome(TestUtils.defaultGenome); igv.newSession(); exec.setSnapshotDirectory(snapshotDir); } diff --git a/src/test/java/org/broad/igv/batch/CommandListenerTest.java b/src/test/java/org/broad/igv/batch/CommandListenerTest.java index 217dfa14f1..c245c860dc 100755 --- a/src/test/java/org/broad/igv/batch/CommandListenerTest.java +++ b/src/test/java/org/broad/igv/batch/CommandListenerTest.java @@ -68,7 +68,7 @@ public void setUp() throws Exception{ super.setUp(); CommandListener.halt(); CommandListener.start(port); - GenomeManager.getInstance().loadGenome(TestUtils.defaultGenome, null); + GenomeManager.getInstance().loadGenome(TestUtils.defaultGenome); } @After diff --git a/src/test/java/org/broad/igv/feature/genome/GenomeDescriptorTest.java b/src/test/java/org/broad/igv/feature/genome/GenomeDescriptorTest.java deleted file mode 100644 index 069c26478c..0000000000 --- a/src/test/java/org/broad/igv/feature/genome/GenomeDescriptorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.broad.igv.feature.genome; - -import org.broad.igv.feature.genome.load.GenomeDescriptor; -import org.broad.igv.util.TestUtils; -import org.junit.Test; - -import java.io.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * @author jrobinso - * @date Apr 28, 2011 - */ -public class GenomeDescriptorTest { - - /** - * Test the patch to fix legacy .genome files with incorrect sequence paths - */ - - @Test - public void testParseGenomeDescriptor() throws IOException { - - String path = TestUtils.DATA_DIR + "/genomes/hg18.unittest.genome"; - GenomeDescriptor descriptor = GenomeDescriptor.parseGenomeArchiveFile(new File(path)); - assertNotNull(descriptor); - assertEquals("hg18.unittest", descriptor.getId()); - InputStream is = descriptor.getCytoBandStream(); - assertNotNull(is); - is.close(); - descriptor.close(); - - - } -} diff --git a/src/test/java/org/broad/igv/feature/genome/GenomeImporterTest.java b/src/test/java/org/broad/igv/feature/genome/GenomeImporterTest.java deleted file mode 100644 index ef9d87b31e..0000000000 --- a/src/test/java/org/broad/igv/feature/genome/GenomeImporterTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.broad.igv.feature.genome; - -import org.broad.igv.AbstractHeadlessTest; -import org.broad.igv.util.TestUtils; -import org.junit.Test; - -import java.io.File; -import java.io.FilenameFilter; -import java.util.zip.ZipFile; - -import static junit.framework.Assert.*; - -/** - * User: jacob - * Date: 2012-Sep-06 - */ -public class GenomeImporterTest extends AbstractHeadlessTest { - - @Test - public void testCreateGenomeArchiveFromDir() throws Exception { - - File genomeFile = new File(TestUtils.TMP_OUTPUT_DIR, "testSetGenome.genome"); - genomeFile.deleteOnExit(); - String genomeId = "testSet"; - String genomeDisplayName = genomeId; - String fastaPath = TestUtils.DATA_DIR + "fasta/set"; - - deleteFaiFiles(fastaPath); - - File genomeArchive = (new GenomeImporter()).createGenomeArchive( - genomeFile, genomeId, genomeDisplayName, fastaPath, - null, null, null); - - assertNotNull(genomeArchive); - assertTrue(genomeArchive.exists()); - - deleteFaiFiles(fastaPath); - } - - /** - * Deletes all fasta index files in the provided path - * - * @param dir - */ - private void deleteFaiFiles(String dir) { - //Delete index files, if they exist - File fastaDir = new File(dir); - File[] idxFiles = fastaDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.endsWith(".fai"); - } - }); - - if(idxFiles == null) return; - - for (File idxFile : idxFiles) { - idxFile.delete(); - } - } -} diff --git a/src/test/java/org/broad/igv/feature/genome/GenomeManagerTest.java b/src/test/java/org/broad/igv/feature/genome/GenomeManagerTest.java index dcb885aecc..bf3ae887ec 100644 --- a/src/test/java/org/broad/igv/feature/genome/GenomeManagerTest.java +++ b/src/test/java/org/broad/igv/feature/genome/GenomeManagerTest.java @@ -31,12 +31,7 @@ package org.broad.igv.feature.genome; import org.broad.igv.AbstractHeadlessTest; -import org.broad.igv.DirectoryManager; -import org.broad.igv.prefs.Constants; -import org.broad.igv.prefs.PreferencesManager; import org.broad.igv.ui.commandbar.GenomeListManager; -import org.broad.igv.util.FileUtils; -import org.broad.igv.util.HttpUtils; import org.broad.igv.util.TestUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -45,7 +40,6 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.net.URL; import static org.junit.Assert.*; @@ -107,7 +101,7 @@ private void createDotGenomeForTest(String fastaFileName) throws IOException{ @Test public void testLoadGenomeFastaRelative() throws Exception{ createDotGenomeForTest(fastaFileRelPath); - Genome relGenome = GenomeManager.getInstance().loadGenome(genomeZipFile, null); + Genome relGenome = GenomeManager.getInstance().loadGenome(genomeZipFile); checkGenome(relGenome); } @@ -122,7 +116,7 @@ public void testLoadGenomeFastaAbsolute() throws Exception{ String fastaAbsPath = fastaFile.getAbsolutePath(); createDotGenomeForTest(fastaAbsPath); - Genome absGenome = GenomeManager.getInstance().loadGenome(genomeZipFile, null); + Genome absGenome = GenomeManager.getInstance().loadGenome(genomeZipFile); checkGenome(absGenome); } @@ -141,7 +135,7 @@ public void testLoadFastaOrdering() throws Exception{ String fastaPath = TestUtils.DATA_DIR + "fasta/out_order.fa"; TestUtils.createIndex(fastaPath); - Genome genome = GenomeManager.getInstance().loadGenome(fastaPath, null); + Genome genome = GenomeManager.getInstance().loadGenome(fastaPath); String[] chromos = {"chr1", "chr5"}; assertArrayEquals(chromos, genome.getAllChromosomeNames().toArray()); @@ -155,7 +149,7 @@ public void testLoadFastaOrdering() throws Exception{ @Test public void testLoadChromSizes() throws Exception { String testFile = TestUtils.DATA_DIR + "genomes/hg19.chrom.sizes"; - Genome genome = GenomeManager.getInstance().loadGenome(testFile, null); + Genome genome = GenomeManager.getInstance().loadGenome(testFile); assertEquals(37, genome.getAllChromosomeNames().size()); assertEquals(3130404865l, genome.getTotalLength()); diff --git a/src/test/java/org/broad/igv/feature/genome/GenomeTest.java b/src/test/java/org/broad/igv/feature/genome/GenomeTest.java index 67d3b81503..f00dd0dae3 100644 --- a/src/test/java/org/broad/igv/feature/genome/GenomeTest.java +++ b/src/test/java/org/broad/igv/feature/genome/GenomeTest.java @@ -40,7 +40,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static junit.framework.Assert.*; @@ -85,7 +84,7 @@ public void testAlias_02() throws Exception { private Genome loadGenomeAssumeSuccess(String genomeURL) { Genome genome = null; try { - genome = GenomeManager.getInstance().loadGenome(genomeURL, null); + genome = GenomeManager.getInstance().loadGenome(genomeURL); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/java/org/broad/igv/feature/genome/fasta/FastaUtilsTest.java b/src/test/java/org/broad/igv/feature/genome/fasta/FastaUtilsTest.java index ac94556f38..dd97dd0956 100644 --- a/src/test/java/org/broad/igv/feature/genome/fasta/FastaUtilsTest.java +++ b/src/test/java/org/broad/igv/feature/genome/fasta/FastaUtilsTest.java @@ -29,8 +29,6 @@ import org.broad.igv.exceptions.DataLoadException; import org.broad.igv.feature.genome.Genome; import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.feature.genome.fasta.FastaIndex; -import org.broad.igv.feature.genome.fasta.FastaUtils; import org.broad.igv.util.TestUtils; import org.junit.Ignore; import org.junit.Test; @@ -104,7 +102,7 @@ public void tstCreateIndex_02(String inPath) throws Exception { assertEquals(tG, entry.getContig()); GenomeManager manager = GenomeManager.getInstance(); - Genome genome = manager.loadGenome(inPath, null); + Genome genome = manager.loadGenome(inPath); String tAseq = new String(genome.getSequence(tA, 0, tAsize)); assertEquals(tAsize, tAseq.length()); String remmed = tAseq.replaceAll("A", ""); @@ -141,7 +139,7 @@ public void testCreateIndexEcoli() throws Exception { String outPath = tstCreateIndex(inPath); GenomeManager manager = GenomeManager.getInstance(); - Genome genome = manager.loadGenome(inPath, null); + Genome genome = manager.loadGenome(inPath); String chr = "gi|110640213|ref|NC_008253.1|"; assertNotNull(genome.getChromosome(chr)); //See http://www.ncbi.nlm.nih.gov/nuccore/110640213 diff --git a/src/test/java/org/broad/igv/sam/cram/CRAMReaderTest.java b/src/test/java/org/broad/igv/sam/cram/CRAMReaderTest.java index 9f4347629e..aa295d8dbd 100644 --- a/src/test/java/org/broad/igv/sam/cram/CRAMReaderTest.java +++ b/src/test/java/org/broad/igv/sam/cram/CRAMReaderTest.java @@ -34,10 +34,8 @@ import htsjdk.samtools.util.CloseableIterator; import org.broad.igv.Globals; import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.sam.Alignment; import org.broad.igv.sam.SAMAlignment; import org.broad.igv.sam.reader.BAMReader; -import org.broad.igv.sam.reader.SAMReader; import org.broad.igv.util.ResourceLocator; import org.broad.igv.util.TestUtils; import org.junit.AfterClass; @@ -71,7 +69,7 @@ public static void tearDownClass() throws Exception { public void testIterateLocalCraiCram() throws Exception { String cramFile = TestUtils.DATA_DIR + "cram/cram_with_crai_index.cram"; - GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta", null); + GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta"); BAMReader reader = new BAMReader(new ResourceLocator(cramFile), true); @@ -89,7 +87,7 @@ public void testIterateLocalCraiCram() throws Exception { public void testQueryLocalCraiCram() throws Exception { String cramFile = TestUtils.DATA_DIR + "cram/cram_with_crai_index.cram"; - GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta", null); + GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta"); BAMReader reader = new BAMReader(new ResourceLocator(cramFile), true); @@ -103,7 +101,7 @@ public void testQueryLocalCraiCram() throws Exception { public void testQueryLocalBaiCram() throws Exception { String cramFile = TestUtils.DATA_DIR + "cram/cram_with_bai_index.cram"; - GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta", null); + GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta"); BAMReader reader = new BAMReader(new ResourceLocator(cramFile), true); @@ -118,7 +116,7 @@ public void testQueryLocalBaiCram() throws Exception { public void testRemoteCraiCram() throws Exception { String cramFile = "https://s3.amazonaws.com/igv.broadinstitute.org/test/cram/cram_with_crai_index.cram"; - GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta", null); + GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta"); BAMReader reader = new BAMReader(new ResourceLocator(cramFile), true); @@ -132,7 +130,7 @@ public void testRemoteCraiCram() throws Exception { public void testRemoteBaiCram() throws Exception { String cramFile = TestUtils.DATA_DIR + "cram/cram_with_bai_index.cram"; - GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta", null); + GenomeManager.getInstance().loadGenome(TestUtils.DATA_DIR + "cram/hg19mini.fasta"); BAMReader reader = new BAMReader(new ResourceLocator(cramFile), true); diff --git a/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java b/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java index 3589ac4cd3..24b4bd4112 100644 --- a/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java +++ b/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java @@ -53,7 +53,7 @@ public void setUp() throws Exception { } private void assertReferenceReqionRequestsWork(final String fastaUrl) throws IOException { - GenomeManager.getInstance().loadGenome(fastaUrl, null); + GenomeManager.getInstance().loadGenome(fastaUrl); IGVReferenceSource refSource = new IGVReferenceSource(); String expected = EXPECTED_REFERENCE_BASES; @@ -76,7 +76,7 @@ public void testGetReferenceBasesByRegionCompressed() throws Exception { @Test public void testGetReferenceBasesCompressed() throws Exception { - GenomeManager.getInstance().loadGenome(COMPRESSED_FASTA_URL, null); + GenomeManager.getInstance().loadGenome(COMPRESSED_FASTA_URL); IGVReferenceSource refSource = new IGVReferenceSource(); SAMSequenceRecord rec = new SAMSequenceRecord("22", 50818468); diff --git a/src/test/java/org/broad/igv/tdf/TDFRegressionTests.java b/src/test/java/org/broad/igv/tdf/TDFRegressionTests.java index 84ea611d33..1b57b955f4 100644 --- a/src/test/java/org/broad/igv/tdf/TDFRegressionTests.java +++ b/src/test/java/org/broad/igv/tdf/TDFRegressionTests.java @@ -41,7 +41,6 @@ import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import java.io.IOException; import java.util.List; import static org.junit.Assert.*; @@ -118,7 +117,7 @@ private boolean overlaps(long start, long end, LocusScore score){ public void tstCHR_ALL(String genPath, String wigPath, String tdfPath, boolean expHaveChrAll, String[] posChromos, String[] emptyChromos) throws Exception{ Genome genome = null; try { - genome = GenomeManager.getInstance().loadGenome(genPath, null); + genome = GenomeManager.getInstance().loadGenome(genPath); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/java/org/broad/igv/tools/FeatureSearcherTest.java b/src/test/java/org/broad/igv/tools/FeatureSearcherTest.java deleted file mode 100644 index d7b0e0af22..0000000000 --- a/src/test/java/org/broad/igv/tools/FeatureSearcherTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2007-2015 Broad Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.broad.igv.tools; - -import org.broad.igv.AbstractHeadlessTest; -import org.broad.igv.feature.tribble.TribbleIndexNotFoundException; -import org.broad.igv.track.FeatureSource; -import org.broad.igv.track.TribbleFeatureSource; -import org.broad.igv.util.LongRunningTask; -import org.broad.igv.util.ResourceLocator; -import org.broad.igv.util.TestUtils; -import htsjdk.tribble.Feature; -import org.junit.Test; - -import java.io.IOException; - -import static junit.framework.Assert.*; - -/** - * User: jacob - * Date: 2013-Feb-21 - */ -public class FeatureSearcherTest extends AbstractHeadlessTest { - - @Test - public void testSearchInWindow() throws Exception{ - tstSearchInWindow(true); - tstSearchInWindow(false); - } - - @Test - public void testSearchOutsideWindow() throws Exception{ - tstSearchOutsideWindow(true); - tstSearchOutsideWindow(false); - } - - @Test - public void testSearchOutsideWindowBackwards() throws Exception{ - //tstSearchOutsideWindowBackwards(true); - tstSearchOutsideWindowBackwards(false); - } - - @Test - public void testSearchNextChromo() throws Exception{ - tstSearchDifferentChromo(true); - tstSearchDifferentChromo(false); - } - - /** - * Runs the search, either on this thread or a different one. - * In either case blocks until the searching is done - * @param searcher - * @param sepThread - * @throws Exception - */ - private void runSearch(FeatureSearcher searcher, boolean sepThread) throws Exception{ - - assertFalse(searcher.isDone()); - assertNull(searcher.getResult()); - - if(sepThread){ - LongRunningTask.getThreadExecutor().execute(searcher); - //Tacky, but it should take <1000 mSec to start the search - Thread.sleep(1000); - while(!searcher.isDone()){ - Thread.sleep(100); - } - }else{ - searcher.run(); - } - } - - public void tstSearchInWindow(boolean sepThread) throws Exception{ - - FeatureSearcher searcher = new FeatureSearcher(getTestBedSource(), genome, "chr1", 0); - - runSearch(searcher, sepThread); - - Feature feat = searcher.getResult().next(); - - assertEquals("chr1", feat.getChr()); - assertEquals(100, feat.getStart()); - assertEquals(101, feat.getEnd()); - } - - public void tstSearchOutsideWindow(boolean sepThread) throws Exception{ - - FeatureSearcher searcher = new FeatureSearcher(getTestBedSource(), genome, "chr1", 500); - searcher.setSearchIncrement(10000); - - runSearch(searcher, sepThread); - - Feature feat = searcher.getResult().next(); - - assertEquals("chr1", feat.getChr()); - assertEquals(100000, feat.getStart()); - assertEquals(100010, feat.getEnd()); - } - - public void tstSearchOutsideWindowBackwards(boolean sepThread) throws Exception{ - - FeatureSearcher searcher = new FeatureSearcher(getTestBedSource(), genome, "chr1", 500000); - searcher.setSearchIncrement(-10000); - - runSearch(searcher, sepThread); - - Feature feat = searcher.getResult().next(); - - assertEquals("chr1", feat.getChr()); - assertEquals(100000, feat.getStart()); - assertEquals(100010, feat.getEnd()); - } - - public void tstSearchDifferentChromo(boolean sepThread) throws Exception{ - - FeatureSearcher searcher = new FeatureSearcher(getTestBedSource(), genome, "chr1", 500000); - searcher.setSearchIncrement(10000); - - runSearch(searcher, sepThread); - - Feature feat = searcher.getResult().next(); - - assertEquals("chr2", feat.getChr()); - assertEquals(1, feat.getStart()); - assertEquals(10, feat.getEnd()); - } - - public FeatureSource getTestBedSource() throws IOException, TribbleIndexNotFoundException { - String path = TestUtils.DATA_DIR + "bed/test.bed"; - TestUtils.createIndex(path); - return TribbleFeatureSource.getFeatureSource(new ResourceLocator(path), genome); - } - -} diff --git a/src/test/java/org/broad/igv/ui/AbstractHeadedTest.java b/src/test/java/org/broad/igv/ui/AbstractHeadedTest.java index 1e67771526..806097f4e3 100644 --- a/src/test/java/org/broad/igv/ui/AbstractHeadedTest.java +++ b/src/test/java/org/broad/igv/ui/AbstractHeadedTest.java @@ -28,7 +28,6 @@ import org.broad.igv.Globals; import org.broad.igv.feature.genome.Genome; import org.broad.igv.feature.genome.GenomeManager; -import org.broad.igv.track.Track; import org.broad.igv.util.TestUtils; import org.junit.*; import org.junit.rules.TestRule; @@ -36,7 +35,6 @@ import javax.swing.*; import java.awt.*; -import java.io.File; import java.io.IOException; import static org.junit.Assert.assertTrue; @@ -124,7 +122,7 @@ protected static IGV startGUI(String genomeFile) throws IOException { assertTrue(IGV.getInstance().waitForNotify(1000)); } if (genomeFile != null) { - GenomeManager.getInstance().loadGenome(genomeFile, null); + GenomeManager.getInstance().loadGenome(genomeFile); genome = GenomeManager.getInstance().getCurrentGenome(); } return igv;