Search in sources :

Example 41 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class CompositeSequenceMapSummary method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append(compositeSequence.getName()).append("\t");
    if (compositeSequence.getBiologicalCharacteristic() != null) {
        buf.append(compositeSequence.getBiologicalCharacteristic().getName()).append("\t");
    } else {
        buf.append("\t");
    }
    buf.append(blatResults.size()).append("\t");
    for (GeneProduct gp : geneProducts) {
        buf.append(gp.getName()).append("|");
    }
    buf.append("\t");
    for (Gene g : genes) {
        buf.append(g.getOfficialSymbol()).append("|");
    }
    return buf.toString().replaceAll("\\|\t", "\t").replaceFirst("\\|$", "");
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) Gene(ubic.gemma.model.genome.Gene)

Example 42 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class CompositeSequenceGeneMapperService method getGene2ProbeMapByOfficialSymbols.

/**
 * @param arrayDesigns    to look in
 * @param officialSymbols official symbols
 * @return map of gene to composite sequences
 */
public LinkedHashMap<Gene, Collection<CompositeSequence>> getGene2ProbeMapByOfficialSymbols(Collection<String> officialSymbols, Collection<ArrayDesign> arrayDesigns) {
    LinkedHashMap<String, Collection<Gene>> genesMap = this.findGenesByOfficialSymbols(officialSymbols);
    Set<String> geneOfficialSymbolKeySet = genesMap.keySet();
    LinkedHashMap<Gene, Collection<CompositeSequence>> compositeSequencesForGeneMap = new LinkedHashMap<>();
    for (String officialSymbol : geneOfficialSymbolKeySet) {
        log.debug("official symbol: " + officialSymbol);
        Collection<Gene> genes = genesMap.get(officialSymbol);
        for (Gene g : genes) {
            Collection<CompositeSequence> compositeSequences = geneService.getCompositeSequencesById(g.getId());
            for (CompositeSequence sequence : compositeSequences) {
                if (arrayDesigns.contains(sequence.getArrayDesign())) {
                    if (compositeSequencesForGeneMap.get(g) == null) {
                        compositeSequencesForGeneMap.put(g, new HashSet<CompositeSequence>());
                    }
                    compositeSequencesForGeneMap.get(g).add(sequence);
                }
            }
        }
    }
    return compositeSequencesForGeneMap;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class GenericGenelistDesignGenerator method getExistingGeneMap.

/**
 * For gene symbols.
 */
private Map<Gene, CompositeSequence> getExistingGeneMap(ArrayDesign arrayDesign) {
    Map<Gene, CompositeSequence> existingElements = new HashMap<>();
    if (arrayDesign.getCompositeSequences().isEmpty())
        return existingElements;
    AbstractCLI.log.info("Loading genes for existing platform ...");
    Map<CompositeSequence, Collection<Gene>> geneMap = compositeSequenceService.getGenes(arrayDesign.getCompositeSequences());
    AbstractCLI.log.info("Platform has genes already for " + geneMap.size() + "/" + arrayDesign.getCompositeSequences().size() + " elements.");
    for (CompositeSequence cs : geneMap.keySet()) {
        Collection<Gene> genes = geneMap.get(cs);
        /*
             * Two genes with the same symbol, but might be a mistake from an earlier run.
             */
        Gene g = null;
        if (genes.size() > 1) {
            AbstractCLI.log.warn("More than one gene for: " + cs + ": " + StringUtils.join(genes, ";"));
            for (Gene cg : genes) {
                if (cg.getOfficialSymbol().equals(cs.getName())) {
                    g = cg;
                }
            }
        } else {
            g = genes.iterator().next();
        }
        existingElements.put(g, cs);
    }
    return existingElements;
}
Also used : Gene(ubic.gemma.model.genome.Gene) HashMap(java.util.HashMap) Collection(java.util.Collection) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 44 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class GeneralSearchControllerImpl method fillValueObjects.

@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<?> vos;
    if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
        vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
        }
    } else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
        vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
        }
    } else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
        Collection<CompositeSequenceValueObject> css = new ArrayList<>();
        for (SearchResult sr : results) {
            CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
            css.add(csvo);
        }
        vos = css;
    } else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
        Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
        bss = bibliographicReferenceService.thaw(bss);
        vos = bibliographicReferenceService.loadValueObjects(bss);
    } else if (Gene.class.isAssignableFrom(entityClass)) {
        Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
        genes = geneService.thawLite(genes);
        vos = geneService.loadValueObjects(genes);
    } else if (Characteristic.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            Characteristic ch = (Characteristic) sr.getResultObject();
            cvos.add(new CharacteristicValueObject(ch));
        }
        vos = cvos;
    } else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
            cvos.add(ch);
        }
        vos = cvos;
    } else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
        return;
    } else if (GeneSet.class.isAssignableFrom(entityClass)) {
        vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
    } else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
        vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
    } else if (FactorValue.class.isAssignableFrom(entityClass)) {
        Collection<FactorValueValueObject> fvo = new ArrayList<>();
        for (SearchResult sr : results) {
            fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
        }
        vos = fvo;
    } else {
        throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
    }
    if (vos == null || vos.isEmpty()) {
        // it causing front end errors, if vos is empty make sure to get rid of all search results
        for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
            it.next();
            it.remove();
        }
        return;
    }
    // retained objects...
    Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
    for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
        SearchResult sr = it.next();
        if (!idMap.containsKey(sr.getId())) {
            it.remove();
            continue;
        }
        sr.setResultObject(idMap.get(sr.getId()));
    }
    if (timer.getTime() > 1000) {
        BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
    }
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) Gene(ubic.gemma.model.genome.Gene) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Characteristic(ubic.gemma.model.common.description.Characteristic) SearchResult(ubic.gemma.core.search.SearchResult) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) SearchSettingsValueObject(ubic.gemma.model.common.search.SearchSettingsValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)

Example 45 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class GeneServiceTest method testLoadGenes.

@Test
public void testLoadGenes() {
    Taxon human = taxonService.findByCommonName("human");
    Gene gene = Gene.Factory.newInstance();
    Integer id = Integer.parseInt(RandomStringUtils.randomNumeric(5));
    gene.setNcbiGeneId(id);
    gene.setName("Ma_Gene");
    gene.setDescription("Lost in space");
    gene.setTaxon(human);
    geneDao.create(gene);
    Collection<Gene> genes = geneDao.loadAll(human);
    assertNotNull(genes);
    assertTrue(genes.contains(gene));
    geneDao.remove(gene);
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Aggregations

Gene (ubic.gemma.model.genome.Gene)186 Taxon (ubic.gemma.model.genome.Taxon)34 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)32 StopWatch (org.apache.commons.lang3.time.StopWatch)31 Test (org.junit.Test)24 HashSet (java.util.HashSet)23 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)20 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)18 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 Collection (java.util.Collection)11 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)11 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)10 HashMap (java.util.HashMap)8 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)7