Esempio n. 1
0
        private double fragmentMass(pwiz.CLI.proteome.Fragmentation f, IonSeries series, int length, int charge)
        {
            switch (series)
            {
            case IonSeries.a: return(f.a(length, charge));

            case IonSeries.b: return(f.b(length, charge));

            case IonSeries.c: return(f.c(length, charge));

            case IonSeries.cMinus1: return(f.c(length, charge) - Proton.Mass / charge);

            case IonSeries.x: return(f.x(length, charge));

            case IonSeries.y: return(f.y(length, charge));

            case IonSeries.z: return(f.z(length, charge));

            case IonSeries.zPlus1: return(f.zRadical(length, charge));

            case IonSeries.zPlus2: return(f.zRadical(length, charge) + Proton.Mass / charge);

            default: throw new ArgumentException();
            }
        }
Esempio n. 2
0
 public PredictedIon(int charge, double mz, int number, string finalAA, IonSeries series)
 {
     Charge  = charge;
     MZ      = mz;
     Number  = number;
     FinalAA = finalAA;
     Series  = series;
 }
Esempio n. 3
0
        public override void Update (GraphItem item, pwiz.MSGraph.MSPointList points, GraphObjList annotations)
        {
            if (!Enabled)
                return;

            if (!(item is MassSpectrum))
                return; // throw exception?

            GraphObjList list = annotations;
            Peptide peptide;

            try
            {
                peptide = new Peptide(sequence,
                    pwiz.CLI.proteome.ModificationParsing.ModificationParsing_Auto,
                    pwiz.CLI.proteome.ModificationDelimiter.ModificationDelimiter_Brackets);
            }
            catch (Exception)
            {
                return;
            }

            var spectrum = (item as MassSpectrum).Element;

            if (ReferenceEquals(manualTolerance, null))
            {
                MZTolerance maxTolerance = new MZTolerance(0.5);
                foreach (var scan in spectrum.scanList.scans.Where(o => o.instrumentConfiguration != null))
                {
                    // assume the last analyzer of the instrument configuration is responsible for the resolution
                    if (scan.instrumentConfiguration.componentList.Count == 0)
                        continue;
                    var analyzer = scan.instrumentConfiguration.componentList.Where(o => o.type == ComponentType.ComponentType_Analyzer).Last().cvParamChild(CVID.MS_mass_analyzer_type);
                    if (analyzer.cvid == CVID.CVID_Unknown)
                        continue;

                    MZTolerance analyzerTolerance = null;
                    foreach (var kvp in mzToleranceByAnalyzer)
                        if (CV.cvIsA(analyzer.cvid, kvp.Key))
                        {
                            analyzerTolerance = kvp.Value;
                            break;
                        }

                    if (analyzerTolerance == null)
                        continue;

                    if (maxTolerance.units == analyzerTolerance.units)
                    {
                        if (maxTolerance.value < analyzerTolerance.value)
                            maxTolerance = analyzerTolerance;
                    }
                    else if (analyzerTolerance.units == MZTolerance.Units.PPM)
                        maxTolerance = analyzerTolerance;
                }
                tolerance = maxTolerance;
            }
            else
                tolerance = manualTolerance;

            if (ionSeriesIsEnabled(IonSeries.Auto))
                foreach (var precursor in spectrum.precursors)
                    foreach (var method in precursor.activation.cvParamChildren(CVID.MS_dissociation_method))
                    {
                        if (!ionSeriesByDissociationMethod.Contains(method.cvid))
                            ionSeries = IonSeries.All;
                        else
                            ionSeries |= ionSeriesByDissociationMethod[method.cvid];
                    }

            int nSeries = (ionSeriesIsEnabled(IonSeries.a) ? 1 : 0) +
                          (ionSeriesIsEnabled(IonSeries.b) ? 1 : 0) +
                          (ionSeriesIsEnabled(IonSeries.c) ? 1 : 0);
            int cSeries = (ionSeriesIsEnabled(IonSeries.x) ? 1 : 0) +
                          (ionSeriesIsEnabled(IonSeries.y) ? 1 : 0) +
                          (ionSeriesIsEnabled(IonSeries.z) ? 1 : 0) +
                          (ionSeriesIsEnabled(IonSeries.zRadical) ? 1 : 0);

            showLadders = showLadders && nSeries < 2 && cSeries < 2;

            string unmodifiedSequence = peptide.sequence;
            int sequenceLength = unmodifiedSequence.Length;
            Fragmentation fragmentation = peptide.fragmentation(fragmentMassType == 0 ? true : false, true);

            for (int i = 1; i <= sequenceLength; ++i)
            {
                if (ionSeriesIsEnabled(IonSeries.Immonium))
                    addFragment(list, points, "immonium-" + unmodifiedSequence[i - 1], 0, 1, immoniumIonByResidue[unmodifiedSequence[i - 1]]);

                for (int charge = min; charge <= max; ++charge)
                {
                    if (ionSeriesIsEnabled(IonSeries.a)) addFragment(list, points, "a", i, charge, fragmentation.a(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.b)) addFragment(list, points, "b", i, charge, fragmentation.b(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.y)) addFragment(list, points, "y", i, charge, fragmentation.y(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.z)) addFragment(list, points, "z", i, charge, fragmentation.z(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.zRadical)) addFragment(list, points, "z*", i, charge, fragmentation.zRadical(i, charge));

                    if (i < sequenceLength)
                    {
                        if (ionSeriesIsEnabled(IonSeries.c)) addFragment(list, points, "c", i, charge, fragmentation.c(i, charge));
                        if (ionSeriesIsEnabled(IonSeries.x)) addFragment(list, points, "x", i, charge, fragmentation.x(i, charge));
                    }
                }
            }

            if (showLadders || showFragmentationSummary)
            {
                string topSeries = ionSeriesIsEnabled(IonSeries.a) ? "a" : ionSeriesIsEnabled(IonSeries.b) ? "b" : ionSeriesIsEnabled(IonSeries.c) ? "c" : "";
                string bottomSeries = ionSeriesIsEnabled(IonSeries.x) ? "x" : ionSeriesIsEnabled(IonSeries.y) ? "y" : ionSeriesIsEnabled(IonSeries.z) ? "z" : ionSeriesIsEnabled(IonSeries.zRadical) ? "z*" : "";
                if (showLadders)
                    addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                if (showFragmentationSummary)
                    addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
            }

            // fill peptide info table
            annotationPanels.peptideInfoGridView.Rows.Clear();

            if (spectrum.precursors.Count > 0 &&
                spectrum.precursors[0].selectedIons.Count > 0 &&
                spectrum.precursors[0].selectedIons[0].hasCVParam(CVID.MS_selected_ion_m_z) &&
                spectrum.precursors[0].selectedIons[0].hasCVParam(CVID.MS_charge_state))
            {
                double selectedMz = (double) spectrum.precursors[0].selectedIons[0].cvParam(CVID.MS_selected_ion_m_z).value;
                int chargeState = (int) spectrum.precursors[0].selectedIons[0].cvParam(CVID.MS_charge_state).value;
                double calculatedMass = (precursorMassType == 0 ? peptide.monoisotopicMass(chargeState) : peptide.molecularWeight(chargeState)) * chargeState;
                double observedMass = selectedMz * chargeState;
                annotationPanels.peptideInfoGridView.Rows.Add("Calculated mass:", calculatedMass, "Mass error (daltons):", observedMass - calculatedMass);
                annotationPanels.peptideInfoGridView.Rows.Add("Observed mass:", observedMass, "Mass error (ppm):", ((observedMass - calculatedMass) / calculatedMass) * 1e6);
            }
            else
                annotationPanels.peptideInfoGridView.Rows.Add("Calculated neutral mass:", precursorMassType == 0 ? peptide.monoisotopicMass() : peptide.molecularWeight());

            annotationPanels.peptideInfoGridView.Columns[1].DefaultCellStyle.Format = "F4";
            foreach (DataGridViewRow row in annotationPanels.peptideInfoGridView.Rows)
                row.Height = row.InheritedStyle.Font.Height + 2;

            // show/hide/update fragment table
            if (!annotationPanels.showFragmentationTableCheckBox.Checked || ionSeries <= IonSeries.Auto)
            {
                annotationPanels.fragmentInfoGridView.Visible = false;
                annotationPanels.fragmentInfoGridView.Rows.Clear();
                return;
            }

            annotationPanels.fragmentInfoGridView.Visible = true;
            annotationPanels.fragmentInfoGridView.SuspendLayout();

            if (annotationPanels.fragmentInfoGridView.Columns.Count == 0)
            {
                #region Add columns for fragment types
                if (ionSeriesIsEnabled(IonSeries.a))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "a" + charge.ToString(),
                            "a" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                if (ionSeriesIsEnabled(IonSeries.b))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "b" + charge.ToString(),
                            "b" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                if (ionSeriesIsEnabled(IonSeries.c))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "c" + charge.ToString(),
                            "c" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));

                annotationPanels.fragmentInfoGridView.Columns.Add("N", "");
                annotationPanels.fragmentInfoGridView.Columns.Add("Sequence", "");
                annotationPanels.fragmentInfoGridView.Columns.Add("C", "");

                if (ionSeriesIsEnabled(IonSeries.x))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "x" + charge.ToString(),
                            "x" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                if (ionSeriesIsEnabled(IonSeries.y))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "y" + charge.ToString(),
                            "y" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                if (ionSeriesIsEnabled(IonSeries.z))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "z" + charge.ToString(),
                            "z" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                if (ionSeriesIsEnabled(IonSeries.zRadical))
                    for (int charge = min; charge <= max; ++charge)
                        annotationPanels.fragmentInfoGridView.Columns.Add(
                            "z*" + charge.ToString(),
                            "z*" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                #endregion

                foreach (DataGridViewColumn column in annotationPanels.fragmentInfoGridView.Columns)
                {
                    column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    if (column.Name != "N" && column.Name != "C" && column.Name != "Sequence")
                        column.DefaultCellStyle.Format = "F3";
                }
            }

            while (annotationPanels.fragmentInfoGridView.Rows.Count > sequenceLength)
                annotationPanels.fragmentInfoGridView.Rows.RemoveAt(annotationPanels.fragmentInfoGridView.Rows.Count - 1);
            if (sequenceLength - annotationPanels.fragmentInfoGridView.Rows.Count > 0)
                annotationPanels.fragmentInfoGridView.Rows.Add(sequenceLength - annotationPanels.fragmentInfoGridView.Rows.Count);
            for (int i = 1; i <= sequenceLength; ++i)
            {
                int cTerminalLength = sequenceLength - i + 1;
                var row = annotationPanels.fragmentInfoGridView.Rows[i - 1];
                var values = new List<object>(10);
                //var row = annotationPanels.fragmentInfoGridView.Rows.Add()];

                if (ionSeriesIsEnabled(IonSeries.a))
                    for (int charge = min; charge <= max; ++charge)
                        values.Add(fragmentation.a(i, charge));
                if (ionSeriesIsEnabled(IonSeries.b))
                    for (int charge = min; charge <= max; ++charge)
                        values.Add(fragmentation.b(i, charge));
                if (ionSeriesIsEnabled(IonSeries.c))
                    for (int charge = min; charge <= max; ++charge)
                        if (i < sequenceLength)
                            values.Add(fragmentation.c(i, charge));
                        else
                            values.Add("");

                values.Add(i);
                values.Add(unmodifiedSequence[i - 1]);
                values.Add(cTerminalLength);

                if (ionSeriesIsEnabled(IonSeries.x))
                    for (int charge = min; charge <= max; ++charge)
                        if (i > 1)
                            values.Add(fragmentation.x(cTerminalLength, charge));
                        else
                            values.Add("");
                if (ionSeriesIsEnabled(IonSeries.y))
                    for (int charge = min; charge <= max; ++charge)
                        values.Add(fragmentation.y(cTerminalLength, charge));
                if (ionSeriesIsEnabled(IonSeries.z))
                    for (int charge = min; charge <= max; ++charge)
                        values.Add(fragmentation.z(cTerminalLength, charge));
                if (ionSeriesIsEnabled(IonSeries.zRadical))
                    for (int charge = min; charge <= max; ++charge)
                        values.Add(fragmentation.zRadical(cTerminalLength, charge));
                row.SetValues(values.ToArray());
            }

            foreach (DataGridViewRow row in annotationPanels.fragmentInfoGridView.Rows)
            {
                row.Height = row.InheritedStyle.Font.Height + 2;

                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (!(cell.Value is double))
                        continue;

                    double mz = (double) cell.Value;

                    if (findPointWithTolerance(points, mz, tolerance) > -1)
                        cell.Style.Font = new Font(annotationPanels.fragmentInfoGridView.Font, FontStyle.Bold);
                    else
                        cell.Style.Font = annotationPanels.fragmentInfoGridView.Font;
                }
            }

            annotationPanels.fragmentInfoGridView.ResumeLayout();
        }
Esempio n. 4
0
 bool ionSeriesIsEnabled (IonSeries series) { return (ionSeries & series) == series; }
Esempio n. 5
0
        void checkBox_CheckedChanged (object sender, EventArgs e)
        {
            if (panel.Tag != this)
                return;

            min = (int) annotationPanels.minChargeUpDown.Value;
            max = (int) annotationPanels.maxChargeUpDown.Value;

            precursorMassType = annotationPanels.precursorMassTypeComboBox.SelectedIndex;
            fragmentMassType = annotationPanels.fragmentMassTypeComboBox.SelectedIndex;

            showLadders = annotationPanels.showFragmentationLaddersCheckBox.Checked;
            showFragmentationSummary = annotationPanels.showFragmentationSummaryCheckBox.Checked;

            // any control which affects the columns displayed for fragments clears the column list;
            // it gets repopulated on the next call to Update()
            if (!ReferenceEquals(sender, annotationPanels.showMissesCheckBox))
                annotationPanels.fragmentInfoGridView.Columns.Clear();

            // when showLadders is checked, the ion series checkboxes act like radio buttons:
            // series from the same terminus are grouped together
            if ((showLadders || showFragmentationSummary) && sender is CheckBox)
            {
                panel.Tag = null;
                if (ReferenceEquals(sender, annotationPanels.showFragmentationLaddersCheckBox) ||
                    ReferenceEquals(sender, annotationPanels.showFragmentationSummaryCheckBox))
                {
                    // uncheck all but the first checked checkbox
                    annotationPanels.bCheckBox.Checked = !annotationPanels.aCheckBox.Checked;
                    annotationPanels.cCheckBox.Checked = !annotationPanels.aCheckBox.Checked && !annotationPanels.bCheckBox.Checked;
                    annotationPanels.yCheckBox.Checked = !annotationPanels.xCheckBox.Checked;
                    annotationPanels.zCheckBox.Checked = !annotationPanels.xCheckBox.Checked && !annotationPanels.yCheckBox.Checked;
                    annotationPanels.zRadicalCheckBox.Checked = !annotationPanels.xCheckBox.Checked && !annotationPanels.yCheckBox.Checked && !annotationPanels.zCheckBox.Checked;
                }
                else if (ReferenceEquals(sender, annotationPanels.aCheckBox))
                    annotationPanels.bCheckBox.Checked = annotationPanels.cCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.bCheckBox))
                    annotationPanels.aCheckBox.Checked = annotationPanels.cCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.cCheckBox))
                    annotationPanels.aCheckBox.Checked = annotationPanels.bCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.xCheckBox))
                    annotationPanels.yCheckBox.Checked = annotationPanels.zCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.yCheckBox))
                    annotationPanels.xCheckBox.Checked = annotationPanels.zCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.zCheckBox))
                    annotationPanels.xCheckBox.Checked = annotationPanels.yCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                else if (ReferenceEquals(sender, annotationPanels.zRadicalCheckBox))
                    annotationPanels.xCheckBox.Checked = annotationPanels.yCheckBox.Checked = annotationPanels.zCheckBox.Checked = false;

                panel.Tag = this;
            }

            ionSeries = IonSeries.Off;
            ionSeries |= annotationPanels.aCheckBox.Checked ? IonSeries.a : IonSeries.Off;
            ionSeries |= annotationPanels.bCheckBox.Checked ? IonSeries.b : IonSeries.Off;
            ionSeries |= annotationPanels.cCheckBox.Checked ? IonSeries.c : IonSeries.Off;
            ionSeries |= annotationPanels.xCheckBox.Checked ? IonSeries.x : IonSeries.Off;
            ionSeries |= annotationPanels.yCheckBox.Checked ? IonSeries.y : IonSeries.Off;
            ionSeries |= annotationPanels.zCheckBox.Checked ? IonSeries.z : IonSeries.Off;
            ionSeries |= annotationPanels.zRadicalCheckBox.Checked ? IonSeries.zRadical : IonSeries.Off;
            ionSeries |= annotationPanels.immoniumCheckBox.Checked ? IonSeries.Immonium : IonSeries.Off;
            showMisses = annotationPanels.showMissesCheckBox.Checked;
            OnOptionsChanged(this, EventArgs.Empty);
        }
Esempio n. 6
0
        public PeptideFragmentationAnnotation (string sequence,
                                               int minCharge, int maxCharge,
                                               MZTolerance tolerance,
                                               IonSeries ionSeries,
                                               bool showFragmentationLadders,
                                               bool showMissedFragments,
                                               bool showLabels,
                                               bool showFragmentationSummary)
        {
            this.sequence = sequence;
            this.min = minCharge;
            this.max = maxCharge;
            this.manualTolerance = tolerance;
            this.tolerance = new MZTolerance(0.5);
            this.ionSeries = ionSeries;
            this.showLadders = showFragmentationLadders;
            this.showMisses = showMissedFragments;
            this.showLabels = showLabels;
            this.showFragmentationSummary = showFragmentationSummary;

            annotationPanels.precursorMassTypeComboBox.SelectedIndex = 0;
            annotationPanels.fragmentMassTypeComboBox.SelectedIndex = 0;

            if (!ReferenceEquals(tolerance, null))
                annotationPanels.fragmentToleranceUnitsComboBox.SelectedIndex = (int) tolerance.units;
            else
                annotationPanels.fragmentToleranceUnitsComboBox.SelectedIndex = 0;

            annotationPanels.sequenceTextBox.TextChanged += sequenceTextBox_TextChanged;
            annotationPanels.minChargeUpDown.ValueChanged += checkBox_CheckedChanged;
            annotationPanels.maxChargeUpDown.ValueChanged += checkBox_CheckedChanged;
            annotationPanels.fragmentToleranceTextBox.TextChanged += toleranceChanged;
            annotationPanels.fragmentToleranceUnitsComboBox.SelectedIndexChanged += toleranceChanged;
            annotationPanels.precursorMassTypeComboBox.SelectedIndexChanged += checkBox_CheckedChanged;
            annotationPanels.fragmentMassTypeComboBox.SelectedIndexChanged += checkBox_CheckedChanged;
            annotationPanels.aCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.bCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.cCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.xCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.yCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.zCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.zRadicalCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.immoniumCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.showFragmentationLaddersCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.showMissesCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.showFragmentationSummaryCheckBox.CheckedChanged += checkBox_CheckedChanged;
            annotationPanels.showFragmentationTableCheckBox.CheckedChanged += checkBox_CheckedChanged;

            annotationPanels.fragmentInfoGridView.Columns.Clear();
        }
Esempio n. 7
0
        public override void Update( GraphItem item, pwiz.MSGraph.MSPointList points, GraphObjList annotations )
        {
            double basePeakIntensity = 0;
            double cutoff = 0;
            foreach (var pointlist in points)
            {
                if (basePeakIntensity < pointlist.Y)
                    basePeakIntensity = pointlist.Y;
            }
            cutoff = basePeakIntensity * basePeakPercentage * 0.01;

            if( !Enabled )
                return;

            if( !( item is MassSpectrum ) )
                return; // throw exception?

            GraphObjList list = annotations;
            Peptide peptide;

            try
            {
                peptide = new Peptide( sequence,
                    pwiz.CLI.proteome.ModificationParsing.ModificationParsing_Auto,
                    pwiz.CLI.proteome.ModificationDelimiter.ModificationDelimiter_Brackets );
            } catch( Exception )
            {
                return;
            }

            //if (annotationPanels.peptideInfoGridView.InvokeRequired)
            //{
            //    annotationPanels.peptideInfoGridView.BeginInvoke(new MethodInvoker(() => Update(item, points, annotations)));
            //    //return;
            //}

            var spectrum = ( item as MassSpectrum ).Element;

            if (spectrum.precursors.Count > 0 && ionSeriesIsEnabled(IonSeries.Auto))
            {
                bool cid = (item as MassSpectrum).Element.precursors[0].activation.hasCVParam(CVID.MS_CID);
                bool etd = (item as MassSpectrum).Element.precursors[0].activation.hasCVParam(CVID.MS_ETD);
                ionSeries |= cid ? IonSeries.b | IonSeries.y : IonSeries.Off;
                ionSeries |= etd ? IonSeries.c | IonSeries.zRadical : IonSeries.Off;
            }

            string unmodifiedSequence = peptide.sequence;
            int sequenceLength = unmodifiedSequence.Length;
            Fragmentation fragmentation = peptide.fragmentation( fragmentMassType == 0 ? true : false, true );

            //test neutral
            ModificationMap modifications = peptide.modifications();
            ///
            #region adding labels for series a/b/c/x/y/z:::::::::naive fragmentation modeling

            if (!showBasophileModel)
            {
                for (int i = 1; i < sequenceLength; ++i)
                {
                    //test neutral loss
                    //note here the Cseq is slightly different than those in addFragmentSummary
                    string Nseq = peptide.sequence.Substring(0, i);
                    string Cseq = peptide.sequence.Substring(sequenceLength - i, i);
                    string NTempSeq = peptide.sequence.Substring(0, sequenceLength - i);
                    char[] Nseqchars = Nseq.ToCharArray();
                    char[] NTempSeqchars = NTempSeq.ToCharArray();
                    char[] seqchars = peptide.sequence.ToCharArray();
                    int Nphosmodi = 0;
                    int NTempPhosmodi = 0;
                    int Cphosmodi = 0;
                    int phosmodi = 0;
                    for (int k = 0; k < i; k++)
                    {
                        if (Math.Round(modifications[k].monoisotopicDeltaMass()) == 80 && (seqchars[k] == 'S' || seqchars[k] == 'T' || seqchars[k] == 'Y'))
                        {
                            Nphosmodi++;
                        }
                    }
                    for (int k = 0; k < sequenceLength - i; k++)
                    {
                        if (Math.Round(modifications[k].monoisotopicDeltaMass()) == 80 && (seqchars[k] == 'S' || seqchars[k] == 'T' || seqchars[k] == 'Y'))
                        {
                            NTempPhosmodi++;
                        }
                    }
                    for (int k = 0; k < sequenceLength; k++)
                    {
                        if (Math.Round(modifications[k].monoisotopicDeltaMass()) == 80 && (seqchars[k] == 'S' || seqchars[k] == 'T' || seqchars[k] == 'Y'))
                        {
                            phosmodi++;
                        }
                    }
                    Cphosmodi = phosmodi - NTempPhosmodi;

                    for (int charge = min; charge <= max; ++charge)
                    {
                        if (ionSeriesIsEnabled(IonSeries.a)) addFragment(list, points, "a", i, charge, fragmentation.a(i, charge));
                        if (ionSeriesIsEnabled(IonSeries.b)) addFragment(list, points, "b", i, charge, fragmentation.b(i, charge));
                        if (ionSeriesIsEnabled(IonSeries.y)) addFragment(list, points, "y", i, charge, fragmentation.y(i, charge));
                        if (ionSeriesIsEnabled(IonSeries.z)) addFragment(list, points, "z", i, charge, fragmentation.z(i, charge));
                        if (ionSeriesIsEnabled(IonSeries.zRadical)) addFragment(list, points, "z*", i, charge, fragmentation.zRadical(i, charge));

                        if (i < sequenceLength)
                        {
                            if (ionSeriesIsEnabled(IonSeries.c)) addFragment(list, points, "c", i, charge, fragmentation.c(i, charge));
                            if (ionSeriesIsEnabled(IonSeries.x)) addFragment(list, points, "x", i, charge, fragmentation.x(i, charge));
                        }

                        //test neutral loss
                        #region water loss
                        if (waterLoss == true)
                        {
                            if (Nseq.Contains("S") || Nseq.Contains("T") || Nseq.Contains("E") || Nseq.Contains("D"))
                            {
                                if (ionSeriesIsEnabled(IonSeries.a)) addFragment(list, points, "a-water", i, charge, fragmentation.a(i, charge) - WATERMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.b)) addFragment(list, points, "b-water", i, charge, fragmentation.b(i, charge) - WATERMONOMASS / charge);
                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.c)) addFragment(list, points, "c-water", i, charge, fragmentation.c(i, charge) - WATERMONOMASS / charge);
                                }
                            }

                            if (Cseq.Contains("S") || Cseq.Contains("T") || Cseq.Contains("E") || Cseq.Contains("D"))
                            {
                                if (ionSeriesIsEnabled(IonSeries.y)) addFragment(list, points, "y-water", i, charge, fragmentation.y(i, charge) - WATERMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.z)) addFragment(list, points, "z-water", i, charge, fragmentation.z(i, charge) - WATERMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.zRadical)) addFragment(list, points, "z*-water", i, charge, fragmentation.zRadical(i, charge) - WATERMONOMASS / charge);

                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.x)) addFragment(list, points, "x-water", i, charge, fragmentation.x(i, charge) - WATERMONOMASS / charge);
                                }
                            }
                        }
                        #endregion

                        //test neutral loss
                        #region ammonium loss
                        if (ammoniumLoss == true)
                        {
                            if (Nseq.Contains("R") || Nseq.Contains("K") || Nseq.Contains("Q") || Nseq.Contains("N"))
                            {
                                if (ionSeriesIsEnabled(IonSeries.a)) addFragment(list, points, "a-ammonium", i, charge, fragmentation.a(i, charge) - AMMONIUMMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.b)) addFragment(list, points, "b-ammonium", i, charge, fragmentation.b(i, charge) - AMMONIUMMONOMASS / charge);
                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.c)) addFragment(list, points, "c-ammonium", i, charge, fragmentation.c(i, charge) - AMMONIUMMONOMASS / charge);
                                }
                            }

                            if (Cseq.Contains("R") || Cseq.Contains("K") || Cseq.Contains("Q") || Cseq.Contains("N"))
                            {
                                if (ionSeriesIsEnabled(IonSeries.y)) addFragment(list, points, "y-ammonium", i, charge, fragmentation.y(i, charge) - AMMONIUMMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.z)) addFragment(list, points, "z-ammonium", i, charge, fragmentation.z(i, charge) - AMMONIUMMONOMASS / charge);
                                if (ionSeriesIsEnabled(IonSeries.zRadical)) addFragment(list, points, "z*-ammonium", i, charge, fragmentation.zRadical(i, charge) - AMMONIUMMONOMASS / charge);

                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.x)) addFragment(list, points, "x-ammonium", i, charge, fragmentation.x(i, charge) - AMMONIUMMONOMASS / charge);
                                }
                            }
                        }
                        #endregion

                        //test neutral loss
                        #region phosphate loss
                        if (phosphateLoss == true)
                        {
                            int minNPhosphate = Math.Min(Nphosmodi, numPhosphate);
                            if (minNPhosphate > 0)
                            {
                                if (ionSeriesIsEnabled(IonSeries.a))
                                {
                                    for (int k = 1; k <= minNPhosphate; k++)
                                    {
                                        addFragment(list, points, "a-" + k + "phos", i, charge, fragmentation.a(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                    }
                                }
                                if (ionSeriesIsEnabled(IonSeries.b))
                                {
                                    for (int k = 1; k <= minNPhosphate; k++)
                                    {
                                        addFragment(list, points, "b-" + k + "phos", i, charge, fragmentation.b(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                    }
                                }
                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.c))
                                    {
                                        for (int k = 1; k <= minNPhosphate; k++)
                                        {
                                            addFragment(list, points, "c-" + k + "phos", i, charge, fragmentation.c(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                        }
                                    }
                                }

                            }

                            int minCPhosphate = Math.Min(Cphosmodi, numPhosphate);
                            if (minCPhosphate > 0)
                            {

                                if (ionSeriesIsEnabled(IonSeries.y))
                                {
                                    for (int k = 1; k <= minCPhosphate; k++)
                                    {
                                        addFragment(list, points, "y-" + k + "phos", i, charge, fragmentation.y(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                    }
                                }
                                if (ionSeriesIsEnabled(IonSeries.z))
                                {
                                    for (int k = 1; k <= minCPhosphate; k++)
                                        addFragment(list, points, "z-" + k + "phos", i, charge, fragmentation.z(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                }
                                if (ionSeriesIsEnabled(IonSeries.zRadical))
                                {
                                    for (int k = 1; k <= minCPhosphate; k++)
                                        addFragment(list, points, "z*-" + k + "phos", i, charge, fragmentation.zRadical(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                }

                                if (i < sequenceLength)
                                {
                                    if (ionSeriesIsEnabled(IonSeries.x))
                                    {
                                        for (int k = 1; k <= minCPhosphate; k++)
                                            addFragment(list, points, "x-" + k + "phos", i, charge, fragmentation.x(i, charge) - k * PHOSPHATEMONOMASS / charge);
                                    }
                                }
                            }

                        }
                        #endregion

                    }
                }
            }

            //for basophile fragmentation modeling
            else if (showBasophileModel)
            {
                //clear the panel
                //annotationPanels.bCheckBox.Checked = false;
                //annotationPanels.yCheckBox.Checked = false;
                String peptideSeq = peptide.sequence;
                int seqLength = peptideSeq.Length;
                char[] seq = peptideSeq.ToCharArray();
                int totalR = 0, totalK = 0, totalH = 0;

                for (int i = 0; i < seqLength; ++i)
                {
                    if (seq[i] == 'R')
                        ++totalR;
                    else if (seq[i] == 'K')
                        ++totalK;
                    else if (seq[i] == 'H')
                        ++totalH;
                }

                for (int c = 1; c < seqLength; c++)
                {
                    int totalNR = 0, totalNK = 0, totalNH = 0, totalNL = 0;
                    int totalCR = 0, totalCK = 0, totalCH = 0, totalCL = 0;
                    for (int i = 0; i < c; ++i)
                    {
                        if (seq[i] == 'R') { ++totalNR; }
                        else if (seq[i] == 'K') { ++totalNK; }
                        else if (seq[i] == 'H') { ++totalNH; }
                    }
                    totalNL = c;
                    totalCR = totalR - totalNR;
                    totalCK = totalK - totalNK;
                    totalCH = totalH - totalNH;
                    totalCL = seqLength - totalNL;

                    double y1_logit = 0.1098112 * totalNR + 0.2085831 * totalNK + 0.1512109 * totalNH + 0.0460839 * totalNL
                                    - 0.3872417 * totalCR - 0.3684911 * totalCK - 0.1634741 * totalCH - 0.1693931 * totalCL + 1.2632997;
                    double y2_logit = -0.6345364 * totalNR - 0.3365917 * totalNK - 0.4577882 * totalNH - 0.1492703 * totalNL
                                     + 0.7738133 * totalCR + 0.6036758 * totalCK + 0.5942542 * totalCH + 0.0701467 * totalCL + 0.0806280;
                    double b1_logit = 0.0801432 * totalNR - 0.1088081 * totalNK - 0.1338220 * totalNH - 0.1413059 * totalNL
                                    - 0.3157957 * totalCR - 0.2708274 * totalCK - 0.3703136 * totalCH + 0.0157418 * totalCL + 1.2124699;
                    double b2_logit = 0.8606449 * totalNR + 0.2763119 * totalNK + 0.4969152 * totalNH + 0.0685712 * totalNL
                                    - 1.3346995 * totalCR - 1.0977316 * totalCK - 1.0973677 * totalCH - 0.2028884 * totalCL + 1.9355980;

                    if (ionSeriesIsEnabled(IonSeries.b))
                    {
                        if (b1_logit > -0.5) addFragment(list, points, "b", c, 1, fragmentation.b(c, 1));
                        if (b2_logit > 0)    addFragment(list, points, "b", c, 2, fragmentation.b(c, 2));
                    }
                    if (ionSeriesIsEnabled(IonSeries.y))
                    {
                        if (y1_logit > -0.5) addFragment(list, points, "y", seqLength - c, 1, fragmentation.y(seqLength - c, 1));
                        if (y2_logit > -0.5) addFragment(list, points, "y", seqLength - c, 2, fragmentation.y(seqLength - c, 2));
                    }
                                            //if (b1_logit > -0.5)
                                            //    if (ionSeriesIsEnabled(IonSeries.b))
                                            //        addFragment(list, points, "b", c, 1, fragmentation.b(c, 1));
                                            //if (b2_logit > 0)
                                            //    if (ionSeriesIsEnabled(IonSeries.b))
                                            //        addFragment(list, points, "b", c, 2, fragmentation.b(c, 2));
                                            //if (y1_logit > -0.5)
                                            //    if (ionSeriesIsEnabled(IonSeries.y))
                                            //        addFragment(list, points, "y", seqLength - c, 1, fragmentation.y(seqLength - c, 1));
                                            //if (y2_logit > -0.5)
                                            //    if (ionSeriesIsEnabled(IonSeries.y))
                                            //        addFragment(list, points, "y", seqLength - c, 2, fragmentation.y(seqLength - c, 2));

                }
            }

            #endregion

            if ( showLadders || showFragmentationSummary)
            {
                //test neutral loss
                //string topSeries = ionSeriesIsEnabled(IonSeries.a) ? "a" : ionSeriesIsEnabled(IonSeries.b) ? "b" : ionSeriesIsEnabled(IonSeries.c) ? "c" : "";
                //string bottomSeries = ionSeriesIsEnabled(IonSeries.x) ? "x" : ionSeriesIsEnabled(IonSeries.y) ? "y" : ionSeriesIsEnabled(IonSeries.z) ? "z" : ionSeriesIsEnabled(IonSeries.zRadical) ? "z*" : "";
                //if (showLadders)
                //    addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                //if (showFragmentationSummary)
                //    addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                string topSeries = "";
                string bottomSeries = "";

                if (ionSeriesIsEnabled(IonSeries.a))
                {
                    topSeries = "a";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.b))
                {
                    topSeries = "b";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.c))
                {
                    topSeries = "c";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.x))
                {
                    bottomSeries = "x";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.y))
                {
                    bottomSeries = "y";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.z))
                {
                    bottomSeries = "z";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
                if (ionSeriesIsEnabled(IonSeries.zRadical))
                {
                    bottomSeries = "z*";
                    if (showLadders)
                        addIonSeries(list, points, peptide, fragmentation, topSeries, bottomSeries);
                    if (showFragmentationSummary)
                        addFragmentationSummary(list, points, peptide, fragmentation, topSeries, bottomSeries);
                }
            }

            annotationPanels.peptideInfoGridView.Rows.Clear();

            if( spectrum.precursors.Count > 0 &&
                spectrum.precursors[0].selectedIons.Count > 0 &&
                spectrum.precursors[0].selectedIons[0].hasCVParam( CVID.MS_selected_ion_m_z ) &&
                spectrum.precursors[0].selectedIons[0].hasCVParam( CVID.MS_charge_state ) )
            {
                double selectedMz = (double) spectrum.precursors[0].selectedIons[0].cvParam( CVID.MS_selected_ion_m_z ).value;
                int chargeState = (int) spectrum.precursors[0].selectedIons[0].cvParam( CVID.MS_charge_state ).value;
                double calculatedMass = ( precursorMassType == 0 ? peptide.monoisotopicMass( chargeState ) : peptide.molecularWeight( chargeState ) ) * chargeState;
                double observedMass = selectedMz * chargeState;
                annotationPanels.peptideInfoGridView.Rows.Add( "Calculated mass:", calculatedMass, "Mass error (daltons):", observedMass - calculatedMass );
                annotationPanels.peptideInfoGridView.Rows.Add( "Observed mass:", observedMass, "Mass error (ppm):", ( ( observedMass - calculatedMass ) / calculatedMass ) * 1e6 );
            } else
                annotationPanels.peptideInfoGridView.Rows.Add( "Calculated neutral mass:", precursorMassType == 0 ? peptide.monoisotopicMass() : peptide.molecularWeight() );

            annotationPanels.peptideInfoGridView.Columns[1].DefaultCellStyle.Format = "F4";
            foreach( DataGridViewRow row in annotationPanels.peptideInfoGridView.Rows )
                row.Height = row.InheritedStyle.Font.Height + 2;

            // TODO: fragmentInfoGridView is slow: make it faster, optional, or both!

            annotationPanels.fragmentInfoGridView.SuspendLayout();

            if( ionSeries > IonSeries.Auto )
            {
                if( annotationPanels.fragmentInfoGridView.Columns.Count == 0 )
                {
                    if (ionSeriesIsEnabled(IonSeries.a))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "a" + charge.ToString(),
                                "a" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                    if (ionSeriesIsEnabled(IonSeries.b))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "b" + charge.ToString(),
                                "b" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                    if (ionSeriesIsEnabled(IonSeries.c))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "c" + charge.ToString(),
                                "c" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));

                    annotationPanels.fragmentInfoGridView.Columns.Add("N", "#");
                    annotationPanels.fragmentInfoGridView.Columns.Add("Sequence", "seq");
                    annotationPanels.fragmentInfoGridView.Columns.Add("C", "#");

                    if (ionSeriesIsEnabled(IonSeries.x))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "x" + charge.ToString(),
                                "x" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                    if (ionSeriesIsEnabled(IonSeries.y))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "y" + charge.ToString(),
                                "y" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                    if (ionSeriesIsEnabled(IonSeries.z))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "z" + charge.ToString(),
                                "z" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                    if (ionSeriesIsEnabled(IonSeries.zRadical))
                        for (int charge = min; charge <= max; ++charge)
                            annotationPanels.fragmentInfoGridView.Columns.Add(
                                "z*" + charge.ToString(),
                                "z*" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));

                    foreach( DataGridViewColumn column in annotationPanels.fragmentInfoGridView.Columns )
                    {
                        column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        if( column.Name != "N" && column.Name != "C" && column.Name != "Sequence" )
                            column.DefaultCellStyle.Format = "F3";
                    }
                }

                while( annotationPanels.fragmentInfoGridView.Rows.Count > sequenceLength )
                    annotationPanels.fragmentInfoGridView.Rows.RemoveAt( annotationPanels.fragmentInfoGridView.Rows.Count - 1 );
                if( sequenceLength - annotationPanels.fragmentInfoGridView.Rows.Count > 0 )
                    annotationPanels.fragmentInfoGridView.Rows.Add( sequenceLength - annotationPanels.fragmentInfoGridView.Rows.Count );

                for( int i = 1; i <= sequenceLength; ++i )
                {
                    int cTerminalLength = sequenceLength - i + 1;
                    var row = annotationPanels.fragmentInfoGridView.Rows[i - 1];
                    var values = new List<object>(10);
                    //var row = annotationPanels.fragmentInfoGridView.Rows.Add()];

                    if (ionSeriesIsEnabled(IonSeries.a))
                        for (int charge = min; charge <= max; ++charge)
                            values.Add(fragmentation.a(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.b))
                        for (int charge = min; charge <= max; ++charge)
                            values.Add(fragmentation.b(i, charge));
                    if (ionSeriesIsEnabled(IonSeries.c))
                        for (int charge = min; charge <= max; ++charge)
                            if (i < sequenceLength)
                                values.Add(fragmentation.c(i, charge));
                            else
                                values.Add("");

                    values.Add(i);
                    values.Add(unmodifiedSequence[i - 1]);
                    values.Add(cTerminalLength);

                    if (ionSeriesIsEnabled(IonSeries.x))
                        for (int charge = min; charge <= max; ++charge)
                            if (i > 1)
                                values.Add(fragmentation.x(cTerminalLength, charge));
                            else
                                values.Add("");
                    if (ionSeriesIsEnabled(IonSeries.y))
                        for (int charge = min; charge <= max; ++charge)
                            values.Add(fragmentation.y(cTerminalLength, charge));
                    if (ionSeriesIsEnabled(IonSeries.z))
                        for (int charge = min; charge <= max; ++charge)
                            values.Add(fragmentation.z(cTerminalLength, charge));
                    if (ionSeriesIsEnabled(IonSeries.zRadical))
                        for (int charge = min; charge <= max; ++charge)
                            values.Add(fragmentation.zRadical(cTerminalLength, charge));
                    row.SetValues(values.ToArray());
                }

                //add my code in between
                //the purpose is to switch the fragmentInfoGridView table into a html
                //to solve the bug that the table can be copied, but the bold font information can not be copied
                //basically, a stringbuilder object is created and going to copy values, formats from gridview, and then output
                //currently the html output is only stored in local, and I am trying to adapt it into a applet-like viewer.

                //first a stringbuilder is created
                StringBuilder sb_original = new StringBuilder();
                //Setting HTML and table tags
                sb_original.Append("<html>");
                sb_original.Append("<head>");
                sb_original.Append("<title>fragmentGridView2HTML</title>");
                sb_original.Append("</head>");
                sb_original.Append("<body>");
                sb_original.Append("<br>");
                sb_original.AppendLine("<" + "table border='2' cellpadding='1' cellspacing='1'>");
                sb_original.AppendLine("<tr>");
                //setting table headers
                //make them bold
                for (int i = 0; i < annotationPanels.fragmentInfoGridView.Columns.Count; i++)
                {
                    sb_original.AppendLine("<th>" + annotationPanels.fragmentInfoGridView.Columns[i].HeaderText + "</th>");
                }
                sb_original.AppendLine("</tr>");

                //starting copying cells to html
                foreach( DataGridViewRow row in annotationPanels.fragmentInfoGridView.Rows )
                {
                    sb_original.AppendLine("<tr>");
                    row.Height = row.InheritedStyle.Font.Height + 2;

                    foreach( DataGridViewCell cell in row.Cells )
                    {
                        if (!(cell.Value is double))
                        {
                            //note: added two line here
                            sb_original.AppendLine("<td>" + cell.FormattedValue + "</td>");
                            continue;
                        }

                        double mz = (double) cell.Value;

                        int index = -1;
                        if( points != null )
                            index = points.FullLowerBound(mz - 0.5);

                        if (index == -1 || points.FullList[index].X > (mz + 0.5))
                        {
                            //note: added two line here
                            //first is to pass value to sb;
                            //second is to change the cell fontstyle back to regular, if previouly bold
                            sb_original.AppendLine("<td>" + cell.FormattedValue + "</td>");
                            cell.Style.Font = new Font(annotationPanels.fragmentInfoGridView.Font, FontStyle.Regular);
                            continue;
                        }

                        cell.Style.Font = new Font(annotationPanels.fragmentInfoGridView.Font, FontStyle.Bold);
                        //note: added one line here
                        sb_original.AppendLine("<td><b>" + cell.FormattedValue + "</b></td>");
                    }
                }

                sb_original.AppendLine("</tr>");
                sb_original.AppendLine("</body>");
                sb_original.AppendLine("</head>");
                sb_original.AppendLine("</html>");
                //for storation of stringbuilder into local file
                //test only

                string file_original = "C:\\Temp\\originalTable.html";
                Directory.CreateDirectory(Path.GetDirectoryName(file_original));
                TextWriter tw_original = new StreamWriter(file_original);
                tw_original.WriteLine(sb_original.ToString());
                tw_original.Flush();
                tw_original.Close();

                /////////////////////////////////////////////////////////
                /////////////////////////////////////////////////////////
                //test neutral loss
                #region Neutral Loss
                StringBuilder sb_neutral = new StringBuilder();

                if (waterLoss == false && ammoniumLoss == false && phosphateLoss == false)
                {
                    sb_neutral = sb_original;
                }
                else //if any of the neutral loss is clicked
                {
                    #region if any of the neutral loss is clicked
                    DataGridView neutralLossDataGridView = new DataGridView();

                    ///
                    #region add first columns part

                    if (ionSeriesIsEnabled(IonSeries.a))
                        for (int charge = min; charge <= max; ++charge)
                        {
                            neutralLossDataGridView.Columns.Add(
                                "a" + charge.ToString(),
                                "a" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                            if (waterLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "a" + charge.ToString() + "waterLoss",
                                    "a" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                            if (ammoniumLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "a" + charge.ToString() + "ammoniumLoss",
                                    "a" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                            if (phosphateLoss == true)
                            {
                                for (int k = 1; k<= numPhosphate; k++)
                                {
                                    if (k == 1)
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "a" + charge.ToString() + "phosphateLoss",
                                            "a" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                    }
                                    else
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "a" + charge.ToString() + "phosphateLoss",
                                            "a" + (charge > 1 ? "(+" + charge.ToString() + ")-"+k+"PHO" : "-"+k+"PHO"));
                                    }
                                }
                            }

                        }

                    if (ionSeriesIsEnabled(IonSeries.b))
                        for (int charge = min; charge <= max; ++charge)
                        {
                            neutralLossDataGridView.Columns.Add(
                                "b" + charge.ToString(),
                                "b" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                            if (waterLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "b" + charge.ToString() + "waterLoss",
                                    "b" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                            if (ammoniumLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "b" + charge.ToString() + "ammoniumLoss",
                                    "b" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                            if (phosphateLoss == true)
                            {
                                for (int k = 1; k<= numPhosphate; k++)
                                {
                                    if (k == 1)
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "b" + charge.ToString() + "phosphateLoss",
                                            "b" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                    }
                                    else
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "b" + charge.ToString() + "phosphateLoss",
                                            "b" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                    }
                                }
                            }
                        }

                    if (ionSeriesIsEnabled(IonSeries.c))
                        for (int charge = min; charge <= max; ++charge)
                        {
                            neutralLossDataGridView.Columns.Add(
                                "c" + charge.ToString(),
                                "c" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                            if (waterLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "c" + charge.ToString() + "waterLoss",
                                    "c" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                            if (ammoniumLoss == true)
                                neutralLossDataGridView.Columns.Add(
                                    "c" + charge.ToString() + "ammoniumLoss",
                                    "c" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                            if (phosphateLoss == true)
                            {
                                for (int k = 1; k<= numPhosphate; k++)
                                {
                                    if (k == 1)
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "c" + charge.ToString() + "phosphateLoss",
                                            "c" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                    }
                                    else
                                    {
                                        neutralLossDataGridView.Columns.Add(
                                            "c" + charge.ToString() + "phosphateLoss",
                                            "c" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                    }
                                }
                            }

                        }
                    #endregion

                    neutralLossDataGridView.Columns.Add("N", "#");
                    neutralLossDataGridView.Columns.Add("Sequence", "seq");
                    neutralLossDataGridView.Columns.Add("C", "#");
                    ///
                    #region add second columns part
                        if (ionSeriesIsEnabled(IonSeries.x))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                neutralLossDataGridView.Columns.Add(
                                   "x" + charge.ToString(),
                                   "x" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                                if (waterLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "x" + charge.ToString() + "waterLoss",
                                        "x" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                                if (ammoniumLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "x" + charge.ToString() + "ammoniumLoss",
                                        "x" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k<= numPhosphate; k++)
                                    {
                                        if (k == 1)
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "x" + charge.ToString() + "phosphateLoss",
                                                "x" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                        }
                                        else
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "x" + charge.ToString() + "phosphateLoss",
                                                "x" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                        }
                                    }
                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.y))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                neutralLossDataGridView.Columns.Add(
                                    "y" + charge.ToString(),
                                    "y" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                                if (waterLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "y" + charge.ToString() + "waterLoss",
                                        "y" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                                if (ammoniumLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "y" + charge.ToString() + "ammoniumLoss",
                                        "y" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k<= numPhosphate; k++)
                                    {
                                        if (k == 1)
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "y" + charge.ToString() + "phosphateLoss",
                                                "y" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                        }
                                        else
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "y" + charge.ToString() + "phosphateLoss",
                                                "y" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                        }
                                    }
                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.z))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                neutralLossDataGridView.Columns.Add(
                                    "z" + charge.ToString(),
                                    "z" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                                if (waterLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "z" + charge.ToString() + "waterLoss",
                                        "z" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                                if (ammoniumLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "z" + charge.ToString() + "ammoniumLoss",
                                        "z" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k<= numPhosphate; k++)
                                    {
                                        if (k == 1)
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "z" + charge.ToString() + "phosphateLoss",
                                                "z" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                        }
                                        else
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "z" + charge.ToString() + "phosphateLoss",
                                                "z" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                        }
                                    }
                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.zRadical))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                neutralLossDataGridView.Columns.Add(
                                   "z*" + charge.ToString(),
                                   "z*" + (charge > 1 ? "(+" + charge.ToString() + ")" : ""));
                                if (waterLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "z*" + charge.ToString() + "waterLoss",
                                        "z*" + (charge > 1 ? "(+" + charge.ToString() + ")-H2O" : "-H2O"));
                                if (ammoniumLoss == true)
                                    neutralLossDataGridView.Columns.Add(
                                        "z*" + charge.ToString() + "ammoniumLoss",
                                        "z*" + (charge > 1 ? "(+" + charge.ToString() + ")-NH3" : "-NH3"));
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k<= numPhosphate; k++)
                                    {
                                        if (k == 1)
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "z*" + charge.ToString() + "phosphateLoss",
                                                "z*" + (charge > 1 ? "(+" + charge.ToString() + ")-PHO" : "-PHO"));
                                        }
                                        else
                                        {
                                            neutralLossDataGridView.Columns.Add(
                                                "z*" + charge.ToString() + "phosphateLoss",
                                                "z*" + (charge > 1 ? "(+" + charge.ToString() + ")-" + k + "PHO" : "-" + k + "PHO"));
                                        }
                                    }
                                }
                            }
                        #endregion

                    while (neutralLossDataGridView.Rows.Count > sequenceLength)
                        neutralLossDataGridView.Rows.RemoveAt(neutralLossDataGridView.Rows.Count - 1);
                    if (sequenceLength - neutralLossDataGridView.Rows.Count > 0)
                        neutralLossDataGridView.Rows.Add(sequenceLength - neutralLossDataGridView.Rows.Count);

                    char[] aminoAcids = peptide.sequence.ToCharArray();
                    for (int i = 1; i <= sequenceLength; ++i)
                    {
                        int Nphosmodi = 0;
                        int Cphosmodi = 0;

                        int cTerminalLength = sequenceLength - i + 1;
                        var row = neutralLossDataGridView.Rows[i - 1];
                        var values = new List<object>();

                        //define the amino acides that are capable of losing water
                        //AA = S,T,E,D
                        bool nSTED = false;
                        bool cSTED = false;
                        bool nRKQN = false;
                        bool cRKQN = false;

                        for (int index = 0; index < i; index++)
                        {
                            if (aminoAcids[index] == 'S' || aminoAcids[index] == 'T' || aminoAcids[index] == 'E' || aminoAcids[index] == 'D')
                                nSTED = true;
                            if (aminoAcids[index] == 'R' || aminoAcids[index] == 'K' || aminoAcids[index] == 'Q' || aminoAcids[index] == 'N')
                                nRKQN = true;
                            if (Math.Round(modifications[index].monoisotopicDeltaMass()) == 80 && (aminoAcids[index] == 'S' || aminoAcids[index] == 'T' || aminoAcids[index] == 'Y'))
                                Nphosmodi++;
                        }

                        //here is more tricky. since the display is
                        //b1    -----     y(seq-1+1)
                        //b2    -----     y(seq-2+1)
                        for (int index = sequenceLength - 1; index >= i - 1; index--)
                        {
                            if (aminoAcids[index] == 'S' || aminoAcids[index] == 'T' || aminoAcids[index] == 'E' || aminoAcids[index] == 'D')
                                cSTED = true;
                            if (aminoAcids[index] == 'R' || aminoAcids[index] == 'K' || aminoAcids[index] == 'Q' || aminoAcids[index] == 'N')
                                cRKQN = true;
                            if (Math.Round(modifications[index].monoisotopicDeltaMass()) == 80 && (aminoAcids[index] == 'S' || aminoAcids[index] == 'T' || aminoAcids[index] == 'Y'))
                                Cphosmodi++;

                        }

                        int minNPhosphate = Math.Min(numPhosphate, Nphosmodi);
                        int minCPhosphate = Math.Min(numPhosphate, Cphosmodi);
                        if (ionSeriesIsEnabled(IonSeries.a))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                values.Add(Math.Round(fragmentation.a(i, charge), 3));
                                if (waterLoss == true)
                                {
                                    if (nSTED) values.Add(Math.Round(fragmentation.a(i, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (nRKQN) values.Add(Math.Round(fragmentation.a(i, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k <= numPhosphate; k++)
                                    {
                                        if (k <= minNPhosphate)
                                        {
                                            values.Add(Math.Round(fragmentation.a(i, charge) - k*PHOSPHATEMONOMASS / charge, 3));
                                        }
                                        else
                                        {
                                            values.Add("-");
                                        }

                                    }
                                }

                            }

                        if (ionSeriesIsEnabled(IonSeries.b))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                values.Add(Math.Round(fragmentation.b(i, charge), 3));
                                if (waterLoss == true)
                                {
                                    if (nSTED) values.Add(Math.Round(fragmentation.b(i, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (nRKQN) values.Add(Math.Round(fragmentation.b(i, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k <= numPhosphate; k++)
                                    {
                                        if (k <= minNPhosphate)
                                        {
                                            values.Add(Math.Round(fragmentation.b(i, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                        }
                                        else
                                        {
                                            values.Add("-");
                                        }
                                    }
                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.c))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                if (i < sequenceLength)
                                    values.Add(Math.Round(fragmentation.c(i, charge), 3));
                                else
                                    values.Add("-");
                                if (waterLoss == true)
                                {
                                    if (nSTED && i < sequenceLength)
                                        values.Add(Math.Round(fragmentation.c(i, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (nRKQN && i < sequenceLength)
                                        values.Add(Math.Round(fragmentation.c(i, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    if (i < sequenceLength)
                                    {
                                        for (int k = 1; k <= numPhosphate; k++)
                                        {
                                            if (k <= minNPhosphate)
                                            {
                                                values.Add(Math.Round(fragmentation.c(i, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                            }
                                            else
                                            {
                                                values.Add("-");
                                            }
                                        }
                                    }
                                    else values.Add("-");

                                }
                            }

                        values.Add(i);
                        values.Add(unmodifiedSequence[i - 1]);
                        values.Add(cTerminalLength);

                        if (ionSeriesIsEnabled(IonSeries.x))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                if (i > 1)
                                    values.Add(Math.Round(fragmentation.x(sequenceLength - i + 1, charge), 3));
                                else
                                    values.Add("-");
                                if (waterLoss == true)
                                {
                                    if (cSTED && i > 1)
                                        values.Add(Math.Round(fragmentation.x(sequenceLength - i + 1, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (cRKQN && i > 1)
                                        values.Add(Math.Round(fragmentation.x(sequenceLength - i + 1, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    if (i > 1)
                                    {
                                        for (int k = 1; k <= numPhosphate; k++)
                                        {
                                            if (k <= minCPhosphate)
                                            {
                                                values.Add(Math.Round(fragmentation.x(sequenceLength - i + 1, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                            }
                                            else
                                            {
                                                values.Add("-");
                                            }
                                        }
                                    }
                                    else values.Add("-");

                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.y))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                values.Add(Math.Round(fragmentation.y(sequenceLength - i + 1, charge), 3));
                                if (waterLoss == true)
                                {
                                    if (cSTED) values.Add(Math.Round(fragmentation.y(sequenceLength - i + 1, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (cRKQN) values.Add(Math.Round(fragmentation.y(sequenceLength - i + 1, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k <= numPhosphate; k++)
                                    {
                                        if (k <= minCPhosphate)
                                        {
                                            values.Add(Math.Round(fragmentation.y(sequenceLength - i + 1, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                        }
                                        else
                                        {
                                            values.Add("-");
                                        }
                                    }
                                }
                            }

                        if (ionSeriesIsEnabled(IonSeries.z))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                values.Add(Math.Round(fragmentation.z(sequenceLength - i + 1, charge), 3));
                                if (waterLoss == true)
                                {
                                    if (cSTED) values.Add(Math.Round(fragmentation.z(sequenceLength - i + 1, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (cRKQN) values.Add(Math.Round(fragmentation.z(sequenceLength - i + 1, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k <= numPhosphate; k++)
                                    {
                                        if (k <= minCPhosphate)
                                        {
                                            values.Add(Math.Round(fragmentation.z(sequenceLength - i + 1, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                        }
                                        else
                                        {
                                            values.Add("-");
                                        }
                                    }
                                }
                            }
                        if (ionSeriesIsEnabled(IonSeries.zRadical))
                            for (int charge = min; charge <= max; ++charge)
                            {
                                values.Add(Math.Round(fragmentation.zRadical(sequenceLength - i + 1, charge), 3));
                                if (waterLoss == true)
                                {
                                    if (cSTED) values.Add(Math.Round(fragmentation.zRadical(sequenceLength - i + 1, charge) - WATERMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (ammoniumLoss == true)
                                {
                                    if (cRKQN) values.Add(Math.Round(fragmentation.zRadical(sequenceLength - i + 1, charge) - AMMONIUMMONOMASS / charge, 3));
                                    else values.Add("-");
                                }
                                if (phosphateLoss == true)
                                {
                                    for (int k = 1; k <= numPhosphate; k++)
                                    {
                                        if (k <= minCPhosphate)
                                        {
                                            values.Add(Math.Round(fragmentation.zRadical(sequenceLength - i + 1, charge) - k * PHOSPHATEMONOMASS / charge, 3));
                                        }
                                        else
                                        {
                                            values.Add("-");
                                        }
                                    }
                                }
                            }

                        row.SetValues(values.ToArray());

                    }//end for

                    //add sb_neutral loss table
                    #region add sb_neutral loss table
                    sb_neutral.Append("<html>");
                    sb_neutral.Append("<head>");
                    sb_neutral.Append("<title>neutralLossFragmentGridView2HTML</title>");
                    sb_neutral.Append("</head>");
                    sb_neutral.Append("<body>");
                    sb_neutral.Append("<br>");
                    sb_neutral.AppendLine("<" + "table border='2' cellpadding='1' cellspacing='1'>");
                    sb_neutral.AppendLine("<tr>");

                    for (int i = 0; i < neutralLossDataGridView.Columns.Count; i++)
                    {
                        sb_neutral.AppendLine("<th>" + neutralLossDataGridView.Columns[i].HeaderText + "</th>");
                    }

                    foreach (DataGridViewRow row in neutralLossDataGridView.Rows)
                    {
                        sb_neutral.AppendLine("<tr>");

                        #region basepeakthresholding is false
                        if (basePeakThresholding == false)
                        {
                            foreach (DataGridViewCell cell in row.Cells)
                            {
                                if (!(cell.Value is double))
                                {
                                    sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                    continue;
                                }

                                double mz = (double)cell.Value;

                                int index = -1;
                                if (points != null)
                                    index = points.FullLowerBound(mz - 0.5);

                                if (index == -1 || points.FullList[index].X > (mz + 0.5))
                                {
                                    sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                    //cell.Style.Font = new Font(annotationPanels.fragmentInfoGridView.Font, FontStyle.Regular);
                                    continue;
                                }
                                //cell.Style.Font = new Font(annotationPanels.fragmentInfoGridView.Font, FontStyle.Bold);
                                sb_neutral.AppendLine("<td><b>" + cell.FormattedValue + "</b></td>");
                            }
                        }
                        #endregion

                        else//basepeakthresholding is true
                        {
                            int columnIndex = 0;
                            foreach (DataGridViewCell cell in row.Cells)
                            {
                                if (neutralLossDataGridView.Columns[columnIndex].HeaderText.Contains("H2O") || neutralLossDataGridView.Columns[columnIndex].HeaderText.Contains("NH3") || neutralLossDataGridView.Columns[columnIndex].HeaderText.Contains("PHO"))
                                {
                                    if (!(cell.Value is double))
                                    {
                                        sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                        columnIndex++;
                                        continue;
                                    }

                                    double mz = (double)cell.Value;

                                    int index = -1;
                                    if (points != null)
                                        index = points.FullLowerBound(mz - 0.5);

                                    if (index == -1 || points.FullList[index].X > (mz + 0.5) || points.FullList[index].Y < cutoff)
                                    {
                                        sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                        columnIndex++;
                                        continue;
                                    }
                                    sb_neutral.AppendLine("<td><b>" + cell.FormattedValue + "</b></td>");
                                    columnIndex++;
                                }
                                else
                                {
                                    if (!(cell.Value is double))
                                    {
                                        sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                        columnIndex++;
                                        continue;
                                    }

                                    double mz = (double)cell.Value;

                                    int index = -1;
                                    if (points != null)
                                        index = points.FullLowerBound(mz - 0.5);

                                    if (index == -1 || points.FullList[index].X > (mz + 0.5))
                                    {
                                        sb_neutral.AppendLine("<td>" + cell.FormattedValue + "</td>");
                                        columnIndex++;
                                        continue;
                                    }
                                    sb_neutral.AppendLine("<td><b>" + cell.FormattedValue + "</b></td>");
                                    columnIndex++;
                                }
                            }
                        }

                    }
                    sb_neutral.AppendLine("</tr>");
                    sb_neutral.AppendLine("</body>");
                    sb_neutral.AppendLine("</head>");
                    sb_neutral.AppendLine("</html>");
                    #endregion

                    #endregion
                } //end of else
                string file_neutral = "C:\\Temp\\neutralLossTable.html";
                Directory.CreateDirectory(Path.GetDirectoryName(file_neutral));
                TextWriter tw_neutral = new StreamWriter(file_neutral);
                tw_neutral.WriteLine(sb_neutral.ToString());
                tw_neutral.Flush();
                tw_neutral.Close();
                #endregion
            }
            else
                annotationPanels.fragmentInfoGridView.Rows.Clear();

            annotationPanels.fragmentInfoGridView.ResumeLayout();
        }
Esempio n. 8
0
        void checkBox_CheckedChanged( object sender, EventArgs e )
        {
            if( panel.Tag == this )
            {
                min = (int) annotationPanels.minChargeUpDown.Value;
                max = (int) annotationPanels.maxChargeUpDown.Value;

                precursorMassType = annotationPanels.precursorMassTypeComboBox.SelectedIndex;
                fragmentMassType = annotationPanels.fragmentMassTypeComboBox.SelectedIndex;

                showLadders = annotationPanels.showFragmentationLaddersCheckBox.Checked;
                showFragmentationSummary = annotationPanels.showFragmentationSummaryCheckBox.Checked;
                showBasophileModel = annotationPanels.showBasophileCheckBox.Checked;

                //test neutral loss
                waterLoss = annotationPanels.waterLossCheckBox.Checked;
                ammoniumLoss = annotationPanels.ammoniumLossCheckBox.Checked;
                phosphateLoss = annotationPanels.phosphateLossCheckBox.Checked;
                basePeakThresholding = annotationPanels.thresholdCheckBox.Checked;
                numPhosphate = (int)annotationPanels.phosphateUpDown.Value;
                basePeakPercentage = (double)annotationPanels.basePeakIntenPercentageUpDown.Value;

                // any control which affects the columns displayed for fragments clears the column list;
                // it gets repopulated on the next call to Update()
                if(!ReferenceEquals(sender, annotationPanels.showMissesCheckBox))
                    annotationPanels.fragmentInfoGridView.Columns.Clear();

                //test neutral loss
                //I think the waterLoss checkbox will affect the fragments, so I guess this should be related to clear()
                //not sure about this
                if (!ReferenceEquals(sender, annotationPanels.waterLossCheckBox))
                    annotationPanels.fragmentInfoGridView.Columns.Clear();
                if (!ReferenceEquals(sender, annotationPanels.ammoniumLossCheckBox))
                    annotationPanels.fragmentInfoGridView.Columns.Clear();
                if (!ReferenceEquals(sender, annotationPanels.phosphateLossCheckBox))
                    annotationPanels.fragmentInfoGridView.Columns.Clear();

                // when showLadders is checked, the ion series checkboxes act like radio buttons:
                // series from the same terminus are grouped together
                if ((showLadders || showFragmentationSummary) && sender is CheckBox)
                {
                    panel.Tag = null;
                    if (ReferenceEquals(sender, annotationPanels.showFragmentationLaddersCheckBox) ||
                        ReferenceEquals(sender, annotationPanels.showFragmentationSummaryCheckBox))
                    {
                        // uncheck all but the first checked checkbox
                        annotationPanels.bCheckBox.Checked = !annotationPanels.aCheckBox.Checked;
                        annotationPanels.cCheckBox.Checked = !annotationPanels.aCheckBox.Checked && !annotationPanels.bCheckBox.Checked;
                        annotationPanels.yCheckBox.Checked = !annotationPanels.xCheckBox.Checked;
                        annotationPanels.zCheckBox.Checked = !annotationPanels.xCheckBox.Checked && !annotationPanels.yCheckBox.Checked;
                        annotationPanels.zRadicalCheckBox.Checked = !annotationPanels.xCheckBox.Checked && !annotationPanels.yCheckBox.Checked && !annotationPanels.zCheckBox.Checked;
                    }
                    //else if (ReferenceEquals(sender, annotationPanels.aCheckBox))
                    //    annotationPanels.bCheckBox.Checked = annotationPanels.cCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.bCheckBox))
                    //    annotationPanels.aCheckBox.Checked = annotationPanels.cCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.cCheckBox))
                    //    annotationPanels.aCheckBox.Checked = annotationPanels.bCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.xCheckBox))
                    //    annotationPanels.yCheckBox.Checked = annotationPanels.zCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.yCheckBox))
                    //    annotationPanels.xCheckBox.Checked = annotationPanels.zCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.zCheckBox))
                    //    annotationPanels.xCheckBox.Checked = annotationPanels.yCheckBox.Checked = annotationPanels.zRadicalCheckBox.Checked = false;

                    //else if (ReferenceEquals(sender, annotationPanels.zRadicalCheckBox))
                    //    annotationPanels.xCheckBox.Checked = annotationPanels.yCheckBox.Checked = annotationPanels.zCheckBox.Checked = false;

                    panel.Tag = this;
                }

                ionSeries = IonSeries.Off;
                ionSeries |= annotationPanels.aCheckBox.Checked ? IonSeries.a : IonSeries.Off;
                ionSeries |= annotationPanels.bCheckBox.Checked ? IonSeries.b : IonSeries.Off;
                ionSeries |= annotationPanels.cCheckBox.Checked ? IonSeries.c : IonSeries.Off;
                ionSeries |= annotationPanels.xCheckBox.Checked ? IonSeries.x : IonSeries.Off;
                ionSeries |= annotationPanels.yCheckBox.Checked ? IonSeries.y : IonSeries.Off;
                ionSeries |= annotationPanels.zCheckBox.Checked ? IonSeries.z : IonSeries.Off;
                ionSeries |= annotationPanels.zRadicalCheckBox.Checked ? IonSeries.zRadical : IonSeries.Off;
                showMisses = annotationPanels.showMissesCheckBox.Checked;
                OnOptionsChanged( this, EventArgs.Empty );
            }
        }
Esempio n. 9
0
        public PeptideFragmentationAnnotation(string sequence,
                                               int minCharge, int maxCharge,
                                               IonSeries ionSeries,
                                               bool showFragmentationLadders,
                                               bool showMissedFragments,
                                               bool showLabels,
                                               bool showFragmentationSummary)
        {
            this.sequence = sequence;
            this.min = minCharge;
            this.max = maxCharge;
            this.ionSeries = ionSeries;
            this.showLadders = showFragmentationLadders;
            this.showMisses = showMissedFragments;
            this.showLabels = showLabels;
            this.showFragmentationSummary = showFragmentationSummary;
            //this.showBasophileModel = showBasophileModel;

            //test neutral loss
            this.numPhosphate = 1;
            basePeakThresholding = false;
            this.basePeakPercentage = 0;

            annotationPanels.precursorMassTypeComboBox.SelectedIndex = 0;
            annotationPanels.fragmentMassTypeComboBox.SelectedIndex = 0;

            annotationPanels.sequenceTextBox.TextChanged += new EventHandler( sequenceTextBox_TextChanged );
            annotationPanels.minChargeUpDown.ValueChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.maxChargeUpDown.ValueChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.precursorMassTypeComboBox.SelectedIndexChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.fragmentMassTypeComboBox.SelectedIndexChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.aCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.bCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.cCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.xCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.yCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.zCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.zRadicalCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.showFragmentationLaddersCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.showMissesCheckBox.CheckedChanged += new EventHandler( checkBox_CheckedChanged );
            annotationPanels.showFragmentationSummaryCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
            annotationPanels.showBasophileCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);

            //test neutral loss
            annotationPanels.waterLossCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
            annotationPanels.ammoniumLossCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
            annotationPanels.phosphateLossCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
            annotationPanels.thresholdCheckBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
            annotationPanels.basePeakIntenPercentageUpDown.ValueChanged += new EventHandler(checkBox_CheckedChanged);

            annotationPanels.fragmentInfoGridView.Columns.Clear();
        }
 private double fragmentMass(pwiz.CLI.proteome.Fragmentation f, IonSeries series, int length, int charge)
 {
     switch (series)
     {
         case IonSeries.a: return f.a(length, charge);
         case IonSeries.b: return f.b(length, charge);
         case IonSeries.c: return f.c(length, charge);
         case IonSeries.x: return f.x(length, charge);
         case IonSeries.y: return f.y(length, charge);
         case IonSeries.z: return f.z(length, charge);
         default: throw new ArgumentException();
     }
 }
Esempio n. 11
0
        private void PlotSequence(List <PredictedIon> peaks, IonSeries ionType, double yHeight, SolidColorBrush theBrush)
        {
            if (IonsInDisplay.Count == 0)
            {
                IonsInDisplay = myMS;

                if (myMS.Count == 0)
                {
                    return;
                }
            }

            double lowestMass  = IonsInDisplay.Min(a => a.MZ);
            double largestMass = IonsInDisplay.Max(a => a.MZ);

            List <PredictedIon> peaksOfInterest = peaks.FindAll(a => a.Number >= 0 && a.Series.Equals(ionType));

            peaksOfInterest.Sort((a, b) => a.MZ.CompareTo(b.MZ));

            string upperLabel   = "";
            string lowerLabel   = "";
            int    matchCounter = 0;
            double lastX        = ConvertMZToPixelX(lowestMass, lowestMass, largestMass);

            for (int i = 0; i < peaksOfInterest.Count; i++)
            {
                if (peaksOfInterest[i].Matched || i == peaksOfInterest.Count - 1)
                {
                    matchCounter++;
                    upperLabel += peaksOfInterest[i].FinalAA;
                    lowerLabel += peaksOfInterest[i].Number;

                    //Plot
                    double startX = lastX;
                    double endX   = ConvertMZToPixelX(peaksOfInterest[i].MZ, lowestMass, largestMass);

                    ArrowHeads.ArrowEnds thisArrowEnds = ArrowHeads.ArrowEnds.Both;
                    if (matchCounter == 1 && peaksOfInterest[i].Number > i)
                    {
                        thisArrowEnds = ArrowHeads.ArrowEnds.End;
                    }

                    if (i == peaksOfInterest.Count - 1)
                    {
                        endX = ConvertMZToPixelX(largestMass, lowestMass, largestMass);
                        if (peaksOfInterest[i].MZ > largestMass)
                        {
                            thisArrowEnds = ArrowHeads.ArrowEnds.Start;
                        }
                    }

                    PatternTools.ArrowHeads.ArrowDeNovo.ArrowDeNovoDraw(upperLabel, lowerLabel, theBrush, canvasDenovo, startX, endX, yHeight, thisArrowEnds);

                    //And now clear for the next labels
                    upperLabel = "";
                    lowerLabel = "";
                    lastX      = endX;
                }
                else
                {
                    upperLabel += peaksOfInterest[i].FinalAA + " ";
                    lowerLabel += peaksOfInterest[i].Number + ", ";
                }
            }
        }
Esempio n. 12
0
        private static List <PredictedIon> SequentialScore(List <PredictedIon> theoretical, IonSeries ionSerie)
        {
            int greatestSequence = 0;
            int sequenceCounter  = 0;

            List <PredictedIon> theIons       = theoretical.FindAll(a => a.Series.Equals(ionSerie));
            List <PredictedIon> theResult     = new List <PredictedIon>(10);
            List <PredictedIon> partialResult = new List <PredictedIon>(10);

            if (theIons[0].Matched)
            {
                sequenceCounter++;
                partialResult.Add(theIons[0]);

                greatestSequence = sequenceCounter;
                theResult.Clear();
                theResult.AddRange(partialResult);
            }

            for (int i = 1; i < theIons.Count - 1; i++)
            {
                if (theIons[i].Matched && theIons[i + 1].Matched)
                {
                    sequenceCounter++;
                    partialResult.Add(theIons[i + 1]);
                }
                else
                {
                    if (sequenceCounter > greatestSequence)
                    {
                        greatestSequence = sequenceCounter;
                        theResult.Clear();
                        theResult.AddRange(partialResult);
                    }
                }
            }

            if (theIons[theIons.Count - 2].Matched)
            {
                sequenceCounter++;
                partialResult.Add(theIons[theIons.Count - 1]);

                greatestSequence = sequenceCounter;
                theResult.Clear();
                theResult.AddRange(partialResult);
            }

            return(theResult);
        }