Skip to content

Commit

Permalink
bug fix -- not all fields in genome.json were handled for local genom…
Browse files Browse the repository at this point in the history
…es with relative paths.
  • Loading branch information
jrobinso committed Sep 27, 2024
1 parent 51e5288 commit f3233fc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/feature/genome/Genome.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Genome(GenomeConfig config) throws IOException {
} else if (config.fastaURL != null) {
String fastaPath = config.fastaURL;
String indexPath = config.indexURL;
String gziIndexPath = config.gziIndexURL;
String gziIndexPath = config.gziIndexURL != null ? config.gziIndexURL : config.compressedIndexURL; // Synonyms
uncachedSequence = fastaPath.endsWith(".gz") ?
new FastaBlockCompressedSequence(fastaPath, gziIndexPath, indexPath) :
new FastaIndexedSequence(fastaPath, indexPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ private String fixChromosomeOrder(String jsonString) {
* @return
*/
private GenomeConfig fixPaths(GenomeConfig config) {

if (config.chromAliasBbURL != null) {
config.chromAliasBbURL = FileUtils.getAbsolutePath(config.chromAliasBbURL, genomePath);
}
if (config.twoBitURL != null) {
config.twoBitURL = FileUtils.getAbsolutePath(config.twoBitURL, genomePath);
}
if (config.cytobandBbURL != null) {
config.cytobandBbURL = FileUtils.getAbsolutePath(config.cytobandBbURL, genomePath);
}
if (config.chromSizesURL != null) {
config.chromSizesURL = FileUtils.getAbsolutePath(config.chromSizesURL, genomePath);
}
if (config.fastaURL != null) {
config.fastaURL = FileUtils.getAbsolutePath(config.fastaURL, genomePath);
}
Expand All @@ -108,6 +121,9 @@ private GenomeConfig fixPaths(GenomeConfig config) {
if (config.gziIndexURL != null) {
config.gziIndexURL = FileUtils.getAbsolutePath(config.gziIndexURL, genomePath);
}
if (config.compressedIndexURL != null) {
config.compressedIndexURL = FileUtils.getAbsolutePath(config.compressedIndexURL, genomePath);
}
if (config.cytobandURL != null) {
config.cytobandURL = FileUtils.getAbsolutePath(config.cytobandURL, genomePath);
}
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/org/broad/igv/ui/commandbar/GenomeListManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,28 @@ private static Map<String, GenomeListItem> getCachedGenomeList() {
JsonObject json = rootElement.getAsJsonObject();
JsonElement id = json.get("id");
JsonElement name = json.get("name");
JsonElement fastaURL = json.get("fastaURL");
if (id != null && name != null && fastaURL != null) {
if (cachedGenomes.containsKey(id.getAsString())) {
File prevFile = new File(cachedGenomes.get(id.getAsString()).getPath());
prevFile.delete();
}
GenomeListItem item = new GenomeListItem(name.getAsString(), file.getAbsolutePath(), id.getAsString());
cachedGenomes.put(item.getId(), item);
JsonElement fasta = json.get("fastaURL");
JsonElement twobit = json.get("twoBitURL");
if (id == null) {
log.error("Error parsing " + file.getName() + ". \"id\" is required");
continue;
}
if (name == null) {
log.error("Error parsing " + file.getName() + ". \"name\" is required");
continue;
}
if (id == null) {
log.error("Error parsing " + file.getName() + ". \"id\" is required");
continue;
}
if (fasta == null && twobit == null) {
log.error("Error parsing " + file.getName() + ". One of either \"fastaURL\" or \"twoBitURL\" is required");
continue;
}

GenomeListItem item = new GenomeListItem(name.getAsString(), file.getAbsolutePath(), id.getAsString());
cachedGenomes.put(item.getId(), item);

}
} catch (Exception e) {
log.error("Error parsing genome json: " + file.getAbsolutePath(), e);
Expand Down Expand Up @@ -316,7 +329,7 @@ public void removeGenomeListItem(GenomeListItem genomeListItem) {

// If this is a cached genome remove it from cache
Map<String, GenomeListItem> cachedItems = getCachedGenomeList();
if(cachedItems.containsKey(id)){
if (cachedItems.containsKey(id)) {
try {
(new File(genomeListItem.getPath())).delete();
} catch (Exception e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/broad/igv/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,11 @@ public static String getFileExtension(String filePath) {
* @return
*/
public static String getAbsolutePath(String inputPath, String referencePath) {

if (isRemote(inputPath) || referencePath == null) {
return inputPath;
}

File inFile = new File(inputPath);
if (inFile.isAbsolute()) {
return inFile.getAbsolutePath();
Expand Down

0 comments on commit f3233fc

Please sign in to comment.