Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from igvteam:main #7

Open
wants to merge 131 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
48f06fe
base mod popup text bug
jrobinso Jul 24, 2024
5e88611
Create gradle.yml
jrobinso Jul 24, 2024
1648696
update badge
jrobinso Jul 24, 2024
e5e6254
Update gradle.yml
jrobinso Jul 24, 2024
d4e05b7
Add right-click menu option to remove empty track panels
jrobinso Jul 25, 2024
9c78e80
Restore cluster menu option for 3rd gen alignments, renamed to "Clus…
jrobinso Jul 25, 2024
e976e70
cleanup
jrobinso Jul 25, 2024
4e79005
Bug fix -- errors saving session on shutdown could hang IGV, necessit…
jrobinso Jul 25, 2024
0072026
Handle startup errors due to corrupt .genome files.
jrobinso Jul 25, 2024
735d626
Map legacy URLs before opening connection input stream
jrobinso Jul 25, 2024
e9ccb3b
update default genome to hg38
jrobinso Jul 25, 2024
0f0b4fb
Check RNA stats before 3rd gen to detect long-read rna seq. Fixes #1…
jrobinso Jul 26, 2024
a4cd2d5
Expanded insertion issue - collapsing seemed to shift view, due to at…
jrobinso Jul 26, 2024
cf9dc34
Change "hide small indels" default for 3rd gen to false
jrobinso Jul 26, 2024
0e6b0e8
Don't popup information if size is < hidel small indel threshold. Fi…
jrobinso Jul 26, 2024
b1510d0
Proxy server for testing.
jrobinso Jul 26, 2024
bf7f46f
Cleanup git ignore
jrobinso Jul 30, 2024
fa87234
Restore center-on-click to ruler panel. Fixes #1538
jrobinso Aug 3, 2024
7663069
Clip splice junction arcs at junction boundaries. Fix for Bezier cur…
jrobinso Aug 12, 2024
8c599b8
compute long chr names for chrom.sizes file
jrobinso Aug 12, 2024
1a426ee
Fix unit tests and issue with "chrom.sizes" genomes.
jrobinso Aug 13, 2024
71e111a
Fix logic searching for features containing a position. Fixes #1541
jrobinso Aug 14, 2024
b730c8a
Clarify zoom in instructions for whole genome view. Fixes #1539
jrobinso Aug 14, 2024
d372765
Move the amazon credentials check at startup into an async thread (#1…
lbergelson Aug 14, 2024
b611dbc
Update dependencies to fix vulnerabilities (#1544)
lbergelson Aug 15, 2024
1ed0fc4
Use specifed nameSet, if specified, for whole genome and pulldown chr…
jrobinso Aug 16, 2024
cc37d33
Adding additional options for duplicate reads. (#1542)
lbergelson Aug 18, 2024
0d4375d
SpliceJunction tracks now honor manual color setttings (#1546)
lbergelson Aug 18, 2024
3f4d87b
Alignment track - don't repack on drag unless in FULL mode
jrobinso Aug 20, 2024
4a739bf
Unit test maintenance
jrobinso Aug 20, 2024
916c173
Simplify genome selection dialog
jrobinso Aug 20, 2024
c597d32
Display unrecognized modifications in popup text
jrobinso Sep 1, 2024
7aca9ea
Introduce hidden preference for default oAuth provisioning url
jrobinso Sep 4, 2024
15d7569
Look for "TS" attribute to determine transcript strand. See #1558
jrobinso Sep 4, 2024
1767b02
Delete unused Apache Tomcat Utils package (#1562)
lbergelson Sep 5, 2024
8b364e7
Changes to support BB files with alternative layouts, specifically ch…
jrobinso Sep 5, 2024
1bb1bd1
Refactor BB reader to conform more closely to spec -- no assumptions …
jrobinso Sep 8, 2024
ab89ab9
Remove "snappy" dependency
jrobinso Sep 9, 2024
c265c9d
Disable "snappy" for command line igvtools
jrobinso Sep 9, 2024
4521c92
disable snappy, second attempt
jrobinso Sep 9, 2024
5b18361
disable snappy 3
jrobinso Sep 10, 2024
97dd56d
Improve behavior of the Hide small indels menu option (#1564)
lbergelson Sep 10, 2024
5a9c3ec
Add basemod colors for 3 chebi codes. See #1563 (#1566)
jrobinso Sep 10, 2024
e8e38e1
Genome loading refactor to recover gracefully on startup errors (#1553)
jrobinso Sep 10, 2024
e658784
Update to Java 21 and gradle 8.10.1 (#1568)
lbergelson Sep 13, 2024
b3689ee
remove test generated file
jrobinso Sep 11, 2024
bfd072f
Update jdk-17 references to jdk-21
jrobinso Sep 14, 2024
e16fd78
Update mac startup script for jdk 21
jrobinso Sep 15, 2024
068e20a
Replace compiled shell script MacOS launcher
jrobinso Sep 16, 2024
4448888
Update CRAM reference test to include a genbank (gbk) referece with c…
jrobinso Sep 20, 2024
9170e30
Clarify sequence name mismatch error message
jrobinso Sep 25, 2024
907726c
Fix for 2bit reference crash when reading the end of the reference (#…
lbergelson Sep 25, 2024
6203b45
Correct rendered range of symbolic VCF alleles (#1580)
ctsa Sep 26, 2024
40869ad
Restore hosted genome selection behavior -- json is downloaded to "ge…
jrobinso Sep 26, 2024
dee6708
BB parsing bug - wrong offset for chromTree
jrobinso Sep 27, 2024
1347745
Don't check for "load from server" files in advance -- it can take up…
jrobinso Sep 27, 2024
ab536a5
bug...
jrobinso Sep 27, 2024
c7ef831
Genome improvements (#1589)
jrobinso Sep 27, 2024
dedd7fc
Remove Snappy to avoid issues with notarization (#1571)
lbergelson Sep 27, 2024
2838c30
Bug in chromosome aliasing affecting genbank files. See #1573
jrobinso Sep 30, 2024
5629b43
* Catch errors in sampling alignments to determine experiment type.
jrobinso Sep 30, 2024
c644d51
fix for chrom alias defaults
jrobinso Sep 30, 2024
c4f3ce7
Bug fix -- bigbed parsing fails if there are comments in autoSql.
jrobinso Oct 2, 2024
ea97115
update mac launcher
jrobinso Oct 3, 2024
dc196dd
Encode (#1594)
jrobinso Oct 7, 2024
51ced33
Fix issue1512 (#1590)
kunmonster Oct 7, 2024
15e8c2a
null check
jrobinso Oct 7, 2024
4778137
Extend file format determination code.
jrobinso Oct 9, 2024
c0e7f09
Fix for Amazon failing. (#1599)
lbergelson Oct 11, 2024
bfaab9d
lowercase for fileformat comparison
jrobinso Oct 13, 2024
f36d4cc
Rename ENCODE items
jrobinso Oct 14, 2024
d0afb72
Genomes (#1603)
jrobinso Oct 19, 2024
2ed14fc
bug fix for fasta genome
jrobinso Oct 19, 2024
20da885
"Copy read details" issue #1604
jrobinso Oct 21, 2024
af07c3b
Refactor "copy read details" code, and minor reformatting of output.
jrobinso Oct 21, 2024
07a8c59
GFF3 parsing error -- fixes #1617 (#1618)
jrobinso Nov 18, 2024
004130e
Add case-insensitive search to chrom aliasing code (#1621)
jrobinso Nov 19, 2024
5a9d821
Add Recent Files Menu and Improve Recent Sessions (#1616)
lbergelson Nov 19, 2024
f88feb4
Re-enable tooltip updates on DataPanel (#1615)
lbergelson Nov 19, 2024
a524c97
update registry URL
jrobinso Nov 20, 2024
36a952b
Add READ_ORDER to ColorBy list (#1622)
DevangThakkar Nov 22, 2024
772ee4b
ignore htsget bam test -- server no longer active
jrobinso Nov 27, 2024
d628f71
update mac IGV launcher to universal build
jrobinso Dec 3, 2024
ce6a9e1
hack for deleting "snappy" from the mac distribution
jrobinso Dec 3, 2024
fade54b
Add gradle tasks to build both intel & apple silicon packages
jrobinso Dec 3, 2024
75fe8eb
Redo ENCODE menu items to eliminate need for a section label. The la…
jrobinso Dec 3, 2024
a67652a
refine genome "is downloadable" tests
jrobinso Dec 4, 2024
900ca32
Genomes -- use radio buttons for genome download options.
jrobinso Dec 4, 2024
10abc52
genome download dialog refinements
jrobinso Dec 4, 2024
7884349
ditto
jrobinso Dec 4, 2024
e4ded57
rollback
jrobinso Dec 4, 2024
f4287ff
null check for tooltip text
jrobinso Dec 4, 2024
76584da
Disable memory-mapped index files. This is not needed for IGV, and c…
jrobinso Dec 9, 2024
8a80a57
Fix unmatched quotation mark in README Windows build instructions (#1…
VerisimilitudeX Dec 18, 2024
3a9ef80
Relax implicit assumption in FeatureCache that features are grouped b…
jrobinso Jan 3, 2025
bc00717
Interaction track improvements (#1635)
jrobinso Jan 5, 2025
95350f6
Determine bed file sub-type from track line when specified
jrobinso Jan 14, 2025
3d4b47e
fix logic for bed file type determination
jrobinso Jan 14, 2025
6429dac
S3 (#1639)
jrobinso Jan 17, 2025
a37cff6
Enable linked read preferences, previously these were no-ops (#1645)
jrobinso Jan 25, 2025
d4e2f6f
Track hubs (#1646)
jrobinso Jan 26, 2025
c2691bd
Hub track menu improvements -- collapsible categories (#1648)
jrobinso Jan 27, 2025
3bf983d
fix diagnostic messages from startup scripts
jrobinso Feb 4, 2025
9df5975
Additional track hub support: (#1651)
jrobinso Feb 4, 2025
991f01e
Additional track hub support: (#1651)
jrobinso Feb 4, 2025
b1a1701
Merge branch 'main' into track_hubs
jrobinso Feb 8, 2025
eb810fb
Merge branch 'track_hubs'
jrobinso Feb 8, 2025
066f3af
Bug fix - "Select hosted genomes" did not download.
jrobinso Feb 10, 2025
0d627c7
Revert hub change
jrobinso Feb 10, 2025
620cf91
Add a module requirement on commons compress (#1656)
lbergelson Feb 11, 2025
3c45e56
Catch error instead of exception in longrunning task (#1655)
lbergelson Feb 12, 2025
74acc21
Account for hard clipping in reported read sequence length. See #1658
jrobinso Feb 13, 2025
fac0c02
Track hub refinements
jrobinso Feb 15, 2025
0c11f18
Track hub load improvements. Add search ability if # of tracks in a…
jrobinso Feb 18, 2025
9e7dae8
Add search button for track hub track selection
jrobinso Feb 18, 2025
6b8e8bd
Add track group name to search widget
jrobinso Feb 18, 2025
20dea34
bugs
jrobinso Feb 19, 2025
9d0f246
export all packages. Add implied index for vcfTabix file types
jrobinso Feb 20, 2025
563642c
Large track hubs (#1660)
jrobinso Feb 25, 2025
25fc5ef
missing icons
jrobinso Feb 25, 2025
f035e7f
fix case issue
jrobinso Feb 26, 2025
9c2f03e
minor UI improvements
jrobinso Feb 26, 2025
98441e3
bug fix -- side effects from rendering VCF track name
jrobinso Feb 28, 2025
d19aba8
track load and genome definition refinements.
jrobinso Mar 4, 2025
12b00df
Add wait cursor for genark hub loads. Some can take time to load.
jrobinso Mar 4, 2025
47942ca
spinner and track selection refinements
jrobinso Mar 5, 2025
d161e0e
Refactoring
jrobinso Mar 6, 2025
913bbbf
Parsing fixes from more hub testing
jrobinso Mar 6, 2025
99a96b6
Add "toBedgraph" option to igv tools gui (tdf -> bedgraph conversion)
jrobinso Mar 7, 2025
bc268b9
Refactoring, streamline genome list (#1670)
jrobinso Mar 10, 2025
9996f4c
Track panel refactor (#1673)
jrobinso Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Genome improvements (igvteam#1589)
Refactoring genome load management to simplify code.
  • Loading branch information
jrobinso authored Sep 27, 2024
commit c7ef831eb4ee66e0e1beecb48fe5298e4caef8d0
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 @@ -125,7 +125,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
61 changes: 31 additions & 30 deletions src/main/java/org/broad/igv/feature/genome/GenomeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private GenomeManager() {
* @throws UnsupportedEncodingException
*/
public static File getGenomeFile(String genomePath) throws MalformedURLException, UnsupportedEncodingException {

File archiveFile;

if (HttpUtils.isRemoteURL(genomePath.toLowerCase())) {
// We need a local copy, as there is no http zip file reader
URL genomeArchiveURL = HttpUtils.createURL(genomePath);
Expand Down Expand Up @@ -195,10 +197,11 @@ public Genome loadGenome(String genomePath) throws IOException {
Genome newGenome = GenomeLoader.getLoader(genomePath).loadGenome();

// Load user-defined chr aliases, if any. This is done last so they have priority
final File genomeCacheDirectory = DirectoryManager.getGenomeCacheDirectory();
try {
String aliasPath = (new File(DirectoryManager.getGenomeCacheDirectory(), newGenome.getId() + "_alias.tab")).getAbsolutePath();
String aliasPath = (new File(genomeCacheDirectory, newGenome.getId() + "_alias.tab")).getAbsolutePath();
if (!(new File(aliasPath)).exists()) {
aliasPath = (new File(DirectoryManager.getGenomeCacheDirectory(), newGenome.getId() + "_alias.tab.txt")).getAbsolutePath();
aliasPath = (new File(genomeCacheDirectory, newGenome.getId() + "_alias.tab.txt")).getAbsolutePath();
}
if ((new File(aliasPath)).exists()) {
newGenome.addChrAliases(ChromAliasParser.loadChrAliases(aliasPath));
Expand All @@ -212,7 +215,13 @@ public Genome loadGenome(String genomePath) throws IOException {
IGV.getInstance().resetSession(null);
}

setCurrentGenome(genomePath, newGenome);
// If the genome is loaded from anywhere other than the cache directory add an entry to the pulldown
if(newGenome != null && !(new File(genomePath).getParentFile().equals(genomeCacheDirectory))) {
GenomeListItem genomeListItem = new GenomeListItem(newGenome.getDisplayName(), genomePath, newGenome.getId());
GenomeListManager.getInstance().addGenomeItem(genomeListItem, true);
}

setCurrentGenome(newGenome);

return currentGenome;

Expand All @@ -226,13 +235,7 @@ public Genome loadGenome(String genomePath) throws IOException {
}
}

public void setCurrentGenome(String genomePath, Genome newGenome) {

GenomeListItem genomeListItem = new GenomeListItem(newGenome.getDisplayName(), genomePath, newGenome.getId());
final Set<String> serverGenomeIDs = genomeListManager.getServerGenomeIDs();

boolean userDefined = !serverGenomeIDs.contains(newGenome.getId());
genomeListManager.addGenomeItem(genomeListItem, userDefined);
public void setCurrentGenome(Genome newGenome) {

this.currentGenome = newGenome;

Expand Down Expand Up @@ -354,26 +357,32 @@ public Genome getCurrentGenome() {
}


public boolean downloadGenome(GenomeListItem item, boolean downloadSequence) {
public boolean downloadGenome(GenomeListItem item, boolean downloadDataFiles) {

boolean success;
try {
File genomeFile = getGenomeFile(item.getPath()); // Has side affect of downloading .genome file
if (downloadSequence) {
String fastaPath = null;
File genomeFile = getGenomeFile(item.getPath()); // Has side affect of downloading .genome file

if (downloadDataFiles) {


if (item.getPath().endsWith(".genome")) {
GenomeDescriptor genomeDescriptor = GenomeDescriptor.parseGenomeArchiveFile(genomeFile);
fastaPath = genomeDescriptor.getSequencePath();
String fastaPath = genomeDescriptor.getSequencePath();
if (fastaPath != null && FileUtils.isRemote(fastaPath)) {
File localFile = downloadFasta(fastaPath);
if (localFile != null) {
addLocalFasta(item.getId(), localFile);
}
}

} else if (item.getPath().endsWith(".json")) {

JsonGenomeLoader.GenomeDescriptor desc = (new JsonGenomeLoader(item.getPath())).loadDescriptor();
fastaPath = desc.getFastaURL();
}
if (fastaPath != null && FileUtils.isRemote(fastaPath)) {
File localFile = downloadFasta(fastaPath);
if (localFile != null) {
addLocalFasta(item.getId(), localFile);
}


}

}

success = true;
Expand All @@ -391,7 +400,6 @@ public boolean downloadGenome(GenomeListItem item, boolean downloadSequence) {
}

return success;

}


Expand Down Expand Up @@ -466,11 +474,4 @@ private static void updateSequenceMapFile() {
}
}

public void refreshHostedGenome(String genomeId) {

Map<String, GenomeListItem> itemMap = GenomeListManager.getInstance().getServerGenomeMap();
if (itemMap.containsKey(genomeId)) {
downloadGenome(itemMap.get(genomeId), false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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 @@ -107,6 +120,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
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ public void run() {

if (!genomeLoaded) {
Genome genome = Genome.nullGenome();
GenomeManager.getInstance().setCurrentGenome("", genome);
GenomeManager.getInstance().setCurrentGenome(genome);


//GenomeManager.getInstance().setCurrentGenome(Genome.NoneGenome());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.broad.igv.feature.genome.GenomeUtils;
import org.broad.igv.track.AttributeManager;
import org.broad.igv.track.Track;
import org.broad.igv.ui.commandbar.GenomeComboBox;
import org.broad.igv.ui.commandbar.GenomeListManager;
import org.broad.igv.ui.commandbar.GenomeSelectionDialog;
import org.broad.igv.util.GoogleUtils;
Expand Down Expand Up @@ -435,7 +434,7 @@ private JMenu createGenomesMenu() {
JMenu menu = new JMenu("Genomes");

loadGenomeFromServerMenuItem = new JMenuItem("Download Hosted Genome...");
loadGenomeFromServerMenuItem.addActionListener(e -> GenomeComboBox.loadGenomeFromServer());
loadGenomeFromServerMenuItem.addActionListener(e -> GenomeSelectionDialog.selectGenomesFromServer());
loadGenomeFromServerMenuItem.setToolTipText(LOAD_GENOME_SERVER_TOOLTIP);
menu.add(loadGenomeFromServerMenuItem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package org.broad.igv.ui.action;

import org.broad.igv.Globals;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.load.HubGenomeLoader;
import org.broad.igv.logging.*;
import org.broad.igv.feature.genome.GenomeManager;
Expand Down Expand Up @@ -81,6 +82,7 @@ public void actionPerformed(ActionEvent e) {

if (!dlg.isCanceled()) {


String inputURLs = dlg.getFileURL();
if (inputURLs != null && inputURLs.trim().length() > 0) {

Expand All @@ -89,7 +91,7 @@ public void actionPerformed(ActionEvent e) {
if (inputs.length == 1 && HubGenomeLoader.isHubURL(inputs[0])) {
LongRunningTask.submit(() -> {
try {
GenomeManager.getInstance().loadGenome(inputs[0]);
Genome newGenome = GenomeManager.getInstance().loadGenome(inputs[0]);
} catch (IOException ex) {
log.error("Error loading tack hub", ex);
MessageUtils.showMessage("Error loading track hub: " + ex.getMessage());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/broad/igv/ui/action/UCSCGenArkAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@

import org.broad.igv.Globals;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.GenomeListItem;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.feature.genome.load.HubGenomeLoader;
import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.track.AttributeManager;
import org.broad.igv.ui.IGV;
import org.broad.igv.ui.commandbar.GenomeListManager;
import org.broad.igv.ui.table.SearchableTableDialog;
import org.broad.igv.ui.table.SearchableTableModel;
import org.broad.igv.ui.table.SearchableTableRecord;
Expand Down
80 changes: 1 addition & 79 deletions src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package org.broad.igv.ui.commandbar;

import org.broad.igv.logging.*;
import org.broad.igv.DirectoryManager;
import org.broad.igv.event.GenomeResetEvent;
import org.broad.igv.event.IGVEventBus;
import org.broad.igv.feature.genome.GenomeListItem;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.ui.IGV;
import org.broad.igv.ui.UIConstants;
import org.broad.igv.ui.util.MessageUtils;
import org.broad.igv.ui.util.UIUtilities;
import org.broad.igv.util.LongRunningTask;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.List;

/**
* Created by jrobinso on 7/6/17.
Expand Down Expand Up @@ -100,7 +94,7 @@ private void loadGenomeListItem(final GenomeListItem genomeListItem) {
if (genomeListItem != null && genomeListItem.getPath() != null) {

if (genomeListItem == GenomeListItem.DOWNLOAD_ITEM) {
loadGenomeFromServer();
GenomeSelectionDialog.selectGenomesFromServer();
} else {

try {
Expand Down Expand Up @@ -197,76 +191,4 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
}


/**
* Open a selection list to load a genome from the server. This method is static because its used by multiple
* UI elements (menu bar and genome selection pulldown).
*/
public static void loadGenomeFromServer() {

Runnable showDialog = () -> {

Collection<GenomeListItem> inputListItems = GenomeListManager.getInstance().getServerGenomeList();
if (inputListItems == null) {
return;
}
GenomeSelectionDialog dialog = new GenomeSelectionDialog(IGV.getInstance().getMainFrame(), inputListItems);
UIUtilities.invokeAndWaitOnEventThread(() -> dialog.setVisible(true));

if (dialog.isCanceled()) {
IGVEventBus.getInstance().post(new GenomeResetEvent());
} else {
List<GenomeListItem> selectedValueList = dialog.getSelectedValues();
GenomeListItem firstItem = null;
for (GenomeListItem selectedValue : selectedValueList) {
if (selectedValue != null) {
boolean downloadSequence = false;
boolean success = GenomeManager.getInstance().downloadGenome(selectedValue, downloadSequence);
if (success) {
GenomeListManager.getInstance().addServerGenomeItem(selectedValue);
firstItem = selectedValue;
}
}
}
if (firstItem != null && selectedValueList.size() == 1) {
try {

GenomeManager.getInstance().loadGenome(firstItem.getPath());
// If the user has previously defined this genome, remove it.
GenomeListManager.getInstance().removeUserDefinedGenome(firstItem.getId());

// If this is a .json genome, attempt to remove existing .genome files
if (firstItem.getPath().endsWith(".json")) {
removeDotGenomeFile(firstItem.getId());
}


} catch (IOException e) {
GenomeListManager.getInstance().removeGenomeListItem(firstItem);
MessageUtils.showErrorMessage("Error loading genome " + firstItem.getDisplayableName(), e);
log.error("Error loading genome " + firstItem.getDisplayableName(), e);
}
}
}
};

if (SwingUtilities.isEventDispatchThread()) {
LongRunningTask.submit(showDialog);
} else {
showDialog.run();
}
}

public static void removeDotGenomeFile(String id) {
try {
File dotGenomeFile = new File(DirectoryManager.getGenomeCacheDirectory(), id + ".genome");
if (dotGenomeFile.exists()) {
dotGenomeFile.delete();
}
} catch (Exception e) {
// If anything goes wrong, just log it, this cleanup is not essential
log.error("Error deleting .genome file", e);
}
}


}
Loading