Search in sources :

Example 1 with IdArrayValueObject

use of ubic.gemma.model.analysis.expression.coexpression.IdArrayValueObject in project Gemma by PavlidisLab.

the class CoexpressionDaoImpl method convertToValueObjects.

private Map<Long, List<CoexpressionValueObject>> convertToValueObjects(List<Object[]> rawResults, List<Object[]> supportDetails, Collection<Long> geneIds) {
    int removed = 0;
    Set<NonPersistentNonOrderedCoexpLink> allSeen = new HashSet<>(rawResults.size());
    // unwrap the supportDetails into a map.
    Map<Long, Set<Long>> supportDetailsLists = null;
    if (supportDetails != null) {
        supportDetailsLists = new HashMap<>();
        for (Object[] oa : supportDetails) {
            Long id = ((BigInteger) oa[0]).longValue();
            byte[] data = (byte[]) oa[1];
            IdArrayValueObject vo = new IdArrayValueObject(data);
            supportDetailsLists.put(id, vo.getIdsSet());
        }
    }
    StopWatch timer = new StopWatch();
    timer.start();
    Map<Long, List<CoexpressionValueObject>> results = new HashMap<>();
    int numUnsupported = 0;
    int n = 0;
    for (Object[] oa : rawResults) {
        Long id = ((BigInteger) oa[0]).longValue();
        Boolean pos = (byte) oa[1] > 0;
        Integer support = (Integer) oa[2];
        Long queryGeneId = ((BigInteger) oa[3]).longValue();
        Long secondGene = ((BigInteger) oa[4]).longValue();
        Long supportDetailsId = ((BigInteger) oa[5]).longValue();
        if (support == 0) {
            throw new IllegalArgumentException("Links should not be unsupported: " + id);
        }
        NonPersistentNonOrderedCoexpLink seen = new NonPersistentNonOrderedCoexpLink(queryGeneId, secondGene, pos);
        /*
             * remove duplicates, since each link can be here twice (x->y and y->x). (can happen.)
             */
        if (allSeen.contains(seen)) {
            ++removed;
            continue;
        }
        allSeen.add(seen);
        if (!results.containsKey(queryGeneId)) {
            results.put(queryGeneId, new ArrayList<CoexpressionValueObject>());
        }
        CoexpressionValueObject g2gvo = new CoexpressionValueObject(queryGeneId, secondGene, pos, support, supportDetailsId, supportDetailsLists == null ? null : supportDetailsLists.get(supportDetailsId));
        assert g2gvo.getNumDatasetsSupporting() > 0;
        results.get(queryGeneId).add(g2gvo);
        if (geneIds != null && geneIds.contains(g2gvo.getCoexGeneId())) {
            g2gvo.setInterQueryLink(true);
        }
        if (++n % 1000 == 0 && timer.getTime() > 1000) {
            CoexpressionDaoImpl.log.debug("Process " + n + " coexpressions: " + timer.getTime() + "ms");
            n = 0;
            timer.reset();
            timer.start();
        }
    }
    if (removed > 0)
        CoexpressionDaoImpl.log.debug("Removed " + removed + " duplicate links while converting to value objects");
    // noinspection ConstantConditions // Can change
    if (numUnsupported > 0)
        CoexpressionDaoImpl.log.info("Removed " + numUnsupported + " links that had support of zero.");
    if (results.isEmpty())
        throw new IllegalStateException("Removed everything! (of " + rawResults.size() + " results)");
    return results;
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) IdArrayValueObject(ubic.gemma.model.analysis.expression.coexpression.IdArrayValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) IdArrayValueObject(ubic.gemma.model.analysis.expression.coexpression.IdArrayValueObject) GeneCoexpressionNodeDegreeValueObject(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject)

Aggregations

BigInteger (java.math.BigInteger)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 IdArrayValueObject (ubic.gemma.model.analysis.expression.coexpression.IdArrayValueObject)1 GeneCoexpressionNodeDegreeValueObject (ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject)1 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)1