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