use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class BiomartEnsemblNcbiObjectGenerator method generateRemote.
/**
* @return Generates file from remote biomart location
* @throws IOException if there is a problem while manipulating the file
*/
public Map<String, Ensembl2NcbiValueObject> generateRemote(Collection<Taxon> validTaxa) throws IOException {
Map<String, Ensembl2NcbiValueObject> bioMartEnsemblNcbiIdsForValidAllGemmaTaxa = new HashMap<>();
Map<Taxon, File> taxaBiomartFiles = this.biomartEnsemblNcbiFetcher.fetch(validTaxa);
if (taxaBiomartFiles != null && !taxaBiomartFiles.isEmpty()) {
for (Taxon taxon : taxaBiomartFiles.keySet()) {
File fileForTaxon = taxaBiomartFiles.get(taxon);
if (fileForTaxon != null) {
log.info("Starting processing taxon " + taxon + " for file " + fileForTaxon);
Map<String, Ensembl2NcbiValueObject> map = parseTaxonBiomartFile(taxon, fileForTaxon);
bioMartEnsemblNcbiIdsForValidAllGemmaTaxa.putAll(map);
} else {
log.error("No biomart file retrieved for taxon " + taxon);
}
}
} else {
throw new RuntimeException("No files could be downloaded from Biomart for provided taxon");
}
return bioMartEnsemblNcbiIdsForValidAllGemmaTaxa;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class ExternalFileGeneLoaderServiceImpl method load.
@Override
public int load(String geneFile, String taxonName) throws Exception {
log.info("Starting loading gene file " + geneFile + " for taxon " + taxonName);
Taxon taxon = validateTaxon(taxonName);
log.info("Taxon and file validation passed for " + geneFile + " for taxon " + taxonName);
try (BufferedReader bufferedReaderGene = readFile(geneFile)) {
return load(bufferedReaderGene, taxon);
}
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class ExternalFileGeneLoaderServiceImpl method updateTaxonWithGenesLoaded.
/**
* Method to update taxon to indicate that genes have been loaded for that taxon. If the taxon has children taxa
* then those child genes should not be used and the flag for those child taxon set to false.
*
* @param taxon The taxon to update
*/
private void updateTaxonWithGenesLoaded(Taxon taxon) {
Collection<Taxon> childTaxa = taxonService.findChildTaxaByParent(taxon);
// if this taxon has children flag not to use their genes
if (childTaxa != null && !childTaxa.isEmpty()) {
for (Taxon childTaxon : childTaxa) {
if (childTaxon != null && childTaxon.getIsGenesUsable()) {
childTaxon.setIsGenesUsable(false);
taxonService.update(childTaxon);
log.warn("Child taxa" + childTaxon + " genes have been loaded parent taxa should suppressed");
}
}
}
// set taxon flag indicating that use this taxon's genes
if (!taxon.getIsGenesUsable()) {
taxon.setIsGenesUsable(true);
taxonService.update(taxon);
log.info("Updating taxon genes loaded to true for taxon " + taxon);
}
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class TaxonLoader method load.
public int load(final InputStream inputStream) throws IOException {
TaxonParser parser = new TaxonParser();
parser.parse(inputStream);
Collection<Taxon> results = parser.getResults();
int count = 0;
for (Taxon taxon : results) {
if (TaxonLoader.log.isDebugEnabled())
TaxonLoader.log.debug("Loading " + taxon);
persisterHelper.persist(taxon);
count++;
}
TaxonLoader.log.info("Persisted " + count + " taxa");
return count;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class TaxonParser method parseOneLine.
@Override
public Taxon parseOneLine(String line) {
String[] fields = StringUtils.splitPreserveAllTokens(line, '|');
int ncbiid = Integer.parseInt(StringUtils.strip(fields[0]));
if (!results.containsKey(ncbiid)) {
Taxon t = Taxon.Factory.newInstance();
t.setNcbiId(ncbiid);
t.setIsGenesUsable(false);
t.setIsSpecies(true);
results.put(ncbiid, t);
}
String tag = StringUtils.strip(fields[3]);
if (tag.equals("scientific name")) {
results.get(ncbiid).setScientificName(StringUtils.strip(fields[1]));
} else if (tag.equals("genbank common name")) {
results.get(ncbiid).setCommonName(fields[1]);
}
return results.get(ncbiid);
}
Aggregations