use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class BatchInfoPopulationServiceImpl method fillBatchInformation.
@Override
public boolean fillBatchInformation(ExpressionExperiment ee, boolean force) {
boolean needed = force || this.needToRun(ee);
if (!needed) {
BatchInfoPopulationServiceImpl.log.info("Study already has batch information, or it is known to be unavailable; use 'force' to override");
return false;
}
Collection<LocalFile> files = null;
try {
files = this.fetchRawDataFiles(ee);
if (files == null || files.isEmpty()) {
this.auditTrailService.addUpdateEvent(ee, FailedBatchInformationMissingEvent.class, "No files were found", "");
return false;
}
return this.getBatchDataFromRawFiles(ee, files);
} catch (Exception e) {
BatchInfoPopulationServiceImpl.log.info(e, e);
this.auditTrailService.addUpdateEvent(ee, FailedBatchInformationFetchingEvent.class, e.getMessage(), ExceptionUtils.getStackTrace(e));
return false;
} finally {
if (BatchInfoPopulationServiceImpl.CLEAN_UP && files != null) {
for (LocalFile localFile : files) {
EntityUtils.deleteFile(localFile.asFile());
}
}
}
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class NCBIGene2GOAssociationLoaderCLI method doWork.
@Override
protected Exception doWork(String[] args) {
Exception e = this.processCommandLine(args);
if (e != null) {
AbstractCLI.log.error(e);
return e;
}
TaxonService taxonService = this.getBean(TaxonService.class);
NCBIGene2GOAssociationLoader gene2GOAssLoader = new NCBIGene2GOAssociationLoader();
gene2GOAssLoader.setPersisterHelper(this.getPersisterHelper());
Collection<Taxon> taxa = taxonService.loadAll();
gene2GOAssLoader.setParser(new NCBIGene2GOAssociationParser(taxa));
HttpFetcher fetcher = new HttpFetcher();
Collection<LocalFile> files;
if (filePath != null) {
File f = new File(filePath);
if (!f.canRead()) {
return new IOException("Cannot read from " + filePath);
}
files = new HashSet<>();
LocalFile lf = LocalFile.Factory.newInstance();
try {
lf.setLocalURL(f.toURI().toURL());
} catch (MalformedURLException e1) {
return e1;
}
files.add(lf);
} else {
files = fetcher.fetch("ftp://ftp.ncbi.nih.gov/gene/DATA/" + NCBIGene2GOAssociationLoaderCLI.GENE2GO_FILE);
}
assert files.size() == 1;
LocalFile gene2Gofile = files.iterator().next();
Gene2GOAssociationService ggoserv = this.getBean(Gene2GOAssociationService.class);
AbstractCLI.log.info("Removing all old GO associations");
ggoserv.removeAll();
AbstractCLI.log.info("Done, loading new ones");
gene2GOAssLoader.load(gene2Gofile);
AbstractCLI.log.info("Don't forget to update the annotation files for platforms.");
return null;
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class TaxonLoaderCli method doWork.
@Override
protected Exception doWork(String[] args) {
try {
Exception err = processCommandLine(args);
if (err != null)
return err;
TaxonFetcher tf = new TaxonFetcher();
Collection<LocalFile> files = tf.fetch();
LocalFile names = null;
for (LocalFile file : files) {
if (file.getLocalURL().toString().endsWith("names.dmp")) {
names = file;
}
}
if (names == null) {
throw new IllegalStateException("No names.dmp file");
}
TaxonLoader tl = new TaxonLoader();
tl.setPersisterHelper(this.getBean(PersisterHelper.class));
int numLoaded = tl.load(names.asFile());
log.info("Loaded " + numLoaded + " taxa");
} catch (Exception e) {
log.error(e);
return e;
}
return null;
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class HomologeneServiceImpl method init.
@Override
public synchronized void init(boolean force) {
if (running.get()) {
return;
}
if (ready.get()) {
return;
}
boolean loadHomologene = Settings.getBoolean(HomologeneServiceImpl.LOAD_HOMOLOGENE, true);
this.homologeneFileName = Settings.getString(HomologeneServiceImpl.HOMOLOGENE_FILE);
// if loading homologene is disabled in the configuration, return
if (!force && !loadHomologene) {
HomologeneServiceImpl.log.info("Loading Homologene is disabled (force=false, load.homologene=false)");
return;
}
enabled.set(true);
// Load the homologene groups for searching
Thread loadThread = new Thread(new Runnable() {
@Override
public void run() {
running.set(true);
HomologeneServiceImpl.log.info("Loading Homologene...");
StopWatch loadTime = new StopWatch();
loadTime.start();
HomologeneFetcher hf = new HomologeneFetcher();
Collection<LocalFile> downloadedFiles = hf.fetch(homologeneFileName);
File f;
if (downloadedFiles == null || downloadedFiles.isEmpty()) {
HomologeneServiceImpl.log.warn("Unable to download Homologene File. Aborting");
return;
}
if (downloadedFiles.size() > 1)
HomologeneServiceImpl.log.info("Downloaded more than 1 file for homologene. Using 1st. ");
f = downloadedFiles.iterator().next().asFile();
if (!f.canRead()) {
HomologeneServiceImpl.log.warn("Downloaded Homologene File. But unable to read Aborting");
return;
}
while (!ready.get()) {
try (InputStream is = FileTools.getInputStreamFromPlainOrCompressedFile(f.getAbsolutePath())) {
HomologeneServiceImpl.this.parseHomologeneFile(is);
} catch (IOException ioe) {
HomologeneServiceImpl.log.error("Unable to parse homologene file. Error is " + ioe);
}
}
running.set(false);
}
}, "Homologene_load_thread");
if (running.get())
return;
// So vm doesn't wait on these threads to shutdown (if shutting down)
loadThread.setDaemon(true);
loadThread.start();
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class LocalSeriesFetcher method fetch.
@Override
public Collection<LocalFile> fetch(String accession) {
log.info("Seeking GSE file for " + accession);
assert localPath != null;
String seekFileName = localPath + File.separatorChar + accession + "_family.soft.gz";
File seekFile = new File(seekFileName);
if (seekFile.canRead()) {
return getFile(accession, seekFileName);
}
// try alternative naming scheme.
String altSeekFileName = localPath + File.separatorChar + accession + ".soft.gz";
seekFile = new File(altSeekFileName);
if (seekFile.canRead()) {
return getFile(accession, altSeekFileName);
}
throw new RuntimeException("Failed to find file for " + accession + "; Checked for " + seekFileName + " and " + altSeekFileName);
}
Aggregations