Example #1
0
 public static void FilterBySequence(string[] rawFiles, string decoyPrefix, double totalPeptideFPR,
                                     double specificPeptideFPR, MascotQueryType type, bool perFileThreshold, bool debug,
                                     HashSet <string> sequences, bool onlyCollectSequences, IIdentificationProvider ip)
 {
     for (int i = 0; i < rawFiles.Length; i++)
     {
         FilterBySequence(ip.GetIdentifications(rawFiles[i], type), sequences);
         ip.Dispose();
     }
 }
Example #2
0
        public static void FdrThresholding(string[] rawFiles, string decoyPrefix, double peptideFdr, double peptidePep,
                                           MascotQueryType type, bool perFileThreshold, bool debug, HashSet <string> sequences,
                                           bool onlyCollectSequences, IProteinSet proteinSet,
                                           HashSet <string> labelModificationSet, IIdentificationProvider ip)
        {
            CalcFdr(rawFiles, decoyPrefix, type, proteinSet, debug, labelModificationSet, ip);
            double pepThreshVal;

            double[] pepThreshVals = new double[rawFiles.Length];
            if (peptideFdr < 1)
            {
                for (int i = 0; i < rawFiles.Length; i++)
                {
                    pepThreshVals[i] = FindReverseHitThresholdValue(ip.GetIdentifications(rawFiles[i], type), peptideFdr,
                                                                    decoyPrefix, proteinSet);
                    ip.Dispose();
                    if (peptidePep < 1)
                    {
                        pepThreshVals[i] = Math.Min(pepThreshVals[i], peptidePep);
                    }
                }
                pepThreshVal = ArrayUtil.Median(pepThreshVals);
                if (peptidePep < 1)
                {
                    pepThreshVal = Math.Min(pepThreshVal, peptidePep);
                }
            }
            else
            {
                for (int i = 0; i < rawFiles.Length; i++)
                {
                    pepThreshVals[i] = peptidePep;
                }
                pepThreshVal = peptidePep;
            }
            if (onlyCollectSequences)
            {
                for (int i = 0; i < rawFiles.Length; i++)
                {
                    CollectSequences(ip.GetIdentifications(rawFiles[i], type),
                                     perFileThreshold ? pepThreshVals[i] : pepThreshVal, sequences);
                    ip.Dispose();
                }
            }
            else
            {
                for (int i = 0; i < rawFiles.Length; i++)
                {
                    ApplyReverseHitThreshold(ip.GetIdentifications(rawFiles[i], type),
                                             perFileThreshold ? pepThreshVals[i] : pepThreshVal);
                    ip.Dispose();
                }
            }
        }
Example #3
0
 public MascotQuery(int scanNum, string rawFile, MascotQueryType queryType, string[] fixedMods)
 {
     this.scanNum   = scanNum;
     this.rawFile   = rawFile;
     this.queryType = queryType;
     this.fixedMods = new ushort[fixedMods.Length];
     for (int i = 0; i < fixedMods.Length; i++)
     {
         this.fixedMods[i] = Tables.modifications[fixedMods[i]].Index;
     }
 }
Example #4
0
 private static void LimitPep(string[] rawFiles, MascotQueryType type, IIdentificationProvider ip)
 {
     for (int i = 0; i < rawFiles.Length; i++)
     {
         Identifications ident = ip.GetIdentifications(rawFiles[i], type);
         int             n     = ident.Count;
         for (int j = 0; j < n; j++)
         {
             MascotPeptide p = ident.GetPeptidesAt(j)[0];
             p.Pep = Math.Min(p.Pep, 1);
         }
         ident.Write();
         ip.Dispose();
     }
 }
Example #5
0
        private static void CalcFdr(string[] rawFiles, string decoyPrefix, MascotQueryType type, IProteinSet proteinSet, bool debug,
                                    IIdentificationProvider ip)
        {
            List <bool>   correct = new List <bool>();
            List <double> scores  = new List <double>();
            List <double> seqLen  = new List <double>();

            for (int i = 0; i < rawFiles.Length; i++)
            {
                Identifications ident = ip.GetIdentifications(rawFiles[i], type);
                int             n     = ident.Count;
                for (int j = 0; j < n; j++)
                {
                    bool   c = ident.IsHighestScoringCorrect(j, decoyPrefix, proteinSet);
                    double s = ident.GetHighestAltScore(j);
                    double l = Math.Log(ident.GetBestSequence(j).Length);
                    if (!double.IsNaN(s) && !double.IsInfinity(s))
                    {
                        correct.Add(c);
                        scores.Add(s);
                        seqLen.Add(l);
                    }
                }
                ip.Dispose();
                if (correct.Count > 10000000)
                {
                    break;
                }
            }
            if (correct.Count == 0)
            {
                return;
            }
            bool write             = debug && (type == MascotQueryType.Silac);
            BayesianInversion2D bi = new BayesianInversion2D(scores.ToArray(), seqLen.ToArray(), correct.ToArray(), write);

            if (write)
            {
                Write(rawFiles, bi);
            }
            for (int i = 0; i < rawFiles.Length; i++)
            {
                SetPep(ip.GetIdentifications(rawFiles[i], type), bi);
                ip.Dispose();
            }
        }
Example #6
0
        public void Read()
        {
            if (!File.Exists(filePath))
            {
                return;
            }
            using (BinaryReader reader = FileUtil.GetBinaryReader(filePath)) {
                int len = reader.ReadInt32();
                scanNumbers        = new int[len];
                peptides           = new MascotPeptide[len][];
                fixedModifications = new ushort[len][];
                for (int i = 0; i < scanNumbers.Length; i++)
                {
                    scanNumbers[i] = reader.ReadInt32();
                    int l = reader.ReadInt32();
                    peptides[i] = new MascotPeptide[l];
                    for (int j = 0; j < peptides[i].Length; j++)
                    {
                        peptides[i][j] = new MascotPeptide(reader);
                    }
                    l = reader.ReadInt32();
                    fixedModifications[i] = new ushort[l];
                    for (int j = 0; j < fixedModifications[i].Length; j++)
                    {
                        fixedModifications[i][j] = reader.ReadUInt16();
                    }
                }
                byte x = reader.ReadByte();
                switch (x)
                {
                case 0:
                    type = MascotQueryType.Silac;
                    break;

                case 1:
                    type = MascotQueryType.Isotope;
                    break;

                case 2:
                    type = MascotQueryType.Peak;
                    break;
                }
                reader.Close();
            }
        }
Example #7
0
        public Identifications(MascotQuery[] queries, string filePath, MascotQueryType type)
        {
            this.filePath      = filePath;
            this.type          = type;
            scanNumbers        = new int[queries.Length];
            peptides           = new MascotPeptide[queries.Length][];
            fixedModifications = new ushort[queries.Length][];
            for (int i = 0; i < scanNumbers.Length; i++)
            {
                scanNumbers[i] = queries[i].ScanNum;
            }
            int[] o = ArrayUtil.Order(scanNumbers);
            scanNumbers = ArrayUtil.SubArray(scanNumbers, o);
            queries     = ArrayUtil.SubArray(queries, o);
            for (int i = 0; i < queries.Length; i++)
            {
                peptides[i]           = queries[i].GetPeptides();
                fixedModifications[i] = queries[i].FixedMods;
                double[] scores = new double[peptides[i].Length];
                for (int j = 0; j < scores.Length; j++)
                {
                    scores[j] = -peptides[i][j].MascotScore;
                }
                int[] o1 = ArrayUtil.Order(scores);
                peptides[i] = ArrayUtil.SubArray(peptides[i], o1);
            }
            List <int> valids = new List <int>();

            for (int i = 0; i < scanNumbers.Length; i++)
            {
                if (peptides[i].Length > 0)
                {
                    valids.Add(i);
                }
            }
            int[] oo = valids.ToArray();
            scanNumbers        = ArrayUtil.SubArray(scanNumbers, oo);
            peptides           = ArrayUtil.SubArray(peptides, oo);
            fixedModifications = ArrayUtil.SubArray(fixedModifications, oo);
        }
Example #8
0
        public MsmsHit(MascotPeptide[] peptides, int scanNumber, int fileIndex, MascotQueryType type,
                       int silacIndex, double elutionTime, double mz, double monoisotopicMz, ushort[] fixedMods,
                       HashSet <string> labelModificationSet, SilacType silacType, SilacLabel[] labels1, SilacLabel[] labels2)
        {
            rawFileIndex    = fileIndex;
            this.scanNumber = scanNumber;
            this.silacIndex = silacIndex;
            this.type       = type;
            pep             = peptides[0].Pep;
            score           = peptides[0].MascotScore;
            altScore        = peptides[0].AltScore;
            charge          = (int)Math.Round(peptides[0].Mass / mz);
            massErrorPpm    = peptides[0].MassErrorPpm;
            if (peptides.Length > 1)
            {
                deltaScoreAll = peptides[0].MascotScore - peptides[1].MascotScore;
            }
            else
            {
                deltaScoreAll = peptides[0].MascotScore;
            }
            int ind = -1;

            for (int i = 1; i < peptides.Length; i++)
            {
                if (!peptides[i].Sequence.Equals(peptides[0].Sequence))
                {
                    ind = i;
                    break;
                }
            }
            if (ind != -1)
            {
                deltaScoreDifferentPep = peptides[0].MascotScore - peptides[ind].MascotScore;
            }
            else
            {
                deltaScoreDifferentPep = peptides[0].MascotScore;
            }
            labelModifications =
                peptides[0].Modifications.GetLabelModifications(fixedMods, peptides[0].Sequence, labelModificationSet);
            trueModifications   = peptides[0].Modifications.GetTrueModifications(labelModificationSet);
            this.elutionTime    = elutionTime;
            this.mz             = mz;
            this.monoisotopicMz = monoisotopicMz;
            if (silacType == SilacType.Singlets)
            {
                this.silacIndex = 0;
            }
            else if (type != MascotQueryType.Silac)
            {
                AminoAcid[] allAas     = T07SearchEngineEnhancement.CalcAllAas(silacType, labels1, labels2);
                char[]      allAaLetts = AminoAcid.GetSingleLetters(allAas);
                for (int i = 0; i < allAaLetts.Length; i++)
                {
                    this.silacIndex =
                        CalcSilacIndex(allAaLetts[i], labelModifications, peptides[0].Sequence, silacType, labels1,
                                       labels2);
                    if (this.silacIndex != -1)
                    {
                        break;
                    }
                }
            }
        }
Example #9
0
        public MsmsHit(BinaryReader reader)
        {
            rawFileIndex = reader.ReadInt32();
            scanNumber   = reader.ReadInt32();
            silacIndex   = reader.ReadInt32();
            byte x = reader.ReadByte();

            switch (x)
            {
            case 0:
                type = MascotQueryType.Silac;
                break;

            case 1:
                type = MascotQueryType.Isotope;
                break;

            case 2:
                type = MascotQueryType.Peak;
                break;
            }
            pep                    = reader.ReadDouble();
            score                  = reader.ReadDouble();
            altScore               = reader.ReadDouble();
            deltaScoreAll          = reader.ReadDouble();
            deltaScoreDifferentPep = reader.ReadDouble();
            labelModifications     = PeptideModificationState.Read(reader);
            trueModifications      = PeptideModificationState.Read(reader);
            elutionTime            = reader.ReadDouble();
            id               = reader.ReadInt32();
            mz               = reader.ReadDouble();
            monoisotopicMz   = reader.ReadDouble();
            evidenceId       = reader.ReadInt32();
            ptmScore         = reader.ReadDouble();
            deltaPtmScore    = reader.ReadDouble();
            ptmScoreCounts   = reader.ReadInt32();
            ptmScoreFinished = reader.ReadBoolean();
            massErrorPpm     = reader.ReadDouble();
            changed          = reader.ReadBoolean();
            int len = reader.ReadInt32();

            description = new MsmsPeakAnnotation[len];
            intensities = new float[len];
            massDiffs   = new float[len];
            for (int i = 0; i < len; i++)
            {
                description[i] = new MsmsPeakAnnotation(reader);
                intensities[i] = reader.ReadSingle();
                massDiffs[i]   = reader.ReadSingle();
            }
            charge           = reader.ReadInt32();
            modProbabilities = new Dictionary <ushort, double[]>();
            len = reader.ReadInt32();
            ushort[] keys = new ushort[len];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = reader.ReadUInt16();
            }
            foreach (ushort key in keys)
            {
                len = reader.ReadInt32();
                double[] value = new double[len];
                for (int i = 0; i < value.Length; i++)
                {
                    value[i] = reader.ReadDouble();
                }
                modProbabilities.Add(key, value);
            }
            modScoreDiffs = new Dictionary <ushort, double[]>();
            len           = reader.ReadInt32();
            keys          = new ushort[len];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = reader.ReadUInt16();
            }
            foreach (ushort key in keys)
            {
                len = reader.ReadInt32();
                double[] value = new double[len];
                for (int i = 0; i < value.Length; i++)
                {
                    value[i] = reader.ReadDouble();
                }
                modScoreDiffs.Add(key, value);
            }
        }
Example #10
0
 public static void CalcFdr(string[] rawFiles, string decoyPrefix, MascotQueryType type, IProteinSet proteinSet, bool debug,
                            HashSet <string> labelModificationSet, IIdentificationProvider ip)
 {
     CalcFdr(rawFiles, decoyPrefix, type, proteinSet, debug, ip);
 }