Skip to content

Commit

Permalink
Merge branch 'gitlab/f.guitton'
Browse files Browse the repository at this point in the history
  • Loading branch information
fguitton committed Aug 12, 2013
2 parents dcbf0a4 + 84430ea commit 4053733
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 95 deletions.
2 changes: 1 addition & 1 deletion grails-app/services/PlinkService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PlinkService {
select a.platform_name, a.trial_name
from DE_SUBJECT_SNP_DATASET a
INNER JOIN de_subject_sample_mapping c on c.omic_patient_id=a.patient_num
INNER JOIN (SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ? AND patient_num IN
INNER JOIN (SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric) AND patient_num IN
(SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%')) b on c.patient_id=b.patient_num
where rownum=1
and a.platform_name is not null
Expand Down
8 changes: 4 additions & 4 deletions grails-app/services/PostgresI2b2HelperService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class PostgresI2b2HelperService {

String sqlt="SELECT NVAL_NUM FROM OBSERVATION_FACT f WHERE CONCEPT_CD = '" +
concept_cd + "' AND PATIENT_NUM IN (select distinct patient_num " +
"from qt_patient_set_collection where result_instance_id = " + result_instance_id + ")";
"from qt_patient_set_collection where result_instance_id = CAST(" + result_instance_id + " AS numeric))";

log.debug("executing query: sqlt=" + sqlt);
try {
Expand Down Expand Up @@ -904,10 +904,10 @@ class PostgresI2b2HelperService {
from qt_patient_set_collection q
inner join patient_trial p
on q.patient_num=p.patient_num
where q.result_instance_id=""";
where q.result_instance_id=CAST(""";

String sqlTemplate2 = """ or result_instance_id=""";
String sqlTemplate3 = """) and x.parent_cd=""";
String sqlTemplate2 = """ AS numeric) or result_instance_id=CAST(""";
String sqlTemplate3 = """ AS numeric)) and x.parent_cd=""";



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AdditionalDataService {
select distinct s.sample_cd from de_subject_sample_mapping s
where s.trial_name in ${studies} and patient_id in (
SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd
WHERE sc.result_instance_id = ? AND sc.patient_num = pd.patient_num
WHERE sc.result_instance_id = CAST(? AS numeric) AND sc.patient_num = pd.patient_num
) and s.sample_cd is not null and b.file_name like s.sample_cd||'%'
)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ClinicalDataService {
sqlQuery <<= "LEFT JOIN DEAPP.DE_SUBJECT_SAMPLE_MAPPING ssm ON ssm.PATIENT_ID = ofa.PATIENT_NUM "
}

sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = ? AND ofa.MODIFIER_CD = ?"
sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) AND ofa.MODIFIER_CD = ?"

if (!retrievalTypeMRNAExists && parFilterHighLevelConcepts) {
sqlQuery <<= " AND cd.concept_cd NOT IN (SELECT DISTINCT NVL(sample_type_cd,'-1') as gene_expr_concept"
Expand Down Expand Up @@ -432,7 +432,7 @@ class ClinicalDataService {
queryToReturn <<= "INNER JOIN DE_XTRIAL_CHILD_MAP XMAP ON XMAP.CONCEPT_CD = ofa.CONCEPT_CD "
queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C1 ON C1.CONCEPT_CD = XMAP.CONCEPT_CD "
queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C2 ON C2.CONCEPT_CD = XMAP.PARENT_CD "
queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = ? "
queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) "
queryToReturn <<= "AND ofa.MODIFIER_CD = ? "
queryToReturn <<= "AND ofa.CONCEPT_CD IN "
queryToReturn <<= "( "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DataCountService {
StringBuilder subjectsFromBothSubsetsQuery = new StringBuilder()
StringBuilder gseaQuery = new StringBuilder()

subjectsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?")
subjectsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)")
.append(" AND patient_num IN (select patient_num from patient_dimension where sourcesystem_cd not like '%:S:%')")
subjectsFromBothSubsetsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id IN (")
.append(resultInstanceIds).append(')')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def findStudyAccessions( result_instance_ids){
def rids = []
for(r in result_instance_ids){
if(r?.trim()?.length()>0 ){
rids.add(r);
rids.add('CAST('+ r + ' AS numeric)');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class MetadataService {
select distinct s.sample_cd from de_subject_sample_mapping s
where s.trial_name = ? and patient_id in (
SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd
WHERE sc.result_instance_id = ? AND sc.patient_num = pd.patient_num
WHERE sc.result_instance_id = CAST(? AS numeric) AND sc.patient_num = pd.patient_num
) and s.sample_cd is not null and b.file_name like s.sample_cd||'%'
)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PostgresClinicalDataService {
sqlQuery <<= "LEFT JOIN DE_SUBJECT_SAMPLE_MAPPING ssm ON ssm.PATIENT_ID = ofa.PATIENT_NUM "
}

sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = ? AND ofa.MODIFIER_CD = ?"
sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) AND ofa.MODIFIER_CD = ?"

if (!retrievalTypeMRNAExists && parFilterHighLevelConcepts) {
sqlQuery <<= " AND cd.concept_cd NOT IN (SELECT DISTINCT coalesce(sample_type_cd,'-1') as gene_expr_concept"
Expand Down Expand Up @@ -436,7 +436,7 @@ class PostgresClinicalDataService {
queryToReturn <<= "INNER JOIN DE_XTRIAL_CHILD_MAP XMAP ON XMAP.CONCEPT_CD = ofa.CONCEPT_CD "
queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C1 ON C1.CONCEPT_CD = XMAP.CONCEPT_CD "
queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C2 ON C2.CONCEPT_CD = XMAP.PARENT_CD "
queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = ? "
queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) "
queryToReturn <<= "AND ofa.MODIFIER_CD = ? "
queryToReturn <<= "AND ofa.CONCEPT_CD IN "
queryToReturn <<= "( "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PostgresDataCountService {
StringBuilder gseaQuery = new StringBuilder()

subjectsQuery.append("select omic_patient_id from de_subject_sample_mapping where patient_id in ")
subjectsQuery.append("(SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?")
subjectsQuery.append("(SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)")
.append(" AND patient_num IN (select patient_num from patient_dimension where sourcesystem_cd not like '%:S:%'))")

subjectsFromBothSubsetsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id IN (")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class PostgresExportService {
def rID1 = RequestValidator.nullCheck(params.result_instance_id1)
def rID2 = RequestValidator.nullCheck(params.result_instance_id2)
def rIDs = null
if (rID1 && rID1?.trim() != '' && rID2 && rID2?.trim() != '') rIDs = rID1 + ',' + rID2
else if (rID1 && rID1?.trim() != '') rIDs = rID1
else if (rID2 && rID2?.trim() != '') rIDs = rID2
if (rID1 && rID1?.trim() != '' && rID2 && rID2?.trim() != '') rIDs = 'CAST(' + rID1 + ' AS numeric), CAST(' + rID2 + 'AS numeric)'
else if (rID1 && rID1?.trim() != '') rIDs = 'CAST(' + rID1 + ' AS numeric)'
else if (rID2 && rID2?.trim() != '') rIDs = 'CAST(' + rID2 + ' AS numeric)'

def subsetLen = (rID1 && rID2) ? 2 : (rID1 || rID2) ? 1 : 0
log.debug('rID1 :: ' + rID1 + ' :: rID2 :: ' + rID2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class PostgresGeneExpressionDataService {
ssm.GPL_ID
FROM
de_subject_sample_mapping ssm
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = ? AND ssm.patient_id = sc.patient_num
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = CAST(? AS numeric) AND ssm.patient_id = sc.patient_num
""");
sQuery.append(" WHERE ssm.trial_name = '").append(study).append("' ")
Expand Down Expand Up @@ -184,7 +184,7 @@ class PostgresGeneExpressionDataService {
FROM de_subject_microarray_data a
INNER JOIN de_mrna_annotation b ON a.probeset_id = b.probeset_id
INNER JOIN de_subject_sample_mapping ssm ON ssm.assay_id = A.assay_id
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = ? AND ssm.PATIENT_ID = sc.patient_num
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = CAST(? AS numeric) AND ssm.PATIENT_ID = sc.patient_num
INNER JOIN PATIENT_DIMENSION pd on ssm.patient_id = pd.patient_num
""")

Expand Down Expand Up @@ -302,7 +302,7 @@ class PostgresGeneExpressionDataService {
assayS.append(""" SELECT DISTINCT s.assay_id
FROM de_subject_sample_mapping s,
qt_patient_set_collection qt
WHERE qt.patient_num = s.patient_id AND qt.result_instance_id = ? """);
WHERE qt.patient_num = s.patient_id AND qt.result_instance_id = CAST(? AS numeric) """);


//If we have a sample type, append it to the query.
Expand Down Expand Up @@ -879,11 +879,11 @@ class PostgresGeneExpressionDataService {
SELECT DISTINCT ssm.patient_id FROM de_subject_sample_mapping ssm
INNER JOIN (SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?
WHERE result_instance_id = CAST(? AS numeric)
INTERSECT
SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?) sc ON ssm.patient_id = sc.patient_num
WHERE result_instance_id = CAST(? AS numeric)) sc ON ssm.patient_id = sc.patient_num
"""
groovy.sql.Sql sql = new groovy.sql.Sql(dataSource)
def queryParams = []
Expand Down Expand Up @@ -1056,7 +1056,7 @@ class PostgresGeneExpressionDataService {
def str = new StringBuffer()
def mapValues = resultInstanceIdMap.values()
mapValues.each { val ->
if (val && ((String)val)?.trim() != '') str.append(val).append(',')
if (val && ((String)val)?.trim() != '') str.append('CAST(').append(val).append(' AS numeric),')
}
str.delete(str.length()-1, str.length())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PostgresSnpDataService {
WHERE platform = 'SNP' and patient_id in (
SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?)
WHERE result_instance_id = CAST(? AS numeric))
"""
def patientDataMap = [:]
sql.eachRow(query, [resultInstanceId]) { row ->
Expand Down Expand Up @@ -194,7 +194,7 @@ class PostgresSnpDataService {
INNER JOIN de_subject_sample_mapping dssm on ssd.patient_num=dssm.omic_patient_id
WHERE dssm.patient_id IN (SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?)"""
WHERE result_instance_id = CAST(? AS numeric))"""

def firstRow = sql.firstRow(platformQuery, [resultInstanceId])
def platformName = firstRow.title
Expand Down Expand Up @@ -419,7 +419,7 @@ class PostgresSnpDataService {
FROM bio_content b
WHERE b.study_name in ${studies}
AND b.file_name IN (SELECT DISTINCT sg.gsm_num FROM de_snp_calls_by_gsm sg WHERE sg.patient_num IN (
SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?
SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)
AND patient_num IN (SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%')))
"""

Expand Down Expand Up @@ -473,7 +473,7 @@ class PostgresSnpDataService {
//This from statement needs to be in all selects.
sTables.append(""" FROM DE_SUBJECT_SAMPLE_MAPPING DSM
INNER JOIN patient_dimension PD ON DSM.patient_id = PD.patient_num
INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = ? AND qt.PATIENT_NUM = DSM.PATIENT_ID
INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = CAST(? AS numeric) AND qt.PATIENT_NUM = DSM.PATIENT_ID
LEFT JOIN DE_SNP_CALLS_BY_GSM SNP_GENO ON DSM.OMIC_PATIENT_ID = SNP_GENO.PATIENT_NUM AND DSM.SAMPLE_CD = SNP_GENO.GSM_NUM
LEFT JOIN DE_SNP_COPY_NUMBER SNP_COPY ON DSM.OMIC_PATIENT_ID = SNP_COPY.PATIENT_NUM AND SNP_GENO.snp_name = SNP_COPY.snp_name
INNER JOIN DE_SNP_GENE_MAP D2 ON D2.SNP_NAME = SNP_GENO.SNP_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SnpDataService {
WHERE platform = 'SNP' and patient_id in (
SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?)
WHERE result_instance_id = CAST(? AS numeric))
"""
def patientDataMap = [:]
sql.eachRow(query, [resultInstanceId]) { row ->
Expand Down Expand Up @@ -194,7 +194,7 @@ class SnpDataService {
INNER JOIN de_subject_sample_mapping dssm on ssd.patient_num=dssm.omic_patient_id
WHERE dssm.patient_id IN (SELECT DISTINCT patient_num
FROM qt_patient_set_collection
WHERE result_instance_id = ?)"""
WHERE result_instance_id = CAST(? AS numeric))"""

def firstRow = sql.firstRow(platformQuery, [resultInstanceId])
def platformName = firstRow.title
Expand Down Expand Up @@ -419,7 +419,7 @@ class SnpDataService {
FROM bio_content b
WHERE b.study_name in ${studies}
AND b.file_name IN (SELECT DISTINCT sg.gsm_num FROM de_snp_calls_by_gsm sg WHERE sg.patient_num IN (
SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?
SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)
AND patient_num IN (SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%')))
"""

Expand Down Expand Up @@ -473,7 +473,7 @@ class SnpDataService {
//This from statement needs to be in all selects.
sTables.append(""" FROM DE_SUBJECT_SAMPLE_MAPPING DSM
INNER JOIN patient_dimension PD ON DSM.patient_id = PD.patient_num
INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = ? AND qt.PATIENT_NUM = DSM.PATIENT_ID
INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = CAST(? AS numeric) AND qt.PATIENT_NUM = DSM.PATIENT_ID
INNER JOIN DE_SAMPLE_SNP_DATA SNP ON DSM.SAMPLE_CD = SNP.SAMPLE_ID
INNER JOIN DE_SNP_GENE_MAP D2 ON D2.SNP_NAME = SNP.SNP_NAME
INNER JOIN bio_marker bm ON bm.PRIMARY_EXTERNAL_ID = to_char(D2.ENTREZ_GENE_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ class VcfDataService {
""";
def param = []
if(resultInstanceId1!=null){
param.add(resultInstanceId1)
param.add('CAST(' + resultInstanceId1 + '? AS numeric)')
}
if(resultInstanceId2!=null){
param.add(resultInstanceId2)
param.add('CAST(' + resultInstanceId2 + '? AS numeric)')
}

groovy.sql.Sql sql = new groovy.sql.Sql(dataSource);
Expand All @@ -399,7 +399,7 @@ class VcfDataService {
def q =
""" SELECT distinct a.DATASET_ID, a.SUBJECT_ID, a.POSITION from DE_VARIANT_SUBJECT_IDX a
INNER JOIN de_subject_sample_mapping b on a.SUBJECT_ID = b.SUBJECT_ID
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id in (?) AND b.patient_id = sc.patient_num
INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id in (CAST(? AS numeric)) AND b.patient_id = sc.patient_num
ORDER BY a.POSITION"""
groovy.sql.Sql sql = new groovy.sql.Sql(dataSource);
def datasetIdxMap =[:]
Expand Down
4 changes: 2 additions & 2 deletions src/groovy/com/recomdata/gex/GexDao.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class GexDao {
INNER JOIN search_keyword sk ON sk.bio_data_id = sbm.bio_marker_id
INNER JOIN de_subject_sample_mapping ssm ON (ssm.trial_name = A.trial_name AND ssm.assay_id = A.assay_id)
INNER JOIN (SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd
WHERE sc.result_instance_id = ? AND pd.sourcesystem_cd NOT LIKE '%:S:%'
WHERE sc.result_instance_id = CAST(? AS numeric) AND pd.sourcesystem_cd NOT LIKE '%:S:%'
AND sc.patient_num = pd.patient_num) sub ON ssm.patient_id = sub.patient_num
""");
//TODO replace study within query as parameter to query
Expand Down Expand Up @@ -190,7 +190,7 @@ public class GexDao {
//SQL Query string.
StringBuilder assayS = new StringBuilder("select distinct s.assay_id from de_subject_sample_mapping s");
assayS.append(", (SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd")
.append(" WHERE sc.result_instance_id = ? AND pd.sourcesystem_cd NOT LIKE '%:S:%'")
.append(" WHERE sc.result_instance_id = CAST(? AS numeric) AND pd.sourcesystem_cd NOT LIKE '%:S:%'")
.append(" AND sc.patient_num = pd.patient_num) A where s.patient_id = A.patient_num");

//If we have a sample type, append it to the query.
Expand Down
Loading

0 comments on commit 4053733

Please sign in to comment.