alexander-r
7/27/2017 - 2:01 PM

Data block SQLs (analysis results in MRC2LIMS)

Data block SQLs (analysis results in MRC2LIMS)

--	Get samples for data block
SELECT DISTINCT T.SAMPLE_ID
FROM ANALYSIS_RESULT T
WHERE T.DATA_BLOCK_ID = 79
ORDER BY 1

--	Get compounds for data block
SELECT DISTINCT T.COMPOUND_ID, N.NAME
FROM ANALYSIS_RESULT T,
COMPOUND_NAME N
WHERE T.DATA_BLOCK_ID = 79
AND T.COMPOUND_ID = N.PUBCHEM_CID
AND N.TYPE = 'PRI'
--AND T.COMPOUND_ID  IN ('1055','612','444972')
ORDER BY 1

--	Move compounds between blocks
UPDATE  ANALYSIS_RESULT T
SET T.DATA_BLOCK_ID = 170
WHERE T.DATA_BLOCK_ID IN (648)
AND T.COMPOUND_ID IN (444972, 612, 1055)


--	Get last data block ID
SELECT MAX(T.DATA_BLOCK_ID) AS NEXTID
FROM DATA_BLOCK T

--	Data blocks for experiment
SELECT * FROM DATA_BLOCK T
WHERE T.EXPERIMENT_ID = 'EX00374'
FOR UPDATE

--	Update data blocks
SELECT * FROM DATA_BLOCK T
WHERE T.ACQ_METHOD_ID IS NULL
ORDER BY T.EXPERIMENT_ID, T.ASSAY_ID
FOR UPDATE

--	Summary of compound numbers per block
SELECT B.EXPERIMENT_ID, B.ASSAY_ID, B.DATA_BLOCK_ID, 
COUNT(DISTINCT R.COMPOUND_ID) AS NUMCPD 
FROM ANALYSIS_RESULT R,
DATA_BLOCK B
WHERE R.DATA_BLOCK_ID = B.DATA_BLOCK_ID
AND B.ASSAY_ID IN('A011', 'A043')
GROUP BY B.EXPERIMENT_ID, B.ASSAY_ID, B.DATA_BLOCK_ID
ORDER BY B.EXPERIMENT_ID, B.ASSAY_ID, B.DATA_BLOCK_ID

--	Get acquisition method by name
SELECT * FROM DATA_ACQUISITION_METHOD T
--WHERE T.ACQ_METHOD_ID = 'DQM0481'
WHERE T.METHOD_NAME = 'QQQ-ATP,ADP,AMP,A-UPDATE-2015-09'
ORDER BY T.ACQ_METHOD_ID DESC
--FOR UPDATE

--	Known methods for assay
SELECT DISTINCT T.EXPERIMENT_ID, M.ACQ_METHOD_ID, 
M.METHOD_NAME, M.POLARITY, T.INSTRUMENT_ID
FROM EXPERIMENT_ASSAY_ACQMETHOD T,
DATA_ACQUISITION_METHOD M
WHERE T.ASSAY_ID = 'A011'
AND T.METHOD_ID = M.ACQ_METHOD_ID
ORDER BY T.EXPERIMENT_ID, M.METHOD_NAME