use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class TaxonArg method getGenesOnChromosome.
/**
* Lists Genes overlapping a location on a specific chromosome on a taxon that this TaxonArg represents.
*
* @param taxonService the service that will be used to retrieve the persistent Taxon object.
* @param chromosomeService the service that will be used to find the Chromosome object.
* @param geneService the service that will be used to retrieve the Gene VOs
* @param chromosomeName name of the chromosome to look on
* @param start the start nucleotide denoting the location to look for genes at.
* @param size the size (in nucleotides) of the location from the 'start' nucleotide.
* @return collection of Gene VOs overlapping the location defined by the 'start' and 'size' parameters.
*/
public Collection<GeneValueObject> getGenesOnChromosome(TaxonService taxonService, ChromosomeService chromosomeService, GeneService geneService, String chromosomeName, long start, int size) {
// Taxon argument
Taxon taxon = this.getPersistentObject(taxonService);
// Chromosome argument
Collection<Chromosome> chromosomes = chromosomeService.find(chromosomeName, taxon);
if (chromosomes.isEmpty()) {
WellComposedErrorBody errorBody = new WellComposedErrorBody(Response.Status.NOT_FOUND, "Chromosome " + chromosomeName + " not found for taxon " + taxon.getScientificName());
throw new GemmaApiException(errorBody);
}
Chromosome chromosome = chromosomes.iterator().next();
// Setup chromosome location
PhysicalLocation region = PhysicalLocation.Factory.newInstance(chromosome);
region.setNucleotide(start);
region.setNucleotideLength(size);
// region.setStrand( strand );
Collection<GeneValueObject> GVOs = geneService.loadValueObjects(geneService.find(region));
if (GVOs == null) {
WellComposedErrorBody errorBody = new WellComposedErrorBody(Response.Status.NOT_FOUND, "No genes found on chromosome " + chromosomeName + " between positions " + start + " and " + start + size + ".");
throw new GemmaApiException(errorBody);
}
return GVOs;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class SessionListManagerImpl method getGenesInGroup.
@Override
public Collection<GeneValueObject> getGenesInGroup(Long groupId) {
Collection<GeneValueObject> results;
GeneSet gs = geneSetService.load(groupId);
if (gs == null)
// TODO: Send and error code/feedback?
return null;
results = GeneValueObject.convertMembers2GeneValueObjects(gs.getMembers());
return results;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneSetSearchImpl method findByPhenotypeName.
@Override
public Collection<GeneSetValueObject> findByPhenotypeName(String phenotypeQuery, Taxon taxon) {
StopWatch timer = new StopWatch();
timer.start();
Collection<CharacteristicValueObject> phenotypes = phenotypeAssociationManagerService.searchOntologyForPhenotypes(StringUtils.strip(phenotypeQuery), null);
Collection<GeneSetValueObject> results = new HashSet<>();
if (phenotypes.isEmpty()) {
return results;
}
if (timer.getTime() > 200) {
GeneSetSearchImpl.log.info("Find phenotypes: " + timer.getTime() + "ms");
}
GeneSetSearchImpl.log.debug(" Converting CharacteristicValueObjects collection(size:" + phenotypes.size() + ") into GeneSets for phenotype query " + phenotypeQuery);
Map<String, CharacteristicValueObject> uris = new HashMap<>();
for (CharacteristicValueObject cvo : phenotypes) {
uris.put(cvo.getValueUri(), cvo);
}
Map<String, Collection<? extends GeneValueObject>> genes = phenotypeAssociationManagerService.findCandidateGenesForEach(uris.keySet(), taxon);
if (timer.getTime() > 500) {
GeneSetSearchImpl.log.info("Find phenotype genes done at " + timer.getTime() + "ms");
}
for (String uri : genes.keySet()) {
Collection<? extends GeneValueObject> gvos = genes.get(uri);
if (gvos.isEmpty())
continue;
Collection<Long> geneIds = EntityUtils.getIds(gvos);
GeneSetValueObject transientGeneSet = new GeneSetValueObject();
transientGeneSet.setName(this.uri2phenoID(uris.get(uri)));
transientGeneSet.setDescription(uris.get(uri).getValue());
transientGeneSet.setGeneIds(geneIds);
transientGeneSet.setTaxonId(gvos.iterator().next().getTaxonId());
transientGeneSet.setTaxonName(gvos.iterator().next().getTaxonCommonName());
results.add(transientGeneSet);
}
if (timer.getTime() > 1000) {
GeneSetSearchImpl.log.info("Loaded " + phenotypes.size() + " phenotype gene sets for query " + phenotypeQuery + " in " + timer.getTime() + "ms");
}
return results;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class ArrayDesignMapResultServiceImpl method getSummaryMapValueObjects.
@Override
public Collection<CompositeSequenceMapValueObject> getSummaryMapValueObjects(Collection<Object[]> sequenceData) {
Map<Long, CompositeSequenceMapValueObject> summary = new HashMap<>();
Map<Long, Set<Integer>> blatResultCount = new HashMap<>();
for (Object o : sequenceData) {
Object[] row = (Object[]) o;
Long csId = ((BigInteger) row[0]).longValue();
CompositeSequenceMapValueObject vo;
if (summary.containsKey(csId)) {
vo = summary.get(csId);
} else {
vo = new CompositeSequenceMapValueObject();
summary.put(csId, vo);
}
String csName = (String) row[1];
String bioSequenceName = (String) row[2];
String bioSequenceNcbiId = (String) row[3];
Long blatId = null;
if (row[4] != null) {
blatId = ((BigInteger) row[4]).longValue();
}
if (row[10] != null) {
// When viewing array designs, many will not have a gene.
Long geneProductId = ((BigInteger) row[5]).longValue();
String geneProductName = (String) row[6];
String geneProductAccession = (String) row[7];
Object geneProductGeneId = row[8];
String geneProductType = (String) row[9];
Long geneId = ((BigInteger) row[10]).longValue();
String geneName = (String) row[11];
// NCBI
Integer geneAccession = (Integer) row[12];
// fill in value object for geneProducts
Map<Long, GeneProductValueObject> geneProductSet = vo.getGeneProducts();
// if it isn't there, put it in the map
if (!geneProductSet.containsKey(geneProductId)) {
GeneProductValueObject gpVo = new GeneProductValueObject(geneProductId);
gpVo.setName(geneProductName);
gpVo.setNcbiId(geneProductAccession);
if (geneProductGeneId != null) {
gpVo.setGeneId(((BigInteger) geneProductGeneId).longValue());
}
gpVo.setType(geneProductType);
geneProductSet.put(geneProductId, gpVo);
}
Map<Long, GeneValueObject> geneSet = vo.getGenes();
if (!geneSet.containsKey(geneId)) {
GeneValueObject gVo = new GeneValueObject(geneId);
gVo.setOfficialSymbol(geneName);
gVo.setNcbiId(geneAccession);
geneSet.put(geneId, gVo);
}
}
String arrayDesignShortName = (String) row[13];
Long arrayDesignId = ((BigInteger) row[14]).longValue();
String csDesc = (String) row[20];
vo.setCompositeSequenceDescription(csDesc);
vo.setArrayDesignId(arrayDesignId);
vo.setCompositeSequenceId(csId.toString());
vo.setCompositeSequenceName(csName);
vo.setArrayDesignShortName(arrayDesignShortName);
vo.setArrayDesignName((String) row[21]);
// fill in value object
if (bioSequenceName != null && vo.getBioSequenceName() == null) {
vo.setBioSequenceName(bioSequenceName);
}
// fill in value object
if (bioSequenceNcbiId != null && vo.getBioSequenceNcbiId() == null) {
vo.setBioSequenceNcbiId(bioSequenceNcbiId);
}
if (blatId != null)
this.countBlatHits(row, blatResultCount, csId, vo);
}
return summary.values();
}
use of ubic.gemma.model.genome.gene.GeneValueObject 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();
}
Aggregations