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;
}
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");
}
}
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);
}
}
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;
}
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");
}
}
Aggregations