Search in sources :

Example 11 with LocalFile

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());
            }
        }
    }
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) FailedBatchInformationFetchingEvent(ubic.gemma.model.common.auditAndSecurity.eventType.FailedBatchInformationFetchingEvent)

Example 12 with LocalFile

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;
}
Also used : HttpFetcher(ubic.gemma.core.loader.util.fetcher.HttpFetcher) MalformedURLException(java.net.MalformedURLException) TaxonService(ubic.gemma.persistence.service.genome.taxon.TaxonService) NCBIGene2GOAssociationParser(ubic.gemma.core.loader.association.NCBIGene2GOAssociationParser) Taxon(ubic.gemma.model.genome.Taxon) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NCBIGene2GOAssociationLoader(ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader) LocalFile(ubic.gemma.model.common.description.LocalFile) Gene2GOAssociationService(ubic.gemma.persistence.service.association.Gene2GOAssociationService) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile)

Example 13 with LocalFile

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;
}
Also used : TaxonLoader(ubic.gemma.core.loader.genome.taxon.TaxonLoader) LocalFile(ubic.gemma.model.common.description.LocalFile) TaxonFetcher(ubic.gemma.core.loader.genome.taxon.TaxonFetcher) PersisterHelper(ubic.gemma.persistence.persister.PersisterHelper)

Example 14 with LocalFile

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();
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 15 with LocalFile

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);
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) File(java.io.File)

Aggregations

LocalFile (ubic.gemma.model.common.description.LocalFile)40 File (java.io.File)17 IOException (java.io.IOException)11 MalformedURLException (java.net.MalformedURLException)4 HashSet (java.util.HashSet)4 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)4 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)4 URL (java.net.URL)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)3 Taxon (ubic.gemma.model.genome.Taxon)3 StopWatch (org.apache.commons.lang3.time.StopWatch)2 AffyPowerToolsProbesetSummarize (ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize)2 RawDataFetcher (ubic.gemma.core.loader.expression.geo.fetcher.RawDataFetcher)2 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)2 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1