Example #1
0
        /// <summary>
        /// Temporary Data Dumping Point
        /// Will be removed when GUI is developed
        /// </summary>
        /// <param name="input"></param>
        public static void DataDump(IqTarget input, Run Run)
        {
            //Temporary Data Dumping Point
            //Data Dump also in TopDownIqTesting and ChromCorrelationData
            var target = input as ChromPeakIqTarget;
            var status = "UNK";
            var result = target.GetResult();
            var parent = result.Target.ParentTarget as IqChargeStateTarget;

            if (parent.ObservedScan != -1)
            {
                if (((target.ChromPeak.XValue - target.ChromPeak.Width / 2) <= parent.ObservedScan) &&
                    ((target.ChromPeak.XValue + target.ChromPeak.Width / 2) >= parent.ObservedScan))
                {
                    status = "T-POS";
                }
                else
                {
                    status = "T-NEG";
                }
            }


            using (var sipper = File.AppendText(Outfile))
            {
                sipper.WriteLine(target.ID + "\t" + parent.AlternateID + "\t" + target.ChargeState + "\t" + target.Code + "\t" + target.EmpiricalFormula + "\t" +
                                 target.MZTheor.ToString("0.0000") + "\t" + target.MonoMassTheor + "\t" +
                                 Run.NetAlignmentInfo.GetScanForNet(target.ElutionTimeTheor) +
                                 "\t" + parent.ObservedScan + "\t" + target.ChromPeak.XValue.ToString("0.00") + "\t" +
                                 result.NETError.ToString("0.0000") + "\t" + result.MassErrorBefore.ToString("0.0000") + "\t" +
                                 result.FitScore.ToString("0.0000") + "\t" + result.CorrelationData.RSquaredValsMedian + "\t" +
                                 result.CorrelationData.RSquaredValsAverage + "\t" + result.CorrelationData.RSquaredValsStDev + "\t" +
                                 result.CorrelationData.ToStringWithDetails() + "\t" + target.GetResult().Abundance + "\t" + result.IsIsotopicProfileFlagged + "\t" +
                                 status);
            }
        }
        public List <ChromPeakQualityData> GetChromPeakQualityData(Run run, IqTarget target, List <Peak> chromPeakList)
        {
            var peakQualityList = new List <ChromPeakQualityData>();


            if (MSGenerator == null)
            {
                MSGenerator = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);
                MSGenerator.IsTICRequested = false;
            }

            //iterate over peaks within tolerance and score each peak according to MSFeature quality
#if DEBUG
            var tempMinScanWithinTol = (int)run.NetAlignmentInfo.GetScanForNet(target.ElutionTimeTheor - Parameters.ChromNETTolerance);
            var tempMaxScanWithinTol = (int)run.NetAlignmentInfo.GetScanForNet(target.ElutionTimeTheor + Parameters.ChromNETTolerance);
            var tempCenterTol        = (int)run.NetAlignmentInfo.GetScanForNet(target.ElutionTimeTheor);


            Console.WriteLine("SmartPeakSelector --> NETTolerance= " + Parameters.ChromNETTolerance + ";  chromMinCenterMax= " +
                              tempMinScanWithinTol + "\t" + tempCenterTol + "" +
                              "\t" + tempMaxScanWithinTol);
            Console.WriteLine("MT= " + target.ID + ";z= " + target.ChargeState + "; mz= " + target.MZTheor.ToString("0.000") +
                              ";  ------------------------- PeaksWithinTol = " + chromPeakList.Count);
#endif



            //target.NumChromPeaksWithinTolerance = peaksWithinTol.Count;


            foreach (ChromPeak chromPeak in chromPeakList)
            {
                // TODO: Currently hard-coded to sum only 1 scan
                var lcscanset = _chromPeakUtilities.GetLCScanSetForChromPeak(chromPeak, run, 1);

                //generate a mass spectrum
                var massSpectrumXYData = MSGenerator.GenerateMS(run, lcscanset);

                //find isotopic profile
                var mspeakList  = new List <Peak>();
                var observedIso = TargetedMSFeatureFinder.IterativelyFindMSFeature(massSpectrumXYData, target.TheorIsotopicProfile, out mspeakList);

                double fitScore = 1;

                double iscore = 1;

                //get fit score
                fitScore = FitScoreCalc.CalculateFitScore(target.TheorIsotopicProfile, observedIso, massSpectrumXYData);

                //get i_score
                iscore = InterferenceScorer.GetInterferenceScore(target.TheorIsotopicProfile, mspeakList);

                var leftOfMonoPeakLooker = new LeftOfMonoPeakLooker();
                var peakToTheLeft        = leftOfMonoPeakLooker.LookforPeakToTheLeftOfMonoPeak(target.TheorIsotopicProfile.getMonoPeak(), target.ChargeState,
                                                                                               mspeakList);


                var hasPeakTotheLeft = peakToTheLeft != null;

                //collect the results together


                var pq = new ChromPeakQualityData(chromPeak);

                if (observedIso == null)
                {
                    pq.IsotopicProfileFound = false;
                }
                else
                {
                    pq.IsotopicProfileFound     = true;
                    pq.Abundance                = observedIso.IntensityMostAbundant;
                    pq.FitScore                 = fitScore;
                    pq.InterferenceScore        = iscore;
                    pq.IsotopicProfile          = observedIso;
                    pq.IsIsotopicProfileFlagged = hasPeakTotheLeft;
                    pq.ScanLc = lcscanset.PrimaryScanNumber;
                }

                peakQualityList.Add(pq);
#if DEBUG
                pq.Display();
#endif
            }

            return(peakQualityList);
        }
Example #3
0
        public override List <IqTarget> Import()
        {
            var allTargets = new List <IqTarget>();

            StreamReader reader;

            if (!File.Exists(Filename))
            {
                throw new IOException("Cannot import. File does not exist.");
            }

            try
            {
                reader = new StreamReader(this.Filename);
            }
            catch (Exception)
            {
                throw new IOException("There was a problem importing from the file.");
            }

            //Sequence is the key and processed line is the value
            var parentTargetGroup = new Dictionary <string, List <List <string> > >();

            using (var sr = reader)
            {
                if (sr.Peek() == -1)
                {
                    sr.Close();
                    throw new InvalidDataException("There is no data in the file we are trying to read.");
                }

                var headerLine = sr.ReadLine();
                CreateHeaderLookupTable(headerLine);

                string line;
                var    lineCounter = 1; //used for tracking which line is being processed.

                //read and process each line of the file
                while (sr.Peek() > -1)
                {
                    line = sr.ReadLine();
                    var processedData = ProcessLine(line);

                    //ensure that processed line is the same size as the header line
                    if (processedData.Count != m_columnHeaders.Count)
                    {
                        throw new InvalidDataException("In File: " + Path.GetFileName(Filename) + "; Data in row # " + lineCounter.ToString() + " is NOT valid - \nThe number of columns does not match that of the header line");
                    }

                    //Implement EValueCutoff
                    var EValueCutoff = 1.0E-3;
                    if (ParseDoubleField(processedData, EValueHeader) < EValueCutoff)
                    {
                        if (!parentTargetGroup.ContainsKey(ParseStringField(processedData, PeptideHeader)))
                        {
                            parentTargetGroup.Add(ParseStringField(processedData, PeptideHeader), new List <List <string> >());
                        }
                        parentTargetGroup[ParseStringField(processedData, PeptideHeader)].Add(processedData);
                    }

                    lineCounter++;
                }
                sr.Close();
            }

            var target_id = 1;

            foreach (var keyValuePair in parentTargetGroup)
            {
                IqTarget target = CreateParentTarget(keyValuePair.Value);
                target.ID = target_id;
                allTargets.Add(target);
                target_id++;
            }
            return(allTargets);
        }
Example #4
0
 /// <summary>
 /// Copies the target parameter to a new IqTarget.
 /// </summary>
 /// <param name="target">target parameter</param>
 /// <param name="includeRecursion">whether or not to include the root, parent, and children in the clone</param>
 public IqTargetBasic(IqTarget target)
     : base(target)
 {
 }