Search in sources :

Example 1 with Gene2GOAssociationService

use of ubic.gemma.persistence.service.association.Gene2GOAssociationService 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)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 NCBIGene2GOAssociationLoader (ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader)1 NCBIGene2GOAssociationParser (ubic.gemma.core.loader.association.NCBIGene2GOAssociationParser)1 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)1 LocalFile (ubic.gemma.model.common.description.LocalFile)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