Search in sources :

Example 1 with HttpFetcher

use of ubic.gemma.core.loader.util.fetcher.HttpFetcher in project Gemma by PavlidisLab.

the class HttpFetcherTest method testFetch.

/*
     * Test method for 'ubic.gemma.core.loader.loaderutils.HttpFetcher.fetch(String)'
     */
public void testFetch() {
    HttpFetcher hf = new HttpFetcher();
    try {
        hf.setForce(true);
        Collection<LocalFile> results = hf.fetch("http://www.yahoo.com");
        TestCase.assertNotNull(results);
        TestCase.assertTrue(results.size() > 0 && results.iterator().next().getLocalURL() != null);
        f = new File(results.iterator().next().getLocalURL().toURI());
        TestCase.assertTrue(f.length() > 0);
    } catch (Exception e) {
        if (e.getCause() instanceof IOException) {
            HttpFetcherTest.log.error("Got IOException, skipping test");
        }
    }
}
Also used : HttpFetcher(ubic.gemma.core.loader.util.fetcher.HttpFetcher) LocalFile(ubic.gemma.model.common.description.LocalFile) IOException(java.io.IOException) LocalFile(ubic.gemma.model.common.description.LocalFile) File(java.io.File) IOException(java.io.IOException)

Example 2 with HttpFetcher

use of ubic.gemma.core.loader.util.fetcher.HttpFetcher 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)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)2 LocalFile (ubic.gemma.model.common.description.LocalFile)2 MalformedURLException (java.net.MalformedURLException)1 NCBIGene2GOAssociationLoader (ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader)1 NCBIGene2GOAssociationParser (ubic.gemma.core.loader.association.NCBIGene2GOAssociationParser)1 Taxon (ubic.gemma.model.genome.Taxon)1 Gene2GOAssociationService (ubic.gemma.persistence.service.association.Gene2GOAssociationService)1 TaxonService (ubic.gemma.persistence.service.genome.taxon.TaxonService)1