mainFrame.setIconImage(getIconImage());
if (Globals.IS_MAC) {
setAppleDockIcon();
}
final PreferenceManager preferenceManager = PreferenceManager.getInstance();
try {
contentPane.getCommandBar().initializeGenomeList(monitor);
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(mainFrame, "Error initializing genome list: " + ex.getMessage());
log.error("Error initializing genome list: ", ex);
} catch (NoRouteToHostException ex) {
JOptionPane.showMessageDialog(mainFrame, "Network error initializing genome list: " + ex.getMessage());
log.error("Network error initializing genome list: ", ex);
} finally {
monitor.fireProgressChange(50);
closeWindow(progressDialog);
}
if (igvArgs.getGenomeId() != null) {
IGV.getInstance().loadGenomeById(igvArgs.getGenomeId());
} else if (igvArgs.getSessionFile() == null) {
String genomeId = preferenceManager.getDefaultGenome();
contentPane.getCommandBar().selectGenome(genomeId);
}
//Load plugins
//Do this before loading files, hooks might need to be inserted
initIGVPlugins();
//If there is an argument assume it is a session file or url
if (igvArgs.getSessionFile() != null || igvArgs.getDataFileString() != null) {
if (log.isDebugEnabled()) {
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 = restoreSessionSynchronous(igvArgs.getSessionFile(), igvArgs.getLocusString(), merge);
} else {
File sf = new File(igvArgs.getSessionFile());
if (sf.exists()) {
success = restoreSessionSynchronous(sf.getAbsolutePath(), igvArgs.getLocusString(), false);
}
}
if (!success) {
String genomeId = preferenceManager.getDefaultGenome();
contentPane.getCommandBar().selectGenome(genomeId);
}
} else if (igvArgs.getDataFileString() != null) {
// Not an xml file, assume its a list of data files
String[] dataFiles = igvArgs.getDataFileString().split(",");
String[] names = null;
if (igvArgs.getName() != null) {
names = igvArgs.getName().split(",");
}
String[] indexFiles = null;
if (igvArgs.getIndexFile() != null) {
indexFiles = igvArgs.getIndexFile().split(",");
}
String[] coverageFiles = null;
if (igvArgs.getCoverageFile() != null) {
coverageFiles = igvArgs.getCoverageFile().split(",");
}
List<ResourceLocator> locators = new ArrayList();
for (int i = 0; i < dataFiles.length; i++) {
String p = dataFiles[i].trim();
// Decode local file paths
if (HttpUtils.isURL(p) && !FileUtils.isRemote(p)) {
p = StringUtils.decodeURL(p);
}
ResourceLocator rl = new ResourceLocator(p);
if (names != null && i < names.length) {
String name = names[i];
rl.setName(name);
}
//Set index file, iff one was passed
if(indexFiles != null && i < indexFiles.length) {
String idxP = indexFiles[i];
if (HttpUtils.isURL(idxP) && !FileUtils.isRemote(idxP)) {
idxP = StringUtils.decodeURL(idxP);
}
if (idxP.length() > 0) {
rl.setIndexPath(idxP);
}
}
//Set coverage file, iff one was passed
if(coverageFiles != null && i < coverageFiles.length) {
String covP = coverageFiles[i];
if (HttpUtils.isURL(covP) && !FileUtils.isRemote(covP)) {
covP = StringUtils.decodeURL(covP);
}
if (covP.length() > 0) {
rl.setCoverage(covP);
}
}
locators.add(rl);
}
loadTracks(locators);
}
indefMonitor.stop();
closeWindow(progressDialog2);
}
session.recordHistory();
// Start up a port listener. Port # can be overriden with "-p" command line switch
boolean portEnabled = preferenceManager.getAsBoolean(PreferenceManager.PORT_ENABLED);
String portString = igvArgs.getPort();
if (portEnabled || portString != null) {
// Command listener thread
int port = preferenceManager.getAsInt(PreferenceManager.PORT_NUMBER);
if (portString != null) {
port = Integer.parseInt(portString);
}
CommandListener.start(port);
}