SQL query in a module laurapas  2015-04-16 15:00
Status: Closed
 
Sure, here it is. It is for Skyline data in a Panorama folder. It's similar to the CPTAC example that is published here: https://daily.panoramaweb.org/labkey/project/MacCoss/vsharma/Webinar/Aug%2019%2C2014/begin.view.

SELECT
tci.TransitionId.PrecursorId.PeptideId.PeptideGroupId.Label AS Protein,
tci.TransitionId.PrecursorId.PeptideId.PeptideModifiedSequence AS PeptideModifiedSequence,
tci.TransitionId.PrecursorId.IsotopeLabelId.Name AS IsotopeLabel,
tci.TransitionId.PrecursorId.Charge AS PrecursorCharge,
tci.TransitionId.Charge AS ProductCharge,
tci.TransitionId.FragmentType + CAST(tci.TransitionId.FragmentOrdinal AS VARCHAR) AS FragmentIon,
tci.SampleFileId.ReplicateId.Name AS Replicate,
annot1.Value AS Concentration,
annot2.Value AS SampleGroup,
annot3.Value AS ISSpike,
tci.Area,
tci.Background,
(SELECT annot3.Value
   FROM precursorchrominfoannotation annot3
   WHERE annot3.PrecursorChrominfoId = tci.precursorChromInfoId
   AND annot3.Name = 'do not use') AS DoNotUse,
pepannot1.Value AS PeptideConcentrationIS,
pepannot2.Value AS PeptideConcentration,
annot4.Value AS MultiplicationFactor,
(SELECT
   MAX(CASE WHEN prec.IsotopeLabelId.Name = 'light' THEN CAST(prec.IsotopeLabelId.Standard AS INTEGER) END) as lightstd
   FROM precursor prec
   WHERE tci.TransitionId.PrecursorId.PeptideId.PeptideGroupId.Label = prec.PeptideId.PeptideGroupId.Label
              AND
              tci.TransitionId.PrecursorId.PeptideId.PeptideModifiedSequence = prec.PeptideId.PeptideModifiedSequence
   GROUP BY prec.PeptideId.PeptideGroupId.Label, prec.PeptideId.PeptideModifiedSequence) as lightstd,
(SELECT
   MAX(CASE WHEN prec.IsotopeLabelId.Name = 'heavy' THEN CAST(prec.IsotopeLabelId.Standard AS INTEGER) END) as heavystd
   FROM precursor prec
   WHERE tci.TransitionId.PrecursorId.PeptideId.PeptideGroupId.Label = prec.PeptideId.PeptideGroupId.Label
              AND
              tci.TransitionId.PrecursorId.PeptideId.PeptideModifiedSequence = prec.PeptideId.PeptideModifiedSequence
   GROUP BY prec.PeptideId.PeptideGroupId.Label, prec.PeptideId.PeptideModifiedSequence) as heavystd
FROM transitionchrominfo tci
LEFT JOIN replicateannotation annot1 ON (tci.SampleFileId.ReplicateId = annot1.replicateid AND annot1.Name='Concentration')
LEFT JOIN replicateannotation annot2 ON (tci.SampleFileId.ReplicateId = annot2.replicateid AND annot2.Name='SampleGroup')
LEFT JOIN replicateannotation annot3 ON (tci.SampleFileId.ReplicateId = annot3.replicateid AND annot3.Name='IS Spike')
LEFT JOIN replicateannotation annot4 ON (tci.SampleFileId.ReplicateId = annot4.replicateid AND annot4.Name='Multiplication factor')
LEFT JOIN peptideannotation pepannot1 ON (tci.TransitionId.PrecursorId.PeptideId = pepannot1.PeptideId AND pepannot1.Name='Peptide Concentration IS')
LEFT JOIN peptideannotation pepannot2 ON (tci.TransitionId.PrecursorId.PeptideId = pepannot2.PeptideId AND pepannot2.Name='Peptide Concentration')