Search in sources :

Example 1 with TaxonService

use of ubic.gemma.persistence.service.genome.taxon.TaxonService in project Gemma by PavlidisLab.

the class StringProteinLoadCli method getValidTaxon.

/**
 * If a taxon is supplied on the command line then process protein interactions for that taxon. If no taxon is
 * supplied then create a list of valid taxon to process from those stored in gemma: Criteria are does this taxon
 * have usable genes and is it a species.
 *
 * @return Collection of Taxa to process
 */
private Collection<Taxon> getValidTaxon() {
    Taxon taxon;
    TaxonService taxonService = this.getBean(TaxonService.class);
    Collection<Taxon> taxa = new ArrayList<>();
    if (taxonName != null && StringUtils.isNotBlank(taxonName)) {
        taxon = taxonService.findByCommonName(taxonName);
        if (taxon == null || !(taxon.getIsSpecies()) || !(taxon.getIsGenesUsable())) {
            throw new IllegalArgumentException("The taxon common name supplied: " + taxonName + " Either does not match anything in GEMMA, or is not a species or does have usable genes");
        }
        taxa.add(taxon);
    } else {
        for (Taxon taxonGemma : taxonService.loadAll()) {
            // only those taxon that are species and have usable genes should be processed
            if (taxonGemma != null && taxonGemma.getIsSpecies() && taxonGemma.getIsGenesUsable() && (taxonGemma.getCommonName() != null) && !(taxonGemma.getCommonName().isEmpty())) {
                taxa.add(taxonGemma);
            }
        }
        if (taxa.isEmpty()) {
            throw new RuntimeException("There are no valid taxa in GEMMA to process. Valid taxon are those that are species and have usable genes.");
        }
        AbstractCLI.log.info("Processing " + taxa.size() + "taxa ");
    }
    return taxa;
}
Also used : TaxonService(ubic.gemma.persistence.service.genome.taxon.TaxonService) Taxon(ubic.gemma.model.genome.Taxon) ArrayList(java.util.ArrayList)

Example 2 with TaxonService

use of ubic.gemma.persistence.service.genome.taxon.TaxonService in project Gemma by PavlidisLab.

the class ArrayDesignAnnotationFileCli method processGeneList.

private void processGeneList() throws IOException {
    AbstractCLI.log.info("Loading genes to annotate from " + geneFileName);
    InputStream is = new FileInputStream(geneFileName);
    try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
        String line;
        GeneService geneService = this.getBean(GeneService.class);
        TaxonService taxonService = this.getBean(TaxonService.class);
        Taxon taxon = taxonService.findByCommonName(taxonName);
        if (taxon == null) {
            throw new IllegalArgumentException("Unknown taxon: " + taxonName);
        }
        Collection<Gene> genes = new HashSet<>();
        while ((line = br.readLine()) != null) {
            if (StringUtils.isBlank(line)) {
                continue;
            }
            String[] arguments = StringUtils.split(line, '\t');
            String gene = arguments[0];
            Gene g = geneService.findByOfficialSymbol(gene, taxon);
            if (g == null) {
                AbstractCLI.log.info("Gene: " + gene + " not found.");
                continue;
            }
            genes.add(g);
        }
        AbstractCLI.log.info("File contained " + genes.size() + " potential gene symbols");
        int numProcessed = arrayDesignAnnotationService.generateAnnotationFile(new PrintWriter(System.out), genes, OutputType.SHORT);
        AbstractCLI.log.info("Processed " + numProcessed + " genes that were found");
    }
}
Also used : GeneService(ubic.gemma.core.genome.gene.service.GeneService) TaxonService(ubic.gemma.persistence.service.genome.taxon.TaxonService) Taxon(ubic.gemma.model.genome.Taxon) Gene(ubic.gemma.model.genome.Gene) HashSet(java.util.HashSet)

Example 3 with TaxonService

use of ubic.gemma.persistence.service.genome.taxon.TaxonService in project Gemma by PavlidisLab.

the class ArrayDesignAnnotationFileCli method processAllADs.

/**
 * Goes over all the AD's in the database (possibly limited by taxon) and creates annotation 3 annotation files for
 * each AD that is not merged into or subsumed by another AD. Uses the Accession ID (GPL???) for the name of the
 * annotation file. Appends noParents, bioProcess, allParents to the file name.
 */
private void processAllADs() throws IOException {
    Collection<ArrayDesign> allADs = this.arrayDesignService.loadAll();
    for (ArrayDesign ad : allADs) {
        ad = arrayDesignService.thawLite(ad);
        if (ad.getCurationDetails().getTroubled()) {
            AbstractCLI.log.warn("Troubled: " + ad + " (skipping)");
            continue;
        }
        Taxon taxon = null;
        if (this.taxonName != null) {
            TaxonService taxonService = this.getBean(TaxonService.class);
            taxon = taxonService.findByCommonName(taxonName);
            if (taxon == null) {
                throw new IllegalArgumentException("Unknown taxon: " + taxonName);
            }
        }
        Collection<Taxon> adTaxa = arrayDesignService.getTaxa(ad.getId());
        /*
             * If using taxon, check it.
             */
        if (taxon != null && !adTaxa.contains(taxon)) {
            continue;
        }
        this.processOneAD(ad);
    }
}
Also used : TaxonService(ubic.gemma.persistence.service.genome.taxon.TaxonService) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Taxon(ubic.gemma.model.genome.Taxon)

Example 4 with TaxonService

use of ubic.gemma.persistence.service.genome.taxon.TaxonService 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 5 with TaxonService

use of ubic.gemma.persistence.service.genome.taxon.TaxonService in project Gemma by PavlidisLab.

the class GenericGenelistDesignGenerator method processOptions.

@Override
protected void processOptions() {
    super.processOptions();
    geneService = this.getBean(GeneService.class);
    arrayDesignAnnotationService = this.getBean(ArrayDesignAnnotationService.class);
    TaxonService taxonService = this.getBean(TaxonService.class);
    bioSequenceService = this.getBean(BioSequenceService.class);
    arrayDesignService = this.getBean(ArrayDesignService.class);
    compositeSequenceService = this.getBean(CompositeSequenceService.class);
    annotationAssociationService = this.getBean(AnnotationAssociationService.class);
    externalDatabaseService = this.getBean(ExternalDatabaseService.class);
    arrayDesignReportService = this.getBean(ArrayDesignReportService.class);
    if (this.hasOption('t')) {
        this.taxon = this.setTaxonByName(taxonService);
    }
    if (this.hasOption("ncbiids")) {
        this.useNCBIIds = true;
    } else if (this.hasOption("ensembl")) {
        this.useEnsemblIds = true;
    }
    if (useNCBIIds && useEnsemblIds) {
        throw new IllegalArgumentException("Choose one of ensembl or ncbi ids or gene symbols");
    }
}
Also used : GeneService(ubic.gemma.core.genome.gene.service.GeneService) AnnotationAssociationService(ubic.gemma.persistence.service.genome.sequenceAnalysis.AnnotationAssociationService) ExternalDatabaseService(ubic.gemma.persistence.service.common.description.ExternalDatabaseService) TaxonService(ubic.gemma.persistence.service.genome.taxon.TaxonService) ArrayDesignAnnotationService(ubic.gemma.core.analysis.service.ArrayDesignAnnotationService) BioSequenceService(ubic.gemma.persistence.service.genome.biosequence.BioSequenceService) CompositeSequenceService(ubic.gemma.persistence.service.expression.designElement.CompositeSequenceService) ArrayDesignService(ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService) ArrayDesignReportService(ubic.gemma.core.analysis.report.ArrayDesignReportService)

Aggregations

TaxonService (ubic.gemma.persistence.service.genome.taxon.TaxonService)10 Taxon (ubic.gemma.model.genome.Taxon)6 GeneService (ubic.gemma.core.genome.gene.service.GeneService)3 Gene (ubic.gemma.model.genome.Gene)2 ExternalDatabaseService (ubic.gemma.persistence.service.common.description.ExternalDatabaseService)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArrayDesignReportService (ubic.gemma.core.analysis.report.ArrayDesignReportService)1 ArrayDesignAnnotationService (ubic.gemma.core.analysis.service.ArrayDesignAnnotationService)1 NCBIGene2GOAssociationLoader (ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader)1 NCBIGene2GOAssociationParser (ubic.gemma.core.loader.association.NCBIGene2GOAssociationParser)1 ArrayDesignProbeMapperService (ubic.gemma.core.loader.expression.arrayDesign.ArrayDesignProbeMapperService)1 ArrayDesignSequenceAlignmentService (ubic.gemma.core.loader.expression.arrayDesign.ArrayDesignSequenceAlignmentService)1 NcbiGeneLoader (ubic.gemma.core.loader.genome.gene.ncbi.NcbiGeneLoader)1 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)1 LocalFile (ubic.gemma.model.common.description.LocalFile)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1