Search in sources :

Example 1 with GeneProductValueObject

use of ubic.gemma.model.genome.gene.GeneProductValueObject 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();
}
Also used : GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) BigInteger(java.math.BigInteger) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) BigInteger(java.math.BigInteger) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject)

Example 2 with GeneProductValueObject

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

the class ExternalFileGeneLoaderServiceImpl method createGene.

/**
 * Creates a gene, where gene name and official gene symbol is set to gene symbol(from file) and official name is
 * set to geneName(from file). The gene description is set to a message indicating that the gene was imported from
 * an external file and the associated uniprot id.
 * If the gene already exists, then it is not modified, unless it lacks a gene product. In that case we add one and
 * return it.
 *
 * @param fields A string array containing gene symbol, gene name and uniprot id.
 * @param taxon  Taxon relating to gene
 * @return Gene with associated gene product for loading into Gemma. Null if no gene was loaded (exists, or invalid
 * fields) or modified.
 */
private Gene createGene(String[] fields, Taxon taxon) {
    assert fields.length > 1;
    String geneSymbol = fields[0];
    String geneName = fields[1];
    String uniProt = "";
    if (fields.length > 2)
        uniProt = fields[2];
    Gene gene;
    // need at least the gene symbol and gene name
    if (StringUtils.isBlank(geneSymbol) || StringUtils.isBlank(geneName)) {
        log.warn("Line did not contain valid gene information; GeneSymbol=" + geneSymbol + "GeneName=" + geneName + " UniProt=" + uniProt);
        return null;
    }
    if (log.isDebugEnabled())
        log.debug("Creating gene " + geneSymbol);
    gene = geneService.findByOfficialSymbol(geneSymbol, taxon);
    if (gene != null) {
        Collection<GeneProductValueObject> existingProducts = geneService.getProducts(gene.getId());
        if (existingProducts.isEmpty()) {
            log.warn("Gene " + gene + " exists, but has no products; adding one");
            gene = geneService.thaw(gene);
            GeneProduct newgp = createGeneProduct(gene);
            newgp = geneProductService.create(newgp);
            gene.getProducts().add(newgp);
            geneService.update(gene);
            return gene;
        }
        log.info(gene + " already exists and is valid, will not update");
        // no need to create it, though we ignore the name.
        return null;
    }
    gene = Gene.Factory.newInstance();
    gene.setName(geneSymbol);
    gene.setOfficialSymbol(geneSymbol);
    gene.setOfficialName(StringUtils.lowerCase(geneName));
    gene.setDescription("Imported from external annotation file");
    gene.setTaxon(taxon);
    gene.getProducts().add(createGeneProduct(gene));
    gene = (Gene) persisterHelper.persistOrUpdate(gene);
    return gene;
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) Gene(ubic.gemma.model.genome.Gene)

Example 3 with GeneProductValueObject

use of ubic.gemma.model.genome.gene.GeneProductValueObject 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)

Aggregations

GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)3 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 BigInteger (java.math.BigInteger)1 GeneMappingSummary (ubic.gemma.core.analysis.sequence.GeneMappingSummary)1 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)1 Gene (ubic.gemma.model.genome.Gene)1 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)1 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)1 AnnotationAssociation (ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation)1 BlatAssociation (ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)1 BlatResultValueObject (ubic.gemma.model.genome.sequenceAnalysis.BlatResultValueObject)1