コード例 #1
0
        //method was originally written recursively, but large peptides result in stackoverflow exceptions
        public static void MassMatch(string B, string Y, NeoPsm psm, int BIndex, int YIndex) //this is the workhorse of SpliceFragments
        {
            double experimentalMass = psm.expMass;
            string bFrag            = IonCrop(B, experimentalMass, BIndex, ProductType.B, false); //returns a B ion sequence that has a mass smaller than the experimental mass by cleaving C term AA

            if (bFrag.Length < ionsUsedMassVer)                                                   //If the number of AA from the N-term peptide is less than desired amount, start over loop and remove a single aa from the C-term
            {
                return;
            }
            string yFrag = IonCrop(Y, experimentalMass, YIndex, ProductType.Y, false); //returns a Y ion sequence that has a mass smaller than the experimental mass by cleaving N term AA

            if (yFrag.Length < ionsUsedMassVer)                                        //If the number of AA from the C-term peptide is less than desired amount, end recursion.
            {
                return;
            }
            double theoreticalMass = NeoMassCalculator.MonoIsoptopicMass(bFrag) + NeoMassCalculator.MonoIsoptopicMass(yFrag) - NeoConstants.WATER_MONOISOTOPIC_MASS + fixedModMass; //water added once in b and once in y

            if (NeoMassCalculator.IdenticalMasses(experimentalMass, theoreticalMass, NeoFindAmbiguity.precursorMassTolerancePpm))                                                   //if match
            {
                string novelSeq = bFrag + yFrag;
                if (!psm.candidates.Any(x => x.seq.Equals(novelSeq))) //if fusion sequence was not previously assigned to this psm
                {
                    psm.candidates.Add(new FusionCandidate(novelSeq));
                }
            }
        }
コード例 #2
0
        public static List <NeoPsm> ImportNeoPsms(string nFileName, string cFileName)
        {
            string[]      nInput = File.ReadAllLines(nFileName);
            string[]      cInput = File.ReadAllLines(cFileName);
            List <NeoPsm> psms   = new List <NeoPsm>();

            ParseHeader(nInput[0]);

            List <InitialID> nAssignment = new List <InitialID>();
            List <InitialID> cAssignment = new List <InitialID>();

            for (int i = 1; i < nInput.Count(); i++)
            {
                string[]  line = nInput[i].Split('\t').ToArray();
                InitialID id   = new InitialID(Convert.ToInt32(line[scanNumberIndex]), Convert.ToDouble(line[scanPrecursorMassIndex]), line[accessionIndex], line[fullIndex], line[matchedIonsIndex], line[scoreIndex]);
                nAssignment.Add(id);
            }

            for (int i = 1; i < cInput.Count(); i++)
            {
                string[]  line = cInput[i].Split('\t').ToArray();
                InitialID id   = new InitialID(Convert.ToInt32(line[scanNumberIndex]), Convert.ToDouble(line[scanPrecursorMassIndex]), line[accessionIndex], line[fullIndex], line[matchedIonsIndex], line[scoreIndex]);
                cAssignment.Add(id);
            }
            //sort by scan number
            List <InitialID> nAssignmentSorted = nAssignment.OrderBy(o => o.scanNumber).ToList();
            List <InitialID> cAssignmentSorted = cAssignment.OrderBy(o => o.scanNumber).ToList();

            //remove scans not found in both files
            double maxCount = nAssignmentSorted.Count();

            for (int i = 0; i < maxCount; i++)
            {
                if (i < cAssignmentSorted.Count())
                {
                    if (nAssignmentSorted[i].scanNumber.Equals(cAssignmentSorted[i].scanNumber))
                    {
                        NeoPsm psm = new NeoPsm(nAssignmentSorted[i].scanNumber, nAssignmentSorted[i].expMass, nAssignmentSorted[i], cAssignmentSorted[i]);
                        psms.Add(psm);
                        continue;
                    }
                    else if (nAssignmentSorted[i].scanNumber < cAssignmentSorted[i].scanNumber) //no information was found for the b scan using y ions, so remove it
                    {
                        nAssignmentSorted.Remove(nAssignmentSorted[i]);
                        maxCount--;
                        i--;
                    }
                    else  //no information was found for the y scan using b ions, so remove it
                    {
                        cAssignmentSorted.Remove(cAssignmentSorted[i]);
                        i--;
                    }
                }
            }

            return(psms);
        }
コード例 #3
0
        public static void AutoFill(NeoPsm psm)
        {
            double experimentalMass = psm.expMass;

            for (int i = 0; i < 2; i++)
            {
                string      ionSequence;
                ProductType ion;
                if (i == 0)
                {
                    ionSequence = psm.nInfo.seq;
                    ion         = ProductType.B;
                }
                else
                {
                    ionSequence = psm.cInfo.seq;
                    ion         = ProductType.Y;
                }

                int    fragNumber = 0;
                string ionFrag    = ionSequence;
                while (ionFrag.Length > 1)
                {
                    if (ion == ProductType.B)
                    {
                        ionFrag = ionSequence.Substring(0, (ionSequence.Length - fragNumber));
                        if (ionFrag.Substring(ionSequence.Length - fragNumber - 1, 1) == "]") //if end of a PTM annotation
                        {
                            while (ionFrag.Substring(ionSequence.Length - fragNumber - 1, 1) != "[")
                            {
                                fragNumber++;
                                ionFrag = ionSequence.Substring(0, (ionSequence.Length - fragNumber));
                            }
                            fragNumber += 2; //removes "(" and the AA the PTM was attached to
                            ionFrag     = ionSequence.Substring(0, (ionSequence.Length - fragNumber));
                        }
                    }
                    else //Ion==Y
                    {
                        ionFrag = ionSequence.Substring((0 + fragNumber), (ionSequence.Length - fragNumber));
                        if (ionFrag.Substring(0, 1) == "[") //if start of a PTM annotation
                        {
                            while (ionFrag.Substring(0, 1) != "]")
                            {
                                fragNumber++;
                                ionFrag = ionSequence.Substring((0 + fragNumber), (ionSequence.Length - fragNumber));
                            }
                            fragNumber++; //removes ")"
                            ionFrag = ionSequence.Substring((0 + fragNumber), (ionSequence.Length - fragNumber));
                        }
                    }

                    double theoreticalMass = NeoMassCalculator.MonoIsoptopicMass(ionFrag) - NeoConstants.WATER_MONOISOTOPIC_MASS;
                    if (theoreticalMass < experimentalMass)
                    {
                        double        key          = experimentalMass - theoreticalMass;
                        List <string> combinations = new List <string>();

                        double closestPeak = double.NaN;
                        var    ipos        = Array.BinarySearch(NeoFindAmbiguity.keys, key);
                        if (ipos < 0)
                        {
                            ipos = ~ipos;
                        }

                        if (ipos > 0)
                        {
                            var downIpos = ipos - 1;
                            // Try down
                            while (downIpos >= 0)
                            {
                                closestPeak = NeoFindAmbiguity.keys[downIpos];
                                if (NeoMassCalculator.IdenticalMasses(experimentalMass, closestPeak + theoreticalMass, NeoFindAmbiguity.precursorMassTolerancePpm))
                                {
                                    foreach (string frag in NeoFindAmbiguity.massDict[closestPeak])
                                    {
                                        combinations.Add(frag);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                                downIpos--;
                            }
                        }
                        if (ipos < NeoFindAmbiguity.keys.Length)
                        {
                            var upIpos = ipos;
                            // Try here and up
                            while (upIpos < NeoFindAmbiguity.keys.Length)
                            {
                                closestPeak = NeoFindAmbiguity.keys[upIpos];
                                if (NeoMassCalculator.IdenticalMasses(experimentalMass, closestPeak + theoreticalMass, NeoFindAmbiguity.precursorMassTolerancePpm))
                                {
                                    foreach (string frag in NeoFindAmbiguity.massDict[closestPeak])
                                    {
                                        combinations.Add(frag);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                                upIpos++;
                            }
                        }
                        if (combinations.Count != 0)
                        {
                            foreach (string s in combinations)
                            {
                                if (ion == ProductType.B)
                                {
                                    psm.candidates.Add(new FusionCandidate(ionFrag + s));
                                }
                                else
                                {
                                    psm.candidates.Add(new FusionCandidate(s + ionFrag));
                                }
                            }
                            break;
                        }
                    }
                    fragNumber++;
                }
            }
        }