Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry-Weymouth committed Jun 26, 2013
2 parents 14e2ad5 + a69f412 commit 7dda7a9
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 79 deletions.
6 changes: 3 additions & 3 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Grails Metadata file
#Thu Feb 28 15:57:41 CET 2013
app.grails.version=2.2.1
#Wed May 15 15:47:34 CEST 2013
app.grails.version=2.2.2
app.name=transmart-core
plugins.hibernate=2.2.1
plugins.hibernate=2.2.2
8 changes: 5 additions & 3 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"

grails.project.repos.default = 'repo.hyve.nl-snapshots'
grails.project.repos.default = 'repo.thehyve.nl-snapshots'
grails.project.repos."${grails.project.repos.default}".url = 'http://repo.thehyve.nl/content/repositories/snapshots/'

grails.project.dependency.resolution = {
Expand All @@ -18,7 +18,7 @@ grails.project.dependency.resolution = {
mavenLocal()
mavenCentral()
mavenRepo([
name: 'repo.hyve.nl-snapshots',
name: 'repo.thehyve.nl-snapshots',
root: 'http://repo.thehyve.nl/content/repositories/snapshots/',
])
}
Expand All @@ -45,11 +45,13 @@ grails.project.dependency.resolution = {
compile(':db-reverse-engineer:0.5') { exported: false }

build(":tomcat:$grailsVersion",
":release:2.2.0",
":release:2.2.1",
":rest-client-builder:1.0.3",
) {
exported: false
}

test ":code-coverage:1.2.6"
}

// see http://jira.grails.org/browse/GPRELEASE-42
Expand Down
2 changes: 1 addition & 1 deletion grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// configuration for plugin testing - will not be included in the plugin zip

def dataSourceConfig = new File("${userHome}/" +
".grails/transmartConfig/DataSource.groovy")
".grails/transmartConfig/DataSource-coredb.groovy")

if (!dataSourceConfig.exists())
throw new RuntimeException("Coult not find ${dataSourceConfig}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DeChromosomalRegion implements Region {
Long end
Integer numberOfProbes
String name
String cytoband

/* unused */
String geneSymbol
Expand Down Expand Up @@ -41,6 +42,7 @@ class DeChromosomalRegion implements Region {
end nullable: true
numberOfProbes nullable: true
name nullable: true, maxSize: 100
cytoband nullable: true, maxSize: 100
geneSymbol nullable: true, maxSize: 100
geneId nullable: true
organism nullable: true, maxSize: 200
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.transmartproject.db.dataquery

import groovy.transform.CompileStatic
import org.hibernate.Query
import org.hibernate.ScrollableResults
import org.hibernate.Session
import org.hibernate.StatelessSession
import org.hibernate.impl.AbstractSessionImpl
import org.transmartproject.core.dataquery.DataQueryResource
import org.transmartproject.core.dataquery.acgh.RegionResult
import org.transmartproject.core.dataquery.assay.Assay
import org.transmartproject.core.dataquery.constraints.ACGHRegionQuery
import org.transmartproject.core.dataquery.acgh.Region
import org.transmartproject.core.dataquery.acgh.ACGHValues
import org.transmartproject.core.dataquery.acgh.CopyNumberState
import org.transmartproject.core.dataquery.Platform
import org.transmartproject.core.dataquery.acgh.RegionRow

import static org.hibernate.ScrollMode.FORWARD_ONLY

class DataQueryResourceNoGormService extends DataQueryResourceService {

@Override
protected RegionResult getRegionResultForAssays(final List<Assay> assays, AbstractSessionImpl session) {
def mainHQL = '''
select
acgh.assay.id,
acgh.chipCopyNumberValue,
acgh.segmentCopyNumberValue,
acgh.flag,
acgh.probabilityOfLoss,
acgh.probabilityOfNormal,
acgh.probabilityOfGain,
acgh.probabilityOfAmplification,
region.id,
region.cytoband,
region.chromosome,
region.start,
region.end,
region.numberOfProbes
from DeSubjectAcghData as acgh
inner join acgh.region region
where acgh.assay.id in (:assayIds)
order by region.id, acgh.assay.id'''.stripIndent()

def mainQuery = createQuery(session, mainHQL, ['assayIds': assays.collect {Assay assay -> assay.id}]).scroll(FORWARD_ONLY)

new RegionResultListImpl(assays, mainQuery)
}

@CompileStatic
class ACGHValuesImpl implements ACGHValues {
final List rowList

ACGHValuesImpl(final List rowList) {
this.rowList = rowList
}

Long getAssayId() { rowList[0] as Long }

Double getChipCopyNumberValue() { rowList[1] as Double }

Double getSegmentCopyNumberValue() { rowList[2] as Double }

CopyNumberState getCopyNumberState() { CopyNumberState.forInteger((rowList[3] as Short).intValue()) }

Double getProbabilityOfLoss() { rowList[4] as Double }

Double getProbabilityOfNormal() { rowList[5] as Double }

Double getProbabilityOfGain() { rowList[6] as Double }

Double getProbabilityOfAmplification() { rowList[7] as Double }

}

@CompileStatic
class RegionImpl implements Region {

final List rowList

RegionImpl(final List rowList) {
this.rowList = rowList
}

Long getId() { rowList[8] as Long }

String getCytoband() { rowList[9] as String }

Platform getPlatform() {
throw new UnsupportedOperationException('Getter for get platform is not implemented')
}

String getChromosome() { rowList[10] as String }

Long getStart() { rowList[11] as Long }

Long getEnd() { rowList[12] as Long }

Integer getNumberOfProbes() { rowList[13] as Integer }

}

@CompileStatic
class RegionResultListImpl extends org.transmartproject.db.dataquery.RegionResultImpl {
RegionResultListImpl(List<Assay> indicesList, ScrollableResults results) {
super(indicesList, results)
}

@Override
protected RegionRow getNextRegionRow() {
List rowList = results.get() as List
if (rowList == null) {
return null
}

RegionImpl region = new RegionImpl(rowList)
ACGHValuesImpl acghValue = new ACGHValuesImpl(rowList)

Map values = new HashMap(indicesList.size(), 1)
while (new RegionImpl(rowList).id == region.id) {
values[acghValue.assayId] = acghValue

if (!results.next()) {
break
}
rowList = results.get() as List
acghValue = new ACGHValuesImpl(rowList)
}

new RegionRowImpl(region, indicesList, values)
}
}
}


Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.transmartproject.db.dataquery

import org.apache.commons.beanutils.PropertyUtils
import org.hibernate.Query
import org.hibernate.Session
import org.hibernate.StatelessSession
import org.hibernate.impl.AbstractSessionImpl
import org.transmartproject.core.dataquery.DataQueryResource
import org.transmartproject.core.dataquery.acgh.RegionResult
import org.transmartproject.core.dataquery.assay.Assay
import org.transmartproject.core.dataquery.constraints.ACGHRegionQuery
import org.transmartproject.db.highdim.DeSubjectAcghData

import static org.hibernate.ScrollMode.FORWARD_ONLY

Expand All @@ -19,35 +18,42 @@ class DataQueryResourceService implements DataQueryResource {
@Override
RegionResult runACGHRegionQuery(ACGHRegionQuery spec, session) {
if (!(session == null || session instanceof Session || session
instanceof StatelessSession))
instanceof StatelessSession)) {
throw new IllegalArgumentException('Expected session to be null ' +
'or an instance of type org.hibernate.Session or ' +
'org.hibernate.StatelessSession')
}

validateQuery(spec)

session = session ?: sessionFactory.currentSession
List<Assay> assays = getAssaysForACGHRegionQuery(spec, session)
if (log.isDebugEnabled()) {
log.debug("Found ${assays.size()} assays: " +
assays.collect {
"{id: $it.id, subjectId: $it.subjectId}"
}.join(", "))
}

getRegionResultForAssays(assays, session)
}

def whereClauses,
params
protected List<Assay> getAssaysForACGHRegionQuery(ACGHRegionQuery spec, AbstractSessionImpl session) {
def whereClauses, params

/* first obtain list of assays */
whereClauses = []
params = [:]
populateWhereClauses(spec,whereClauses, params)
populateWhereClauses(spec, whereClauses, params)

def assayHQL = 'from DeSubjectSampleMapping assay\n'
assayHQL <<= 'where ' + whereClauses.join("\nand ") + "\n"
assayHQL <<= 'order by assay\n'

List<Assay> assays = createQuery(session, assayHQL, params).list()
if (log.isDebugEnabled()) {
log.debug("Found ${assays.size()} assays: " +
assays.collect {
"{id: $it.id, subjectId: $id.subjectId}"
}.join(", "))
}
createQuery(session, assayHQL, params).list()
}

protected RegionResult getRegionResultForAssays(final List<Assay> assays, AbstractSessionImpl session) {
/* Then obtain the meat.
*
* Doing 'select acgh from ... inner join fetch acgh.region' should
Expand All @@ -67,21 +73,23 @@ class DataQueryResourceService implements DataQueryResource {
* query before just to get the regions. This would minimize the
* amount of data that the postgres server has to send us.
*/
def mainHQL = 'select acgh, acgh.region\n' +
'from DeSubjectAcghData as acgh\n' +
'inner join acgh.assay assay\n'
//'inner join acgh.region\n'
mainHQL <<= 'where ' + whereClauses.join("\nand ") + "\n"
mainHQL <<= 'order by acgh.region.id, assay\n'

new RegionResultImpl(assays,
createQuery(session, mainHQL, params).scroll(FORWARD_ONLY))
def mainHQL = '''
select acgh, acgh.region
from DeSubjectAcghData as acgh
inner join acgh.assay assay
where assay in (:assays)
order by acgh.region.id, assay'''

def mainQuery = createQuery(session, mainHQL, ['assays': assays]).scroll(FORWARD_ONLY)

new RegionResultImpl(assays, mainQuery)
}

private void validateQuery(ACGHRegionQuery q) {
def checkEmptiness = { it, name ->
if (!it)
if (!it) {
throw new IllegalArgumentException("$name not specified/empty")
}
}
checkEmptiness(q.common, "query.common")
checkEmptiness(q.common.studies, "query.common.studies")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.transmartproject.db.dataquery

import groovy.transform.CompileStatic
import org.hibernate.ScrollableResults
import org.transmartproject.core.dataquery.acgh.RegionResult
import org.transmartproject.core.dataquery.acgh.RegionRow
import org.transmartproject.core.dataquery.assay.Assay
import org.transmartproject.db.highdim.DeChromosomalRegion
import org.transmartproject.db.highdim.DeSubjectAcghData

final class RegionResultImpl implements RegionResult, Closeable {
@CompileStatic
class RegionResultImpl implements RegionResult, Closeable {

final List<Assay> indicesList

Expand All @@ -20,13 +22,14 @@ final class RegionResultImpl implements RegionResult, Closeable {
this.results = results
}

private RegionRow getNextRegionRow() {
protected RegionRow getNextRegionRow() {
def entry = results.get()
if (entry == null)
if (entry == null) {
return null
}

DeSubjectAcghData v = entry[0]
DeChromosomalRegion commonRegion = entry[1]
DeSubjectAcghData v = entry[0] as DeSubjectAcghData
DeChromosomalRegion commonRegion = entry[1] as DeChromosomalRegion

Map values = new HashMap(indicesList.size())
/* Use .@ to access the field and bypass the getter. The problem is
Expand All @@ -38,9 +41,10 @@ final class RegionResultImpl implements RegionResult, Closeable {
while (v.@region.id == commonRegion.id) {
values[v.@assay.id] = v

if (!results.next())
if (!results.next()) {
break
v = results.get()[0]
}
v = results.get()[0] as DeSubjectAcghData
}

new RegionRowImpl(commonRegion, indicesList, values)
Expand All @@ -51,9 +55,9 @@ final class RegionResultImpl implements RegionResult, Closeable {
def row = getNextRegionRow()

[
hasNext: { row != null },
next: { def r = row; row = getNextRegionRow(); r },
remove: { throw new UnsupportedOperationException() }
hasNext: { row != null },
next: { def r = row; row = getNextRegionRow(); r },
remove: { throw new UnsupportedOperationException() }
] as Iterator<RegionRow>
}

Expand Down
Loading

0 comments on commit 7dda7a9

Please sign in to comment.