Search in sources :

Example 6 with BioSequence2GeneProduct

use of ubic.gemma.model.association.BioSequence2GeneProduct in project Gemma by PavlidisLab.

the class CompositeSequenceServiceImpl method getGeneMappingSummary.

@Override
public Collection<GeneMappingSummary> getGeneMappingSummary(CompositeSequence cs) {
    BioSequence biologicalCharacteristic = cs.getBiologicalCharacteristic();
    biologicalCharacteristic = bioSequenceService.thaw(biologicalCharacteristic);
    Map<Integer, GeneMappingSummary> results = new HashMap<>();
    if (biologicalCharacteristic == null || biologicalCharacteristic.getBioSequence2GeneProduct() == null) {
        return results.values();
    }
    Collection<BioSequence2GeneProduct> bs2gps = biologicalCharacteristic.getBioSequence2GeneProduct();
    for (BioSequence2GeneProduct bs2gp : bs2gps) {
        GeneProductValueObject geneProduct = new GeneProductValueObject(geneProductService.thaw(bs2gp.getGeneProduct()));
        GeneValueObject gene = new GeneValueObject(bs2gp.getGeneProduct().getGene());
        BlatResultValueObject blatResult = null;
        if ((bs2gp instanceof BlatAssociation)) {
            BlatAssociation blatAssociation = (BlatAssociation) bs2gp;
            blatResult = new BlatResultValueObject(blatResultService.thaw(blatAssociation.getBlatResult()));
        } else if (bs2gp instanceof AnnotationAssociation) {
            /*
                 * Make a dummy blat result
                 */
            blatResult = new BlatResultValueObject();
            blatResult.setQuerySequence(BioSequenceValueObject.fromEntity(biologicalCharacteristic));
            blatResult.setId(biologicalCharacteristic.getId());
        }
        if (blatResult == null) {
            continue;
        }
        if (results.containsKey(ProbeMapUtils.hashBlatResult(blatResult))) {
            results.get(ProbeMapUtils.hashBlatResult(blatResult)).addGene(geneProduct, gene);
        } else {
            GeneMappingSummary summary = new GeneMappingSummary();
            summary.addGene(geneProduct, gene);
            summary.setBlatResult(blatResult);
            summary.setCompositeSequence(this.loadValueObject(cs));
            results.put(ProbeMapUtils.hashBlatResult(blatResult), summary);
        }
    }
    this.addBlatResultsLackingGenes(cs, results);
    if (results.size() == 0) {
        // add a 'dummy' that at least contains the information about the CS. This is a bit of a hack...
        GeneMappingSummary summary = new GeneMappingSummary();
        summary.setCompositeSequence(this.loadValueObject(cs));
        BlatResultValueObject newInstance = new BlatResultValueObject(-1L);
        newInstance.setQuerySequence(BioSequenceValueObject.fromEntity(biologicalCharacteristic));
        summary.setBlatResult(newInstance);
        results.put(ProbeMapUtils.hashBlatResult(newInstance), summary);
    }
    return results.values();
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) AnnotationAssociation(ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) GeneMappingSummary(ubic.gemma.core.analysis.sequence.GeneMappingSummary) BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) BlatResultValueObject(ubic.gemma.model.genome.sequenceAnalysis.BlatResultValueObject) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)

Example 7 with BioSequence2GeneProduct

use of ubic.gemma.model.association.BioSequence2GeneProduct in project Gemma by PavlidisLab.

the class LinkAnalysisServiceImpl method getProbe2GeneMap.

/**
 * Fills in the probe2gene map for the linkAnalysis. Note that the collection DOES NOT contain probes that have NO
 * genes mapped
 *
 * @param eeDoubleMatrix - used to make sure we don't use probes from vectors that are removed?
 */
private void getProbe2GeneMap(LinkAnalysis la, Collection<ProcessedExpressionDataVector> dataVectors, ExpressionDataDoubleMatrix eeDoubleMatrix) {
    Collection<CompositeSequence> probesForVectors = new HashSet<>();
    for (DesignElementDataVector v : dataVectors) {
        CompositeSequence cs = v.getDesignElement();
        if (eeDoubleMatrix.getRow(cs) != null)
            probesForVectors.add(cs);
    }
    Map<CompositeSequence, Collection<BioSequence2GeneProduct>> specificityData = csService.getGenesWithSpecificity(probesForVectors);
    assert !specificityData.isEmpty();
    /*
         * Convert the specificity
         */
    Map<CompositeSequence, Set<Gene>> probeToGeneMap = new HashMap<>();
    for (CompositeSequence cs : specificityData.keySet()) {
        Collection<BioSequence2GeneProduct> bioSequenceToGeneProducts = specificityData.get(cs);
        if (!probeToGeneMap.containsKey(cs)) {
            probeToGeneMap.put(cs, new HashSet<Gene>());
        }
        for (BioSequence2GeneProduct bioSequence2GeneProduct : bioSequenceToGeneProducts) {
            Gene gene = bioSequence2GeneProduct.getGeneProduct().getGene();
            probeToGeneMap.get(cs).add(gene);
        }
    }
    /*
         * Remove the probes that have no mapping
         */
    int startingSize = probeToGeneMap.size();
    int numRemoved = 0;
    for (Iterator<CompositeSequence> it = probeToGeneMap.keySet().iterator(); it.hasNext(); ) {
        CompositeSequence cs = it.next();
        if (probeToGeneMap.get(cs).isEmpty()) {
            it.remove();
            numRemoved++;
        }
    }
    if (numRemoved > 0) {
        LinkAnalysisServiceImpl.log.info(numRemoved + "/" + startingSize + " elements had no genes mapped and were removed.");
    }
    // assert !probeToGeneMap.isEmpty();
    if (probeToGeneMap.isEmpty()) {
        throw new IllegalStateException("No probes are mapped to genes; example=" + probeToGeneMap.keySet().iterator().next());
    }
    la.setProbeToGeneMap(probeToGeneMap);
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) Gene(ubic.gemma.model.genome.Gene) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)

Example 8 with BioSequence2GeneProduct

use of ubic.gemma.model.association.BioSequence2GeneProduct 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;
}
Also used : Gene(ubic.gemma.model.genome.Gene) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 9 with BioSequence2GeneProduct

use of ubic.gemma.model.association.BioSequence2GeneProduct in project Gemma by PavlidisLab.

the class ExpressionAnalysisResultSet method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    for (DifferentialExpressionAnalysisResult dear : this.getResults()) {
        int count = 0;
        CompositeSequence cs = dear.getProbe();
        buf.append(cs.getName()).append("\t");
        for (BioSequence2GeneProduct bs2gp : cs.getBiologicalCharacteristic().getBioSequence2GeneProduct()) {
            Gene g = bs2gp.getGeneProduct().getGene();
            if (g != null) {
                buf.append(bs2gp.getGeneProduct().getGene().getOfficialSymbol()).append(",");
                count++;
            }
        }
        if (count != 0)
            // removing trailing ,
            buf.deleteCharAt(buf.lastIndexOf(","));
        buf.append("\t");
        count = 0;
        for (ExperimentalFactor ef : this.getExperimentalFactors()) {
            buf.append(ef.getName()).append(",");
            count++;
        }
        if (count != 0)
            // removing trailing ,
            buf.deleteCharAt(buf.lastIndexOf(","));
        buf.append("\t");
        buf.append(dear.getCorrectedPvalue()).append("\n");
    }
    return buf.toString();
}
Also used : Gene(ubic.gemma.model.genome.Gene) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 10 with BioSequence2GeneProduct

use of ubic.gemma.model.association.BioSequence2GeneProduct in project Gemma by PavlidisLab.

the class GoldenPathSequenceAnalysis method getThreePrimeDistances.

/**
 * Uses default mapping settings
 *
 * @param identifier identifier
 * @param method the method
 * @return bio seq 2 gene producs
 */
public Collection<BioSequence2GeneProduct> getThreePrimeDistances(String identifier, ThreePrimeDistanceMethod method) {
    Collection<BlatResult> locations = this.findSequenceLocations(identifier);
    Collection<BioSequence2GeneProduct> results = new HashSet<>();
    for (BlatResult br : locations) {
        results.addAll(this.getThreePrimeDistances(br, method));
    }
    return results;
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) BlatResult(ubic.gemma.model.genome.sequenceAnalysis.BlatResult) HashSet(java.util.HashSet)

Aggregations

BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)11 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)6 Gene (ubic.gemma.model.genome.Gene)5 BlatAssociation (ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)4 HashSet (java.util.HashSet)2 CompositeSequenceValueObject (ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)2 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)2 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)2 BlatResult (ubic.gemma.model.genome.sequenceAnalysis.BlatResult)2 org.hibernate (org.hibernate)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)1 GeneMappingSummary (ubic.gemma.core.analysis.sequence.GeneMappingSummary)1 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)1 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)1 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)1 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)1 GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)1 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)1 AnnotationAssociation (ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation)1