use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.
the class ArrayDesignAnnotationServiceImpl method generateAnnotationFile.
@Override
public int generateAnnotationFile(Writer writer, Collection<Gene> genes, OutputType type) {
Map<Gene, Collection<VocabCharacteristic>> goMappings = gene2GOAssociationService.findByGenes(genes);
for (Gene gene : genes) {
Collection<OntologyTerm> ontologyTerms = this.getGoTerms(goMappings.get(gene), type);
Integer ncbiId = gene.getNcbiGeneId();
String ncbiIds = ncbiId == null ? "" : ncbiId.toString();
String geneString = gene.getOfficialSymbol();
String geneDescriptionString = gene.getOfficialName();
try {
Long id = gene.getId();
this.writeAnnotationLine(writer, geneString, ncbiIds, geneDescriptionString, ontologyTerms, id.toString(), ncbiIds);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return genes.size();
}
use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.
the class ArrayDesignAnnotationServiceImpl method getGOMappings.
private Map<Gene, Collection<VocabCharacteristic>> getGOMappings(Map<CompositeSequence, Collection<BioSequence2GeneProduct>> genesWithSpecificity) {
ArrayDesignAnnotationServiceImpl.log.info("Fetching GO mappings");
Collection<Gene> allGenes = new HashSet<>();
for (CompositeSequence cs : genesWithSpecificity.keySet()) {
Collection<BioSequence2GeneProduct> geneclusters = genesWithSpecificity.get(cs);
for (BioSequence2GeneProduct bioSequence2GeneProduct : geneclusters) {
Gene g = bioSequence2GeneProduct.getGeneProduct().getGene();
allGenes.add(g);
}
}
Map<Gene, Collection<VocabCharacteristic>> goMappings = gene2GOAssociationService.findByGenes(allGenes);
ArrayDesignAnnotationServiceImpl.log.info("Got GO mappings for " + goMappings.size() + " genes");
return goMappings;
}
use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.
the class GeneMultifunctionalityPopulationServiceImpl method saveBatch.
private void saveBatch(Collection<Gene> genes, Map<Gene, Multifunctionality> mfs) {
genes = geneService.thawLite(genes);
for (Gene g : genes) {
if (!mfs.containsKey(g)) {
g.setMultifunctionality(null);
} else {
Multifunctionality updatedMf = mfs.get(g);
Multifunctionality oldMf = g.getMultifunctionality();
if (oldMf == null) {
g.setMultifunctionality(updatedMf);
} else {
oldMf = g.getMultifunctionality();
oldMf.setNumGoTerms(updatedMf.getNumGoTerms());
oldMf.setRank(updatedMf.getRank());
oldMf.setScore(updatedMf.getScore());
}
}
}
geneService.update(genes);
}
use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.
the class GeneMultifunctionalityPopulationServiceImpl method fetchGoAnnotations.
private Map<Gene, Collection<String>> fetchGoAnnotations(Collection<Gene> genes) {
if (!goService.isRunning()) {
goService.init(true);
}
while (!goService.isReady()) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
//
}
GeneMultifunctionalityPopulationServiceImpl.log.info("Waiting for GO to load");
}
/*
* Build the GO 'matrix'.
*/
int count = 0;
Map<Gene, Collection<String>> gomap = new HashMap<>();
for (Gene gene : genes) {
Collection<VocabCharacteristic> annots = gene2GOService.findByGene(gene);
Collection<String> termsForGene = new HashSet<>();
// noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
if (annots.isEmpty()) {
// continue;
}
for (VocabCharacteristic t : annots) {
if (ontologyService.isObsolete(t.getValueUri())) {
GeneMultifunctionalityPopulationServiceImpl.log.warn("Obsolete term annotated to " + gene + " : " + t);
continue;
}
termsForGene.add(t.getValue());
Collection<OntologyTerm> parents = goService.getAllParents(GeneOntologyServiceImpl.getTermForURI(t.getValueUri()));
for (OntologyTerm p : parents) {
termsForGene.add(p.getTerm());
}
}
// noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
if (termsForGene.isEmpty()) {
// continue;
}
gomap.put(gene, termsForGene);
if (++count % 1000 == 0) {
GeneMultifunctionalityPopulationServiceImpl.log.info("Fetched GO annotations for: " + count + "/" + genes.size() + " genes");
}
}
return gomap;
}
use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.
the class PhenotypeAssociationTest method tearDown.
@After
public void tearDown() {
this.runAsAdmin();
Collection<PhenotypeAssociation> toRemove = new HashSet<>();
for (Gene g : this.geneService.loadAll()) {
g = geneService.thaw(g);
toRemove.addAll(g.getPhenotypeAssociations());
g.getPhenotypeAssociations().clear();
this.geneService.update(g);
}
for (PhenotypeAssociation pa : toRemove) {
this.phenotypeAssociationService.remove(pa);
}
// this.externalDatabaseService.remove( this.externalDatabase );
}
Aggregations