Skip to content

Commit

Permalink
Allow refreshing annotations without downloading sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 18, 2024
1 parent b9ff7df commit ed7b967
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
66 changes: 46 additions & 20 deletions src/main/java/org/broad/igv/feature/genome/GenomeDownloadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.ui.IGV;
import org.broad.igv.ui.util.MessageUtils;
import org.broad.igv.ui.util.download.Downloader;
import org.broad.igv.util.HttpUtils;

Expand Down Expand Up @@ -63,32 +64,45 @@ public static File downloadGenome(GenomeConfig config, boolean downloadSequence,

if (config.getTwoBitURL() != null) {

localFile = download(new URL(config.getTwoBitURL()), dataDirectory);
config.setTwoBitURL(relativeDataDirectory + localFile.getName());
localFile = constructLocalFile(new URL(config.getTwoBitURL()), dataDirectory);

// Null out urls not needed for .2bit seequences.
config.setFastaURL(null);
config.setIndexURL(null);
config.setGziIndexURL(null);
// .2bit files can be large, if it already exists confirm before replacing.
if(!localFile.exists() || MessageUtils.confirm("Replace existing file: " + localFile.getName() + "?")) {

// The optional btree index. This is probably not needed for local file configurations.
if (config.getTwoBitBptURL() != null) {
localFile = download(new URL(config.getTwoBitBptURL()), dataDirectory);
config.setTwoBitBptURL(relativeDataDirectory + localFile.getName());
download(new URL(config.getTwoBitURL()), localFile);

config.setTwoBitURL(relativeDataDirectory + localFile.getName());

// Null out urls not needed for .2bit seequences.
config.setFastaURL(null);
config.setIndexURL(null);
config.setGziIndexURL(null);

// The optional btree index. This is probably not needed for local file configurations.
if (config.getTwoBitBptURL() != null) {
localFile = download(new URL(config.getTwoBitBptURL()), dataDirectory);
config.setTwoBitBptURL(relativeDataDirectory + localFile.getName());
}
}
} else if (config.getFastaURL() != null) {

localFile = download(new URL(config.getFastaURL()), dataDirectory);
config.setFastaURL(relativeDataDirectory + localFile.getName());
if (config.getIndexURL() != null) {
localFile = download(new URL(config.getIndexURL()), dataDirectory);
config.setIndexURL(relativeDataDirectory + localFile.getName());
}
if (config.getGziIndexURL() != null) {
localFile = download(new URL(config.getGziIndexURL()), dataDirectory);
config.setGziIndexURL(relativeDataDirectory + localFile.getName());
}
localFile = constructLocalFile(new URL(config.getFastaURL()), dataDirectory);

if(!localFile.exists() || MessageUtils.confirm("Replace existing file: " + localFile.getName() + "?")) {

localFile = download(new URL(config.getFastaURL()), localFile);

// Fasta files can be large, if it already exists confirm before replacing.
config.setFastaURL(relativeDataDirectory + localFile.getName());
if (config.getIndexURL() != null) {
localFile = download(new URL(config.getIndexURL()), dataDirectory);
config.setIndexURL(relativeDataDirectory + localFile.getName());
}
if (config.getGziIndexURL() != null) {
localFile = download(new URL(config.getGziIndexURL()), dataDirectory);
config.setGziIndexURL(relativeDataDirectory + localFile.getName());
}
}
} else {
throw new RuntimeException("Sequence for genome " + config.getName() + " is not downloadable.");
}
Expand Down Expand Up @@ -152,11 +166,23 @@ private static void saveLocalGenome(GenomeConfig genomeConfig, File localFile) t
}
}


private static File constructLocalFile(URL url, File directory) throws MalformedURLException {
String path = url.getPath();
int idx = path.lastIndexOf('/');
String filename = idx < 0 ? path : path.substring(idx + 1);
return new File(directory, filename);
}

private static File download(URL url, File directory) throws MalformedURLException {
String path = url.getPath();
int idx = path.lastIndexOf('/');
String filename = idx < 0 ? path : path.substring(idx + 1);
File localFile = new File(directory, filename);
return getFile(url, localFile);
}

private static File getFile(URL url, File localFile) throws MalformedURLException {
boolean success = Downloader.download(url, localFile, IGV.getInstance().getMainFrame());
if (!success) {
throw new RuntimeException("Download canceled");
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/broad/igv/feature/genome/load/GenomeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,14 @@ public void setChromSizesURL(String chromSizesURL) {
this.chromSizesURL = chromSizesURL;
}

public List<TrackConfig> getTracks() {
return tracks;
public List<TrackConfig> getTrackConfigs() {
return tracks != null ? tracks : annotations;
}

public void setTracks(List<TrackConfig> tracks) {
this.tracks = tracks;
}

public List<TrackConfig> getAnnotations() {
return annotations;
}

public void setAnnotations(List<TrackConfig> annotations) {
this.annotations = annotations;
}

public Sequence getSequence() {
return sequence;
}
Expand Down

0 comments on commit ed7b967

Please sign in to comment.