コード例 #1
0
ファイル: LorenzianFit.cs プロジェクト: danieleRocha/Momentos
        public void RunLorenzian()
        {
            int npts=100;
            //produce test data - a is a vecor with exact solution
            double[] x = new double[npts];
            for (int i = 0; i < npts; i++)
            {
                x[i] = -5 + 0.1 *i; // NR always counts from 1
            }

            double[] a = {1,0};

            LMAFunction f = new LorenzianFunction();

            double[][] dataPoints = f.GenerateData(a,x);

            //initial guess should be close enough
            LMA algorithm = new LMA(f,new double[] {5, 5},
                dataPoints, null, new GeneralMatrix(2,2),1d-20,100);

            algorithm.Fit();

            for (int i=0; i<a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }
コード例 #2
0
ファイル: GaussianFit.cs プロジェクト: danieleRocha/Momentos
        public void RunGaussian()
        {
            int npts=100;
            //produce test data - a is a vecor with exact solution
            double[] x = new double[npts];
            for (int i = 0; i < npts; i++)
            {
                x[i] = 0.1 * (i + 1); // NR always counts from 1
            }

            double[] a = {5, 2, 3, 2, 5, 3};

            LMAFunction f = new GaussianFunction();

            double[][] dataPoints = f.GenerateData(a,x);

            LMA algorithm = new LMA(f,new double[] {4, 2, 2, 2, 5, 2},
                dataPoints, null, new GeneralMatrix(6,6),1d-30,100);

            algorithm.Fit();

            for (int i=0; i<a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }
コード例 #3
0
ファイル: SinFit.cs プロジェクト: danieleRocha/Momentos
        public void RunSin()
        {
            //produce test data - a is a vecor with exact solution
            double[] x = {0.0, 0.1, 0.2, 0.3, 0.5, 0.7};
            double[] a = {2.2, 0.4};
            LMAFunction f = new SinFunction();

            double[][] dataPoints = f.GenerateData(a,x);

            LMA algorithm = new LMA(f,new double[] {0.1, 10},
                dataPoints, null, new GeneralMatrix(2,2),1d-20,100);

            algorithm.Fit();

            for (int i=0; i<a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }
コード例 #4
0
ファイル: LineFit.cs プロジェクト: danieleRocha/Momentos
        public void RunLine()
        {
            double[] x = {0, 2, 6, 8, 9};
            double[] a = {2, 0.51};

            LMAFunction f = new LineFunction();

            double[][] dataPoints = f.GenerateData(a,x);

            LMA algorithm = new LMA(f,new double[] {100, -100},
                dataPoints, null, new GeneralMatrix(2,2),1d-20,100);

            algorithm.Fit();

            for (int i=0; i<a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }
コード例 #5
0
ファイル: Phosphinator.cs プロジェクト: dbaileychess/Compass
public void Phosphinate()
{
    StreamWriter log = null;
            IXRawfile2 raw = null;
            StreamReader csv = null;
            StreamWriter non_phospho_output = null;
            StreamWriter localized_phospho_output = null;
            StreamWriter unlocalized_phospho_output = null;
            StreamWriter motifX = null;

            try
            {
                onStarting(new EventArgs());

                onUpdateProgress(new ProgressEventArgs(0));

                StringBuilder fixed_modifications_sb = new StringBuilder();
                foreach (Modification modification in fixedModifications)
                {
                    fixed_modifications_sb.Append(modification.Name + ", ");
                }
                if (fixed_modifications_sb.Length > 0)
                {
                    fixed_modifications_sb = fixed_modifications_sb.Remove(fixed_modifications_sb.Length - 2, 2);
                }
                string fixed_modifications = fixed_modifications_sb.ToString();

                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                log = new StreamWriter(Path.Combine(outputFolder, "Phosphinator_log.txt"));
                log.AutoFlush = true;

                log.WriteLine("Phosphinator PARAMETERS");
                log.WriteLine("Fixed Modifications: " + fixed_modifications);
                log.WriteLine("Fragment Intensity Threshold: " + intensityThreshold.ToString() + " (" + intensityThresholdType.ToString() + ')');
                log.WriteLine("Fragment m/z Tolerance (Th): " + mzTolerance.ToString());
                log.WriteLine("Ambiguity Score Threshold: " + ambiguityScoreThreshold.ToString());
                log.WriteLine("Eliminate Precursor Interference: " + eliminatePrecursorInterference.ToString());
                if (eliminatePrecursorInterference)
                {
                    log.WriteLine("Precursor Interference Threshold: " + precursorInterferenceThreshold.ToString());
                }
                if (motifXOutput)
                {
                    log.WriteLine("Motif-X Fasta Protein Database Filepath: " + motifXFastaProteinDatabaseFilepath);
                    log.WriteLine("Motif-X Window Size: " + motifXWindowSize.ToString());
                }
                log.WriteLine();

                ProteinSiteCounter identified_sites_by_protein = new ProteinSiteCounter();
                ProteinSiteCounter localized_sites_by_protein = new ProteinSiteCounter();
                ProteinSiteCounter unlocalized_sites_by_protein = new ProteinSiteCounter();

                Dictionary<string, Dictionary<KeyValuePair<int, string>, List<string>>> localized =
                    new Dictionary<string, Dictionary<KeyValuePair<int, string>, List<string>>>();
                Dictionary<string, Dictionary<KeyValuePair<int, string>, List<string>>> unlocalized =
                    new Dictionary<string, Dictionary<KeyValuePair<int, string>, List<string>>>();

                non_phospho_output = new StreamWriter(Path.Combine(outputFolder, "non_phospho.csv"));
                localized_phospho_output = new StreamWriter(Path.Combine(outputFolder, "localized_phospho.csv"));
                unlocalized_phospho_output = new StreamWriter(Path.Combine(outputFolder, "unlocalized_phospho.csv"));

                ProteinDictionary proteins = null;
                Dictionary<string, int> motifs = null;
                if (motifXOutput)
                {
                    proteins = new ProteinDictionary(motifXFastaProteinDatabaseFilepath);
                    motifs = new Dictionary<string, int>();
                    motifX = new StreamWriter(Path.Combine(outputFolder, "motif-x.txt"));
                }

                raw = (IXRawfile2) new MSFileReader_XRawfile();

                string header_line = null;
                string[] headers = null;
                bool quant = false;

                foreach (string csv_filepath in csvFilepaths)
                {
                    onStartingFile(new FilepathEventArgs(csv_filepath));

                    csv = new StreamReader(csv_filepath);

                    using (CsvReader reader = new CsvReader(csv, true))
                    {
                        headers = reader.GetFieldHeaders();

                        header_line = string.Join(",", headers);
                        quant = headers.Contains("Channels Detected");
                        string[] lineData = new string[headers.Length];
                        //header_line = csv.ReadLine();
                        //quant = header_line.Contains("TQ_");

                        non_phospho_output.WriteLine(header_line);
                        localized_phospho_output.WriteLine(header_line +
                                                           ", Number of Theoretical Fragments, Identified Phosphoisoform, Identified Phosphoisoform Number of Matching Fragments, Best Phosphoisoforms, Best Phosphoisoform, Best Phosphoisoform Number of Matching Fragments, Second-Best Phosphoisoform, Second-Best Phosphoisoform Number of Matching Fragments, Identified Phosphoisoform Correct?, Preliminary Localization of All Phosphorylations?, Peptide Phosphorylation Sites, Probability of Spurious Fragment Match, Number of Theoretical Site-Determining Fragment Ions, Number of Matching Site-Determining Fragment Ions, Matching Site-Determining Fragment Ions, Probability Values, Ambiguity Scores, Phosphorylation Sites Localized?, All Phosphorylation Sites Localized?");
                        unlocalized_phospho_output.WriteLine(header_line +
                                                             ", Number of Theoretical Fragments, Identified Phosphoisoform, Identified Phosphoisoform Number of Matching Fragments, Best Phosphoisoforms, Best Phosphoisoform, Best Phosphoisoform Number of Matching Fragments, Second-Best Phosphoisoform, Second-Best Phosphoisoform Number of Matching Fragments, Identified Phosphoisoform Correct?, Preliminary Localization of All Phosphorylations?, Peptide Phosphorylation Sites, Probability of Spurious Fragment Match, Number of Theoretical Site-Determining Fragment Ions, Number of Matching Site-Determining Fragment Ions, Matching Site-Determining Fragment Ions, Probability Values, Ambiguity Scores, Phosphorylation Sites Localized?, All Phosphorylation Sites Localized?");

                        while (reader.ReadNextRecord())
                        {
                            //string line = csv.ReadLine();

                            //string[] fields = Regex.Split(line,
                            //    @",(?!(?<=(?:^|,)\s*\x22(?:[^\x22]|\x22\x22|\\\x22)*,)(?:[^\x22]|\x22\x22|\\\x22)*\x22\s*(?:,|$))");
                            //    // crazy regex to parse CSV with internal double quotes from http://regexlib.com/REDetails.aspx?regexp_id=621

                            string sequence = reader["Peptide"];

                            string dynamic_modifications = reader["Mods"];
                            if (!dynamic_modifications.Contains("phosphorylation"))
                            {
                                //non_phospho_output.WriteLine(line);
                            }
                            else
                            {
                                Peptide identified_phosphopeptide = new Peptide(sequence, fixedModifications,
                                    dynamic_modifications);

                                int start_residue = int.Parse(reader["Start"]);
                                int stop_residue = int.Parse(reader["Stop"]);
                                string protein_description = reader["Defline"].Trim('"');

                                StringBuilder sb = new StringBuilder();
                                reader.CopyCurrentRecordTo(lineData);
                                foreach (string datum in lineData)
                                {
                                    if (datum.Contains(','))
                                        sb.Append("\"" + datum + "\"");
                                    else
                                        sb.Append(datum);
                                    sb.Append(',');
                                }
                                sb.Remove(sb.Length - 1, 1);
                                string line = sb.ToString();
                                if (!identified_sites_by_protein.ContainsKey(protein_description))
                                {
                                    identified_sites_by_protein.Add(protein_description, new Dictionary<string, int>());
                                }
                                foreach (KeyValuePair<int, string> kvp in identified_phosphopeptide.DynamicModifications)
                                {
                                    if (kvp.Value.Contains("phosphorylation"))
                                    {
                                        string site = sequence[kvp.Key - 1] + (start_residue + kvp.Key).ToString();

                                        if (!identified_sites_by_protein[protein_description].ContainsKey(site))
                                        {
                                            identified_sites_by_protein[protein_description].Add(site, 0);
                                        }
                                        identified_sites_by_protein[protein_description][site]++;
                                    }
                                }

                                int scan_number = int.Parse(reader["Spectrum number"]);
                                string filenameID = reader["Filename/id"];
                                FragmentType[] fragment_types = null;
                                if (filenameID.Contains(".ETD.") || filenameID.Contains(".ECD."))
                                {
                                    fragment_types = new FragmentType[] {FragmentType.c, FragmentType.zdot};
                                }
                                else
                                {
                                    fragment_types = new FragmentType[] {FragmentType.b, FragmentType.y};
                                }
                                string raw_filename = filenameID.Substring(0, filenameID.IndexOf('.')) + ".raw";
                                int charge = int.Parse(reader["Charge"]);

                                string current_raw_filename = null;
                                raw.GetFileName(ref current_raw_filename);

                                if (current_raw_filename == null ||
                                    !raw_filename.Equals(Path.GetFileName(current_raw_filename),
                                        StringComparison.InvariantCultureIgnoreCase))
                                {
                                    raw.Close();
                                    string[] raw_filepaths = null;
                                    if (!string.IsNullOrEmpty(rawFolder) && Directory.Exists(rawFolder))
                                    {
                                        raw_filepaths = Directory.GetFiles(rawFolder, raw_filename,
                                            SearchOption.AllDirectories);
                                    }
                                    else
                                    {
                                        raw_filepaths = Directory.GetFiles(Path.GetDirectoryName(csv_filepath),
                                            raw_filename, SearchOption.AllDirectories);
                                    }
                                    if (raw_filepaths.Length == 0)
                                    {
                                        throw new FileNotFoundException("No corresponding .raw file found for " +
                                                                        csv_filepath);
                                    }
                                    if (raw_filepaths.Length > 1)
                                    {
                                        throw new Exception("Multiple corresponding .raw files found for " +
                                                            csv_filepath);
                                    }
                                    raw.Open(raw_filepaths[0]);
                                    raw.SetCurrentController(0, 1);
                                }

                                string scan_filter = null;
                                raw.GetFilterForScanNum(scan_number, ref scan_filter);

                                string low_mz_scan_filter = scan_filter.Substring(scan_filter.IndexOf('[') + 1);
                                double low_mz =
                                    double.Parse(low_mz_scan_filter.Substring(0, low_mz_scan_filter.IndexOf('-')));
                                string high_mz_scan_filter = scan_filter.Substring(scan_filter.LastIndexOf('-') + 1);
                                double high_mz =
                                    double.Parse(high_mz_scan_filter.Substring(0, high_mz_scan_filter.IndexOf(']')));

                                double[,] spectrum = null;
                                if (scan_filter.Contains("FTMS"))
                                {
                                    object labels_obj = null;
                                    object flags_obj = null;
                                    raw.GetLabelData(ref labels_obj, ref flags_obj, ref scan_number);
                                    spectrum = (double[,]) labels_obj;
                                }
                                else
                                {
                                    double centroid_width = double.NaN;
                                    object spectrum_obj = null;
                                    object flags = null;
                                    int size = -1;
                                    raw.GetMassListFromScanNum(ref scan_number, null, 0, -1, 0, 1, ref centroid_width,
                                        ref spectrum_obj, ref flags, ref size);
                                    spectrum = (double[,]) spectrum_obj;
                                }

                                double base_peak_mz = double.NaN;
                                double base_peak_intensity = double.NaN;
                                for (int i = spectrum.GetLowerBound(1); i <= spectrum.GetUpperBound(1); i++)
                                {
                                    if (double.IsNaN(base_peak_mz) ||
                                        spectrum[(int) RawLabelDataColumn.Intensity, i] > base_peak_intensity)
                                    {
                                        base_peak_mz = spectrum[(int) RawLabelDataColumn.MZ, i];
                                        base_peak_intensity = spectrum[(int) RawLabelDataColumn.Intensity, i];
                                    }
                                }

                                double intensity_threshold = intensityThreshold;
                                if (intensityThresholdType == IntensityThresholdType.Relative)
                                {
                                    intensity_threshold = (intensityThreshold/100.0)*base_peak_intensity;
                                }

                                double[] parameters = new double[4];
                                if (!scan_filter.Contains("FTMS") &&
                                    intensityThresholdType == IntensityThresholdType.SignalToNoiseRatio)
                                {
                                    List<double> relative_intensities = new List<double>();
                                    for (int i = spectrum.GetLowerBound(1); i <= spectrum.GetUpperBound(1); i++)
                                    {
                                        relative_intensities.Add(spectrum[(int) RawLabelDataColumn.Intensity, i]/
                                                                 base_peak_intensity);
                                    }

                                    double bin_width = 0.001;
                                    int bins = 101;
                                    double[][] relative_intensity_histogram = new double[2][];
                                    relative_intensity_histogram[0] = new double[bins];
                                    relative_intensity_histogram[1] = new double[bins];
                                    for (int i = relative_intensity_histogram[0].GetLowerBound(0);
                                        i <= relative_intensity_histogram[0].GetUpperBound(0);
                                        i++)
                                    {
                                        relative_intensity_histogram[0][i] = i*bin_width;
                                    }
                                    foreach (double relative_intensity in relative_intensities)
                                    {
                                        int bin_number = (int) Math.Floor(relative_intensity/bin_width);
                                        if (bin_number < bins)
                                        {
                                            relative_intensity_histogram[1][bin_number]++;
                                        }
                                    }

                                    parameters[0] = 0.0;
                                    parameters[1] = 100.0;
                                    parameters[2] = 0.0;
                                    parameters[3] = 0.001;

                                    double[] weights = new double[relative_intensity_histogram[1].Length];
                                    for (int i = weights.GetLowerBound(0); i <= weights.GetUpperBound(0); i++)
                                    {
                                        weights[i] = 1.0;
                                    }
                                    LMA lma = new LMA(new GaussianFunctionWithPartials(), parameters,
                                        relative_intensity_histogram, weights, new DotNetMatrix.GeneralMatrix(4, 4),
                                        0.001, 5000);
                                    lma.Fit();
                                }

                                List<Peptide> peptides = GetAlternativePhosphoisoformPeptides(
                                    identified_phosphopeptide, fixedModifications);
                                List<PhosphopeptideStatistics> all_phosphopeptide_stats =
                                    new List<PhosphopeptideStatistics>(peptides.Count);
                                PhosphopeptideStatistics identified_phosphoisoform = null;
                                List<double> ms2_mz_peaks = new List<double>(spectrum.GetLength(1));
                                for (int i = spectrum.GetLowerBound(1); i <= spectrum.GetUpperBound(1); i++)
                                {
                                    double signal_to_noise = scan_filter.Contains("FTMS")
                                        ? (spectrum[(int) RawLabelDataColumn.Intensity, i] -
                                           spectrum[(int) RawLabelDataColumn.NoiseBaseline, i])/
                                          spectrum[(int) RawLabelDataColumn.NoiseLevel, i]
                                        : ((spectrum[(int) RawLabelDataColumn.Intensity, i]/base_peak_intensity) -
                                           parameters[2])/parameters[3];
                                    if ((intensityThresholdType == IntensityThresholdType.SignalToNoiseRatio
                                         && signal_to_noise >= intensity_threshold)
                                        || (intensityThresholdType != IntensityThresholdType.SignalToNoiseRatio
                                            && spectrum[(int) RawLabelDataColumn.Intensity, i] >= intensity_threshold))
                                    {
                                        ms2_mz_peaks.Add(spectrum[(int) RawLabelDataColumn.MZ, i]);
                                    }
                                }

                                double mz_range = high_mz - low_mz;

                                Dictionary<double, bool> searched_fragment_mzs = new Dictionary<double, bool>();
                                foreach (Peptide peptide in peptides)
                                {
                                    PhosphopeptideStatistics phosphopeptide_stats = new PhosphopeptideStatistics(peptide);
                                    if (peptide.Sequence == identified_phosphopeptide.Sequence)
                                    {
                                        identified_phosphoisoform = phosphopeptide_stats;
                                    }

                                    FragmentDictionary fragments = peptide.CalculateFragments(fragment_types);
                                    foreach (KeyValuePair<string, Fragment> kvp in fragments)
                                    {
                                        phosphopeptide_stats.Fragments.Add(kvp.Key, new Dictionary<int, bool>());

                                        for (int fragment_charge = 1;
                                            fragment_charge <= (charge >= 3 ? 2 : 1);
                                            fragment_charge++)
                                        {
                                            if (fragment_charge > 1 &&
                                                fragment_charge >
                                                (double) kvp.Value.Number/peptide.Sequence.Length*charge)
                                            {
                                                break;
                                            }

                                            double mz = MZFromMassAndCharge(kvp.Value.Mass, fragment_charge);

                                            if (mz < low_mz || mz > high_mz)
                                            {
                                                continue;
                                            }

                                            if (!searched_fragment_mzs.ContainsKey(mz))
                                            {
                                                bool found = false;

                                                foreach (double ms2_mz_peak in ms2_mz_peaks)
                                                {
                                                    if (Math.Abs(ms2_mz_peak - mz) <= mzTolerance)
                                                    {
                                                        found = true;
                                                        break;
                                                    }
                                                    else if (ms2_mz_peak > mz + mzTolerance)
                                                    {
                                                        break;
                                                    }
                                                }

                                                searched_fragment_mzs.Add(mz, found);
                                            }

                                            phosphopeptide_stats.Fragments[kvp.Key].Add(fragment_charge,
                                                searched_fragment_mzs[mz]);
                                        }
                                    }

                                    all_phosphopeptide_stats.Add(phosphopeptide_stats);
                                }

                                all_phosphopeptide_stats.Sort(ComparePhosphopeptidesByDescendingMatchingFragments);

                                PhosphopeptideStatistics best_phosphoisoform = all_phosphopeptide_stats[0];
                                PhosphopeptideStatistics second_best_phosphoisoform = all_phosphopeptide_stats.Count > 1
                                    ? all_phosphopeptide_stats[1]
                                    : null;

                                List<string> best_sequences = new List<string>();
                                foreach (PhosphopeptideStatistics phosphopeptide_stats in all_phosphopeptide_stats)
                                {
                                    if (phosphopeptide_stats.NumberOfMatchingFragments ==
                                        best_phosphoisoform.NumberOfMatchingFragments)
                                    {
                                        best_sequences.Add(phosphopeptide_stats.Peptide.Sequence);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                bool preliminary_localization = second_best_phosphoisoform == null
                                                                ||
                                                                best_phosphoisoform.NumberOfMatchingFragments >
                                                                second_best_phosphoisoform.NumberOfMatchingFragments;

                                bool all_sites_localized = preliminary_localization;

                                Dictionary<string, bool> peptide_sites = new Dictionary<string, bool>();
                                Dictionary<string, bool> protein_sites = new Dictionary<string, bool>();
                                string best_sequence = best_phosphoisoform.Peptide.Sequence;
                                for (int i = 0; i < best_sequence.Length; i++)
                                {
                                    if (char.IsLower(best_sequence[i]))
                                    {
                                        if (preliminary_localization && second_best_phosphoisoform == null)
                                        {
                                            peptide_sites.Add(best_sequence[i] + (i + 1).ToString(), true);
                                            protein_sites.Add(best_sequence[i] + (start_residue + i).ToString(), true);

                                            if (!localized_sites_by_protein.ContainsKey(protein_description))
                                            {
                                                localized_sites_by_protein.Add(protein_description,
                                                    new Dictionary<string, int>());
                                            }
                                            string site = best_sequence[i] + (start_residue + i).ToString();
                                            if (!localized_sites_by_protein[protein_description].ContainsKey(site))
                                            {
                                                localized_sites_by_protein[protein_description].Add(site, 0);
                                            }
                                            localized_sites_by_protein[protein_description][site]++;

                                            if (motifXOutput)
                                            {
                                                ExtractMotifs(motifs, proteins, protein_description, best_sequence,
                                                    start_residue, i);
                                            }
                                        }
                                        else
                                        {
                                            peptide_sites.Add(best_sequence[i] + (i + 1).ToString(), false);
                                            protein_sites.Add(best_sequence[i] + (start_residue + i).ToString(), false);
                                        }
                                    }
                                }

                                double probability_of_success = double.NaN;
                                List<string> theoretical_site_determining_fragment_ions = new List<string>();
                                List<string> matching_site_determining_fragment_ions = new List<string>();
                                List<string> left_site_determining_fragments = new List<string>();
                                List<string> right_site_determining_fragments = new List<string>();
                                List<string> site_determining_fragments = new List<string>();
                                List<string> p_values = new List<string>();
                                List<string> a_scores = new List<string>();
                                List<string> sites_localized = new List<string>();

                                if (preliminary_localization && second_best_phosphoisoform != null)
                                {
                                    probability_of_success = (ms2_mz_peaks.Count*2*mzTolerance)/mz_range;

                                    for (int i = 0; i < best_sequence.Length; i++)
                                    {
                                        if (char.IsLower(best_sequence[i]))
                                        {
                                            int first_phosphorylatable_residue = i - 1;
                                            while (first_phosphorylatable_residue >= 0)
                                            {
                                                if (best_sequence[first_phosphorylatable_residue] == 'S'
                                                    || best_sequence[first_phosphorylatable_residue] == 'T'
                                                    || best_sequence[first_phosphorylatable_residue] == 'Y')
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    first_phosphorylatable_residue--;
                                                }
                                            }

                                            int? num_left_theoretical_site_determining_fragment_ions = null;
                                            int? num_left_matching_site_determining_fragment_ions = null;
                                            double left_p_value = double.NaN;
                                            double left_a_score = double.NaN;
                                            if (first_phosphorylatable_residue >= 0)
                                            {
                                                num_left_theoretical_site_determining_fragment_ions = 0;
                                                num_left_matching_site_determining_fragment_ions = 0;

                                                for (int j = first_phosphorylatable_residue + 1; j <= i; j++)
                                                {
                                                    string n_terminal_fragment = fragment_types[0].ToString() +
                                                                                 j.ToString();
                                                    if (best_phosphoisoform.Fragments.ContainsKey(n_terminal_fragment))
                                                    {
                                                        foreach (
                                                            KeyValuePair<int, bool> kvp in
                                                                best_phosphoisoform.Fragments[n_terminal_fragment])
                                                        {
                                                            num_left_theoretical_site_determining_fragment_ions++;
                                                            if (kvp.Value)
                                                            {
                                                                num_left_matching_site_determining_fragment_ions++;
                                                                string n_terminal_fragment_string =
                                                                    n_terminal_fragment + "(+" + kvp.Key.ToString() +
                                                                    ')';
                                                                if (
                                                                    !left_site_determining_fragments.Contains(
                                                                        n_terminal_fragment_string))
                                                                {
                                                                    left_site_determining_fragments.Add(
                                                                        n_terminal_fragment_string);
                                                                }
                                                            }
                                                        }
                                                    }

                                                    string c_terminal_fragment = fragment_types[1].ToString() +
                                                                                 (best_sequence.Length - j).ToString();
                                                    if (best_phosphoisoform.Fragments.ContainsKey(c_terminal_fragment))
                                                    {
                                                        foreach (
                                                            KeyValuePair<int, bool> kvp in
                                                                best_phosphoisoform.Fragments[c_terminal_fragment])
                                                        {
                                                            num_left_theoretical_site_determining_fragment_ions++;
                                                            if (kvp.Value)
                                                            {
                                                                num_left_matching_site_determining_fragment_ions++;
                                                                string c_terminal_fragment_string =
                                                                    c_terminal_fragment + "(+" + kvp.Key.ToString() +
                                                                    ')';
                                                                if (
                                                                    !left_site_determining_fragments.Contains(
                                                                        c_terminal_fragment_string))
                                                                {
                                                                    left_site_determining_fragments.Add(
                                                                        c_terminal_fragment_string);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                left_p_value =
                                                    alglib.binomialdistr.binomialcdistribution(
                                                        num_left_matching_site_determining_fragment_ions.Value - 1,
                                                        num_left_theoretical_site_determining_fragment_ions.Value,
                                                        probability_of_success);
                                                left_a_score = -10*Math.Log10(left_p_value);
                                            }

                                            int last_phosphorylatable_residue = i + 1;
                                            while (last_phosphorylatable_residue < best_sequence.Length)
                                            {
                                                if (best_sequence[last_phosphorylatable_residue] == 'S'
                                                    || best_sequence[last_phosphorylatable_residue] == 'T'
                                                    || best_sequence[last_phosphorylatable_residue] == 'Y')
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    last_phosphorylatable_residue++;
                                                }
                                            }

                                            int? num_right_theoretical_site_determining_fragment_ions = null;
                                            int? num_right_matching_site_determining_fragment_ions = null;
                                            double right_p_value = double.NaN;
                                            double right_a_score = double.NaN;
                                            if (last_phosphorylatable_residue < best_sequence.Length)
                                            {
                                                num_right_theoretical_site_determining_fragment_ions = 0;
                                                num_right_matching_site_determining_fragment_ions = 0;

                                                for (int j = last_phosphorylatable_residue; j > i; j--)
                                                {
                                                    string n_terminal_fragment = fragment_types[0].ToString() +
                                                                                 j.ToString();
                                                    if (best_phosphoisoform.Fragments.ContainsKey(n_terminal_fragment))
                                                    {
                                                        foreach (
                                                            KeyValuePair<int, bool> kvp in
                                                                best_phosphoisoform.Fragments[n_terminal_fragment])
                                                        {
                                                            num_right_theoretical_site_determining_fragment_ions++;
                                                            if (kvp.Value)
                                                            {
                                                                num_right_matching_site_determining_fragment_ions++;
                                                                string n_terminal_fragment_string =
                                                                    n_terminal_fragment + "(+" + kvp.Key.ToString() +
                                                                    ')';
                                                                if (
                                                                    !right_site_determining_fragments.Contains(
                                                                        n_terminal_fragment_string))
                                                                {
                                                                    right_site_determining_fragments.Add(
                                                                        n_terminal_fragment_string);
                                                                }
                                                            }
                                                        }
                                                    }

                                                    string c_terminal_fragment = fragment_types[1].ToString() +
                                                                                 (best_sequence.Length - j).ToString();
                                                    if (best_phosphoisoform.Fragments.ContainsKey(c_terminal_fragment))
                                                    {
                                                        foreach (
                                                            KeyValuePair<int, bool> kvp in
                                                                best_phosphoisoform.Fragments[c_terminal_fragment])
                                                        {
                                                            num_right_theoretical_site_determining_fragment_ions++;
                                                            if (kvp.Value)
                                                            {
                                                                num_right_matching_site_determining_fragment_ions++;
                                                                string c_terminal_fragment_string =
                                                                    c_terminal_fragment + "(+" + kvp.Key.ToString() +
                                                                    ')';
                                                                if (
                                                                    !right_site_determining_fragments.Contains(
                                                                        c_terminal_fragment_string))
                                                                {
                                                                    right_site_determining_fragments.Add(
                                                                        c_terminal_fragment_string);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                right_p_value =
                                                    alglib.binomialdistr.binomialcdistribution(
                                                        num_right_matching_site_determining_fragment_ions.Value - 1,
                                                        num_right_theoretical_site_determining_fragment_ions.Value,
                                                        probability_of_success);
                                                right_a_score = -10*Math.Log10(right_p_value);
                                            }

                                            theoretical_site_determining_fragment_ions.Add(
                                                (num_left_theoretical_site_determining_fragment_ions.HasValue
                                                    ? num_left_theoretical_site_determining_fragment_ions.ToString()
                                                    : "n/a") + " | " +
                                                (num_right_theoretical_site_determining_fragment_ions.HasValue
                                                    ? num_right_theoretical_site_determining_fragment_ions.ToString()
                                                    : "n/a"));
                                            matching_site_determining_fragment_ions.Add(
                                                (num_left_matching_site_determining_fragment_ions.HasValue
                                                    ? num_left_matching_site_determining_fragment_ions.ToString()
                                                    : "n/a") + " | " +
                                                (num_right_matching_site_determining_fragment_ions.HasValue
                                                    ? num_right_matching_site_determining_fragment_ions.ToString()
                                                    : "n/a"));
                                            site_determining_fragments.Add((left_site_determining_fragments.Count > 0
                                                ? string.Join(",", left_site_determining_fragments.ToArray())
                                                : "n/a") + " | " +
                                                                           (right_site_determining_fragments.Count > 0
                                                                               ? string.Join(",",
                                                                                   right_site_determining_fragments
                                                                                       .ToArray())
                                                                               : "n/a"));
                                            p_values.Add((double.IsNaN(left_p_value) ? "n/a" : left_p_value.ToString()) +
                                                         " | " +
                                                         (double.IsNaN(right_p_value) ? "n/a" : right_p_value.ToString()));
                                            a_scores.Add((double.IsNaN(left_a_score) ? "n/a" : left_a_score.ToString()) +
                                                         " | " +
                                                         (double.IsNaN(right_a_score) ? "n/a" : right_a_score.ToString()));
                                            bool site_localized = (double.IsNaN(left_a_score) ||
                                                                   left_a_score >= ambiguityScoreThreshold) &&
                                                                  (double.IsNaN(right_a_score) ||
                                                                   right_a_score >= ambiguityScoreThreshold);
                                            sites_localized.Add(site_localized.ToString().ToUpper());
                                            if (site_localized)
                                            {
                                                peptide_sites[best_sequence[i] + (i + 1).ToString()] = true;
                                                protein_sites[best_sequence[i] + (start_residue + i).ToString()] = true;

                                                if (!localized_sites_by_protein.ContainsKey(protein_description))
                                                {
                                                    localized_sites_by_protein.Add(protein_description,
                                                        new Dictionary<string, int>());
                                                }
                                                string site = best_sequence[i] + (start_residue + i).ToString();
                                                if (!localized_sites_by_protein[protein_description].ContainsKey(site))
                                                {
                                                    localized_sites_by_protein[protein_description].Add(site, 0);
                                                }
                                                localized_sites_by_protein[protein_description][site]++;

                                                if (motifXOutput)
                                                {
                                                    ExtractMotifs(motifs, proteins, protein_description, best_sequence,
                                                        start_residue, i);
                                                }
                                            }
                                            if (!site_localized)
                                            {
                                                all_sites_localized = false;
                                            }
                                        }
                                    }
                                }

                                int phosphorylations = 0;
                                foreach (
                                    string dynamic_modification in
                                        best_phosphoisoform.Peptide.DynamicModifications.Values)
                                {
                                    if (dynamic_modification.Contains("phosphorylation"))
                                    {
                                        phosphorylations++;
                                    }
                                }
                                string isoform = null;
                                if (all_sites_localized)
                                {
                                    foreach (KeyValuePair<string, bool> kvp in protein_sites)
                                    {
                                        isoform += kvp.Key + ',';
                                    }
                                    isoform = isoform.Substring(0, isoform.Length - 1);
                                    KeyValuePair<int, string> isoform_kvp =
                                        new KeyValuePair<int, string>(phosphorylations, isoform);

                                    if (!localized.ContainsKey(protein_description))
                                    {
                                        localized.Add(protein_description,
                                            new Dictionary<KeyValuePair<int, string>, List<string>>());
                                    }
                                    if (!localized[protein_description].ContainsKey(isoform_kvp))
                                    {
                                        localized[protein_description].Add(isoform_kvp, new List<string>());
                                    }
                                    localized[protein_description][isoform_kvp].Add(line);
                                }
                                else
                                {
                                    if (preliminary_localization)
                                    {
                                        foreach (KeyValuePair<string, bool> kvp in protein_sites)
                                        {
                                            isoform += kvp.Key;
                                            if (!kvp.Value)
                                            {
                                                isoform += '?';
                                            }
                                            isoform += ',';
                                        }
                                    }
                                    else
                                    {
                                        for (int i = 0; i < best_sequence.Length; i++)
                                        {
                                            bool phospho = false;
                                            for (int j = 0; j < all_phosphopeptide_stats.Count; j++)
                                            {
                                                if (all_phosphopeptide_stats[j].NumberOfMatchingFragments <
                                                    best_phosphoisoform.NumberOfMatchingFragments)
                                                {
                                                    break;
                                                }

                                                if (char.IsLower(all_phosphopeptide_stats[j].Peptide.Sequence[i]))
                                                {
                                                    phospho = true;
                                                }
                                            }
                                            if (phospho)
                                            {
                                                isoform += char.ToLower(best_sequence[i]) +
                                                           (start_residue + i).ToString() + "?,";
                                            }
                                        }
                                    }
                                    isoform = isoform.Substring(0, isoform.Length - 1);
                                    KeyValuePair<int, string> isoform_kvp =
                                        new KeyValuePair<int, string>(phosphorylations, isoform);

                                    if (!unlocalized.ContainsKey(protein_description))
                                    {
                                        unlocalized.Add(protein_description,
                                            new Dictionary<KeyValuePair<int, string>, List<string>>());
                                    }
                                    if (!unlocalized[protein_description].ContainsKey(isoform_kvp))
                                    {
                                        unlocalized[protein_description].Add(isoform_kvp, new List<string>());
                                    }
                                    unlocalized[protein_description][isoform_kvp].Add(line);
                                }

                                StreamWriter output = all_sites_localized
                                    ? localized_phospho_output
                                    : unlocalized_phospho_output;

                                output.Write(line + ',');

                                output.Write(identified_phosphoisoform.NumberOfTotalFragments.ToString() + ',');

                                output.Write(identified_phosphoisoform.Peptide.Sequence + ',');
                                output.Write(identified_phosphoisoform.NumberOfMatchingFragments.ToString() + ',');

                                for (int s = 0; s < best_sequences.Count; s++)
                                {
                                    output.Write(best_sequences[s]);
                                    if (s < best_sequences.Count - 1)
                                    {
                                        output.Write('/');
                                    }
                                }
                                output.Write(',');

                                output.Write(best_phosphoisoform.Peptide.Sequence + ',');
                                output.Write(best_phosphoisoform.NumberOfMatchingFragments.ToString() + ',');

                                if (second_best_phosphoisoform != null)
                                {
                                    output.Write(second_best_phosphoisoform.Peptide.Sequence + ',');
                                    output.Write(second_best_phosphoisoform.NumberOfMatchingFragments.ToString() + ',');
                                }
                                else
                                {
                                    output.Write("n/a,n/a,");
                                }

                                output.Write(
                                    (identified_phosphoisoform.NumberOfMatchingFragments ==
                                     best_phosphoisoform.NumberOfMatchingFragments).ToString() + ',');

                                output.Write(preliminary_localization.ToString() + ',');

                                string[] peptide_sites_array = new string[peptide_sites.Count];
                                peptide_sites.Keys.CopyTo(peptide_sites_array, 0);
                                string peptide_sites_array_string = string.Join("; ", peptide_sites_array);
                                AppendFieldToCsv(peptide_sites_array_string, output);
                                output.Write((!double.IsNaN(probability_of_success)
                                    ? probability_of_success.ToString()
                                    : string.Empty) + ',');
                                string theoretical_site_determining_fragment_ions_string = string.Join("; ",
                                    theoretical_site_determining_fragment_ions.ToArray());
                                AppendFieldToCsv(theoretical_site_determining_fragment_ions_string, output);
                                string matching_site_determining_fragment_ions_string = string.Join("; ",
                                    matching_site_determining_fragment_ions.ToArray());
                                AppendFieldToCsv(matching_site_determining_fragment_ions_string, output);
                                string site_determining_fragments_string = string.Join("; ",
                                    site_determining_fragments.ToArray());
                                AppendFieldToCsv(site_determining_fragments_string, output);
                                string p_values_string = string.Join("; ", p_values.ToArray());
                                AppendFieldToCsv(p_values_string, output);
                                string a_scores_string = string.Join("; ", a_scores.ToArray());
                                AppendFieldToCsv(a_scores_string, output);
                                string sites_localized_string = string.Join("; ", sites_localized.ToArray());
                                AppendFieldToCsv(sites_localized_string, output);

                                output.Write(all_sites_localized.ToString().ToUpper());

                                output.WriteLine();
                            }

                            double progress = (double) csv.BaseStream.Position/csv.BaseStream.Length;
                            onUpdateProgress(new ProgressEventArgs((int) Math.Round(progress*100.0)));
                        }

                    }
                    csv.Close();

                    onFinishedFile(new EventArgs());
                }

                raw.Close();

                non_phospho_output.Close();
                localized_phospho_output.Close();
                unlocalized_phospho_output.Close();

                log.WriteLine("Identified Phosphoproteins: " + identified_sites_by_protein.Proteins.ToString());
                log.WriteLine("Identified Phosphosites: " + identified_sites_by_protein.Sites.ToString());

                log.WriteLine();

                log.WriteLine("Localized Phosphoproteins: " + localized_sites_by_protein.Proteins.ToString());
                log.WriteLine("Localized Phosphosites: " + localized_sites_by_protein.Sites.ToString());

                log.WriteLine();

                int localized_phosphoisoforms = 0;
                foreach (KeyValuePair<string, Dictionary<KeyValuePair<int, string>, List<string>>> kvp in localized)
                {
                    foreach (KeyValuePair<KeyValuePair<int, string>, List<string>> kvp2 in kvp.Value)
                    {
                        localized_phosphoisoforms++;
                    }
                }

                int unlocalized_phosphoisoforms = 0;
                foreach (KeyValuePair<string, Dictionary<KeyValuePair<int, string>, List<string>>> kvp in unlocalized)
                {
                    foreach (KeyValuePair<KeyValuePair<int, string>, List<string>> kvp2 in kvp.Value)
                    {
                        unlocalized_phosphoisoforms++;
                    }
                }

                log.WriteLine("Localized Phosphoisoforms: " + localized_phosphoisoforms.ToString());
                log.WriteLine("Unlocalized Phosphoisoforms: " + unlocalized_phosphoisoforms.ToString());

                log.Close();

                using (StreamWriter protein_sites = new StreamWriter(Path.Combine(outputFolder, "localized_protein_phosphosites.csv")))
                {
                    protein_sites.WriteLine("Protein Description, Number of Localized Phosphosites");
                    protein_sites.WriteLine(", Localized Phosphosite");

                    foreach (KeyValuePair<string, Dictionary<string, int>> kvp in localized_sites_by_protein)
                    {
                        protein_sites.WriteLine((kvp.Key.Contains(",") ? '"' + kvp.Key + '"' : kvp.Key) + ',' + kvp.Value.Count.ToString());
                        foreach (KeyValuePair<string, int> kvp2 in kvp.Value)
                        {
                            protein_sites.WriteLine(',' + kvp2.Key);
                        }
                    }
                }

                using (StreamWriter full_localized_output = new StreamWriter(Path.Combine(outputFolder, "full_localized_phosphoisoforms.csv")))
                {
                    //int interference_index = -1;
                    int first_quant_index = -1;
                    int last_quant_index = -1;
                    if (!quant)
                    {
                        full_localized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites, PSMs Identified, Peptides Identified");
                    }
                    else
                    {
                        full_localized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites, PSMs Identified, PSMs Quantified, Peptides Identified, Peptides Quantified,");
                        for (int i = 0; i < headers.Length; i++)
                        {
                            if (headers[i].EndsWith("NL)"))
                            {
                                if (first_quant_index < 0)
                                {
                                    first_quant_index = i;
                                }
                            }
                            if (first_quant_index >= 0)
                                full_localized_output.Write(' ' + headers[i] + ',');
                            if (headers[i].Equals("Channels Detected"))
                            {
                                last_quant_index = i;
                            }
                        }
                        full_localized_output.Write(" Phosphoisoform Quantified?");
                    }
                    full_localized_output.WriteLine();
                    full_localized_output.WriteLine(", " + header_line);

                    using (StreamWriter reduced_localized_output = new StreamWriter(Path.Combine(outputFolder, "reduced_localized_phosphoisoforms.csv")))
                    {
                        if (!quant)
                        {
                            reduced_localized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides , PSMs Identified, Peptides Identified");
                        }
                        else
                        {
                            reduced_localized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides , PSMs Identified, PSMs Quantified, Peptides Identified, Peptides Quantified,");
                            for (int i = first_quant_index; i <= last_quant_index; i++)
                            {
                                reduced_localized_output.Write(' ' + headers[i] + ',');
                            }
                            reduced_localized_output.Write(" Phosphoisoform Quantified?");
                        }
                        reduced_localized_output.WriteLine();

                        foreach (KeyValuePair<string, Dictionary<KeyValuePair<int, string>, List<string>>> kvp in localized)
                        {
                            foreach (KeyValuePair<KeyValuePair<int, string>, List<string>> kvp2 in kvp.Value)
                            {
                                full_localized_output.Write((kvp.Key.Contains(",") ? '"' + kvp.Key + '"' : kvp.Key) + ',');
                                reduced_localized_output.Write((kvp.Key.Contains(",") ? '"' + kvp.Key + '"' : kvp.Key) + ',');

                                full_localized_output.Write((kvp2.Key.Value.Contains(",") ? '"' + kvp2.Key.Value + '"' : kvp2.Key.Value) + ',');
                                reduced_localized_output.Write((kvp2.Key.Value.Contains(",") ? '"' + kvp2.Key.Value + '"' : kvp2.Key.Value) + ',');

                                full_localized_output.Write(kvp2.Key.Key.ToString() + ',');
                                reduced_localized_output.Write(kvp2.Key.Key.ToString() + ',');

                                double[] isoform_quantitation = new double[last_quant_index - first_quant_index + 1];
                                isoform_quantitation = Array.ConvertAll<double, double>(isoform_quantitation, SET_DOUBLE_VALUE_TO_NAN);
                                int spectra_identified = 0;
                                int spectra_quantified = 0;
                                Dictionary<string, int> unique_peptides_identified = new Dictionary<string, int>();
                                Dictionary<string, int> unique_peptides_quantified = new Dictionary<string, int>();
                                StringBuilder peptides = new StringBuilder();
                                foreach (string line in kvp2.Value)
                                {
                                    string[] fields = Regex.Split(line, @",(?!(?<=(?:^|,)\s*\x22(?:[^\x22]|\x22\x22|\\\x22)*,)(?:[^\x22]|\x22\x22|\\\x22)*\x22\s*(?:,|$))"); // crazy regex to parse CSV with internal double quotes from http://regexlib.com/REDetails.aspx?regexp_id=621
                                    spectra_identified++;
                                    string peptide_sequence = fields[2];
                                    peptides.Append(peptide_sequence + " ");
                                    if (!unique_peptides_identified.ContainsKey(peptide_sequence))
                                    {
                                        unique_peptides_identified.Add(peptide_sequence, 0);
                                    }
                                    unique_peptides_identified[peptide_sequence]++;
                                    if (quant)
                                    {

                                        spectra_quantified++;
                                        if (double.IsNaN(isoform_quantitation[0]))
                                        {
                                            isoform_quantitation = Array.ConvertAll<double, double>(isoform_quantitation, SET_DOUBLE_VALUE_TO_ZERO);
                                        }
                                        if (!unique_peptides_quantified.ContainsKey(peptide_sequence))
                                        {
                                            unique_peptides_quantified.Add(peptide_sequence, 0);
                                        }
                                        unique_peptides_quantified[peptide_sequence]++;
                                        for (int i = first_quant_index; i <= last_quant_index; i++)
                                        {
                                            double val = 0;
                                            double.TryParse(fields[i], out val);
                                            isoform_quantitation[i - first_quant_index] += val;
                                        }

                                    }
                                }

                                full_localized_output.Write(peptides.ToString() + ',');
                                reduced_localized_output.Write(peptides.ToString() + ',');

                                full_localized_output.Write(spectra_identified.ToString() + ',');
                                reduced_localized_output.Write(spectra_identified.ToString() + ',');
                                if (quant)
                                {
                                    full_localized_output.Write(spectra_quantified.ToString() + ',');
                                    reduced_localized_output.Write(spectra_quantified.ToString() + ',');
                                }
                                full_localized_output.Write(unique_peptides_identified.Count.ToString() + ',');
                                reduced_localized_output.Write(unique_peptides_identified.Count.ToString() + ',');
                                if (quant)
                                {
                                    full_localized_output.Write(unique_peptides_quantified.Count.ToString() + ',');
                                    reduced_localized_output.Write(unique_peptides_quantified.Count.ToString() + ',');
                                    for (int i = isoform_quantitation.GetLowerBound(0); i <= isoform_quantitation.GetUpperBound(0); i++)
                                    {
                                        full_localized_output.Write(isoform_quantitation[i].ToString() + ',');
                                        reduced_localized_output.Write(isoform_quantitation[i].ToString() + ',');
                                    }
                                    full_localized_output.Write((spectra_quantified > 0).ToString());
                                    reduced_localized_output.Write((spectra_quantified > 0).ToString());
                                }
                                full_localized_output.WriteLine();
                                reduced_localized_output.WriteLine();

                                foreach (string line in kvp2.Value)
                                {
                                    full_localized_output.WriteLine(',' + line);
                                }
                            }
                        }
                    }
                }

                using (StreamWriter full_unlocalized_output = new StreamWriter(Path.Combine(outputFolder, "full_unlocalized_phosphoisoforms.csv")))
                {
                    int first_quant_index = -1;
                    int last_quant_index = -1;
                    if (!quant)
                    {
                        full_unlocalized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides, PSMs Identified, Peptides Identified");
                    }
                    else
                    {
                        full_unlocalized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides, PSMs Identified, PSMs Quantified, Peptides Identified, Peptides Quantified,");
                        for (int i = 0; i < headers.Length; i++)
                        {
                            if (headers[i].EndsWith("NL)"))
                            {
                                if (first_quant_index < 0)
                                {
                                    first_quant_index = i;
                                }
                            }
                            if (first_quant_index >= 0)
                                full_unlocalized_output.Write(' ' + headers[i] + ',');
                            if (headers[i].Equals("Channels Detected"))
                            {
                                last_quant_index = i;
                            }
                        }
                        full_unlocalized_output.Write(" Phosphoisoform Quantified?");
                    }
                    full_unlocalized_output.WriteLine();
                    full_unlocalized_output.WriteLine(", " + header_line);

                    using (StreamWriter reduced_unlocalized_output = new StreamWriter(Path.Combine(outputFolder, "reduced_unlocalized_phosphoisoforms.csv")))
                    {
                        if (!quant)
                        {
                            reduced_unlocalized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides, PSMs Identified, Peptides Identified");
                        }
                        else
                        {
                            reduced_unlocalized_output.Write("Protein Description, Phosphoisoform, Phosphoisoform Sites,Peptides, PSMs Identified, PSMs Quantified, Peptides Identified, Peptides Quantified,");
                            for (int i = first_quant_index; i <= last_quant_index; i++)
                            {
                                reduced_unlocalized_output.Write(' ' + headers[i] + ',');
                            }
                            reduced_unlocalized_output.Write(" Phosphoisoform Quantified?");
                        }
                        reduced_unlocalized_output.WriteLine();

                        foreach (KeyValuePair<string, Dictionary<KeyValuePair<int, string>, List<string>>> kvp in unlocalized)
                        {
                            foreach (KeyValuePair<KeyValuePair<int, string>, List<string>> kvp2 in kvp.Value)
                            {
                                full_unlocalized_output.Write((kvp.Key.Contains(",") ? '"' + kvp.Key + '"' : kvp.Key) + ',');
                                reduced_unlocalized_output.Write((kvp.Key.Contains(",") ? '"' + kvp.Key + '"' : kvp.Key) + ',');

                                full_unlocalized_output.Write((kvp2.Key.Value.Contains(",") ? '"' + kvp2.Key.Value + '"' : kvp2.Key.Value) + ',');
                                reduced_unlocalized_output.Write((kvp2.Key.Value.Contains(",") ? '"' + kvp2.Key.Value + '"' : kvp2.Key.Value) + ',');

                                full_unlocalized_output.Write(kvp2.Key.Key.ToString() + ',');
                                reduced_unlocalized_output.Write(kvp2.Key.Key.ToString() + ',');

                                double[] isoform_quantitation = new double[last_quant_index - first_quant_index + 1];
                                isoform_quantitation = Array.ConvertAll<double, double>(isoform_quantitation, SET_DOUBLE_VALUE_TO_NAN);
                                int spectra_identified = 0;
                                int spectra_quantified = 0;
                                Dictionary<string, int> unique_peptides_identified = new Dictionary<string, int>();
                                Dictionary<string, int> unique_peptides_quantified = new Dictionary<string, int>();
                                StringBuilder peptides = new StringBuilder();
                                foreach (string line in kvp2.Value)
                                {
                                    string[] fields = Regex.Split(line, @",(?!(?<=(?:^|,)\s*\x22(?:[^\x22]|\x22\x22|\\\x22)*,)(?:[^\x22]|\x22\x22|\\\x22)*\x22\s*(?:,|$))"); // crazy regex to parse CSV with internal double quotes from http://regexlib.com/REDetails.aspx?regexp_id=621
                                    spectra_identified++;
                                    string peptide_sequence = fields[2];
                                    peptides.Append(peptide_sequence + " ");
                                    if (!unique_peptides_identified.ContainsKey(peptide_sequence))
                                    {
                                        unique_peptides_identified.Add(peptide_sequence, 0);
                                    }
                                    unique_peptides_identified[peptide_sequence]++;
                                    if (quant)
                                    {
                                        spectra_quantified++;
                                        if (double.IsNaN(isoform_quantitation[0]))
                                        {
                                            isoform_quantitation = Array.ConvertAll<double, double>(isoform_quantitation, SET_DOUBLE_VALUE_TO_ZERO);
                                        }
                                        if (!unique_peptides_quantified.ContainsKey(peptide_sequence))
                                        {
                                            unique_peptides_quantified.Add(peptide_sequence, 0);
                                        }
                                        unique_peptides_quantified[peptide_sequence]++;
                                        for (int i = first_quant_index; i <= last_quant_index; i++)
                                        {
                                            double val = 0;
                                            double.TryParse(fields[i], out val);
                                            isoform_quantitation[i - first_quant_index] += val;
                                        }

                                    }
                                }

                                full_unlocalized_output.Write(peptides.ToString() + ',');
                                reduced_unlocalized_output.Write(peptides.ToString() + ',');

                                full_unlocalized_output.Write(spectra_identified.ToString() + ',');
                                reduced_unlocalized_output.Write(spectra_identified.ToString() + ',');
                                if (quant)
                                {
                                    full_unlocalized_output.Write(spectra_quantified.ToString() + ',');
                                    reduced_unlocalized_output.Write(spectra_quantified.ToString() + ',');
                                }
                                full_unlocalized_output.Write(unique_peptides_identified.Count.ToString() + ',');
                                reduced_unlocalized_output.Write(unique_peptides_identified.Count.ToString() + ',');
                                if (quant)
                                {
                                    full_unlocalized_output.Write(unique_peptides_quantified.Count.ToString() + ',');
                                    reduced_unlocalized_output.Write(unique_peptides_quantified.Count.ToString() + ',');
                                    for (int i = isoform_quantitation.GetLowerBound(0); i <= isoform_quantitation.GetUpperBound(0); i++)
                                    {
                                        full_unlocalized_output.Write(isoform_quantitation[i].ToString() + ',');
                                        reduced_unlocalized_output.Write(isoform_quantitation[i].ToString() + ',');
                                    }
                                    full_unlocalized_output.Write((spectra_quantified > 0).ToString());
                                    reduced_unlocalized_output.Write((spectra_quantified > 0).ToString());
                                }
                                full_unlocalized_output.WriteLine();
                                reduced_unlocalized_output.WriteLine();

                                foreach (string line in kvp2.Value)
                                {
                                    full_unlocalized_output.WriteLine(',' + line);
                                }
                            }
                        }
                    }
                }

                if (motifXOutput)
                {
                    foreach (string motif in motifs.Keys)
                    {
                        motifX.WriteLine(motif);
                    }
                    motifX.Close();

                    using (StreamWriter motif_fasta = new StreamWriter(Path.Combine(outputFolder, "motif-x.fasta")))
                    {
                        foreach (KeyValuePair<string, string> kvp in proteins)
                        {
                            if (!kvp.Key.Contains("DECOY") && !kvp.Key.Contains("REVERSED"))
                            {
                                motif_fasta.WriteLine('>' + kvp.Key);
                                motif_fasta.WriteLine(kvp.Value);
                            }
                        }
                    }
                }

                onFinished(new EventArgs());
                //}
                //catch(Exception ex)
                //{
                //    onThrowException(new ExceptionEventArgs(ex));
                //}
                //finally
                //{
                if (log != null)
                {
                    log.Close();
                }
                if (raw != null)
                {
                    raw.Close();
                }
                if (csv != null)
                {
                    csv.Close();
                }
                if (non_phospho_output != null)
                {
                    non_phospho_output.Close();
                }
                if (localized_phospho_output != null)
                {
                    localized_phospho_output.Close();
                }
                if (unlocalized_phospho_output != null)
                {
                    unlocalized_phospho_output.Close();
                }
                if (motifX != null)
                {
                    motifX.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + " " + e.StackTrace);
            }
}
コード例 #6
0
        public void Produto2500Teste()
        {
            LMAFunction f = new FuncaoGaussianaAcumulada();

            double[] parametrosEstimados = new[] { 0.111989183, 0.735 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.12,
                0.14,
                0.16,
                0.18,
                0.2,
                0.22,
                0.24,
                0.26,
                0.28,
                0.3,
                0.32,
                0.34,
                0.36,
                0.38,
                0.4,
                0.42,
                0.44,
                0.46,
                0.48,
                0.5,
                0.52,
                0.54,
                0.56,
                0.58,
                0.6,
                0.62,
                0.64,
                0.66,
                0.68,
                0.7,
                0.72,
                0.74,
                0.76,
                0.78,
                0.8,
                0.82,
                0.84,
                0.86,
                0.88,
                0.9,
                0.92,
                0.94,
                0.96
            };

            double[] yExperimental = new[]
            {
                0,
                0,
                0.03472,
                0.06644,
                0.09601,
                0.12272,
                0.14793,
                0.17208,
                0.19535,
                0.21753,
                0.23669,
                0.25444,
                0.27351,
                0.29654,
                0.32522,
                0.35796,
                0.39288,
                0.42818,
                0.46214,
                0.4953,
                0.52848,
                0.56211,
                0.59659,
                0.63314,
                0.67136,
                0.70917,
                0.74448,
                0.77573,
                0.80428,
                0.83035,
                0.85386,
                0.87476,
                0.89255,
                0.90755,
                0.92063,
                0.93257,
                0.94395,
                0.95415,
                0.96302,
                0.97057,
                0.97682,
                0.98124,
                0.98433,
                0.98668,
                0.98884,
                0.9908,
                0.9916,
                0.99404,
                0.99706
            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(2, 2), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #7
0
        public void Produto1724Teste()
        {
            LMAFunction f = new FuncaoGaussianaAcumulada();

            double[] parametrosEstimados = new[] { 0.111989183, 0.735 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.12,
                0.14,
                0.16,
                0.18,
                0.2,
                0.22,
                0.24,
                0.26,
                0.28,
                0.3,
                0.32,
                0.34,
                0.36,
                0.38,
                0.4,
                0.42,
                0.44,
                0.46,
                0.48,
                0.5,
                0.52,
                0.54,
                0.56,
                0.58,
                0.6,
                0.62,
                0.64,
                0.66,
                0.68,
                0.7,
                0.72,
                0.74,
                0.76,
                0.78,
                0.8,
                0.82,
                0.84,
                0.86,
                0.88,
                0.9,
                0.92,
                0.94,
                0.96
            };

            double[] yExperimental = new[]
            {
                0,
                0,
                0.01558,
                0.02839,
                0.04047,
                0.05091,
                0.05979,
                0.06895,
                0.07986,
                0.09401,
                0.11091,
                0.12986,
                0.15061,
                0.17297,
                0.19653,
                0.22114,
                0.2478,
                0.27755,
                0.31163,
                0.35184,
                0.396,
                0.44082,
                0.48298,
                0.52204,
                0.55988,
                0.59661,
                0.63235,
                0.66734,
                0.70202,
                0.73575,
                0.7677,
                0.79702,
                0.82366,
                0.84807,
                0.87005,
                0.88941,
                0.90594,
                0.91933,
                0.92999,
                0.93881,
                0.94672,
                0.95361,
                0.95951,
                0.96473,
                0.96941,
                0.97359,
                0.97704,
                0.97868,
                0.97878
            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(2, 2), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #8
0
        public void Produto0952Teste()
        {
            LMAFunction f = new FuncaoGaussianaAcumulada();

            double[] parametrosEstimados = new[] { 0.111989183, 0.735 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.12,
                0.14,
                0.16,
                0.18,
                0.2,
                0.22,
                0.24,
                0.26,
                0.28,
                0.3,
                0.32,
                0.34,
                0.36,
                0.38,
                0.4,
                0.42,
                0.44,
                0.46,
                0.48,
                0.5,
                0.52,
                0.54,
                0.56,
                0.58,
                0.6,
                0.62,
                0.64,
                0.66,
                0.68,
                0.7,
                0.72,
                0.74,
                0.76,
                0.78,
                0.8,
                0.82,
                0.84,
                0.86,
                0.88,
                0.9,
                0.92,
                0.94,
                0.96
            };

            double[] yExperimental = new[]
            {
                0,
                0.00608,
                0.01391,
                0.02146,
                0.02825,
                0.03357,
                0.03764,
                0.04171,
                0.04676,
                0.05379,
                0.06234,
                0.07212,
                0.08319,
                0.09557,
                0.10882,
                0.12271,
                0.13817,
                0.15615,
                0.17769,
                0.20325,
                0.23188,
                0.2624,
                0.29354,
                0.32523,
                0.35833,
                0.39221,
                0.42622,
                0.45978,
                0.49319,
                0.52665,
                0.56012,
                0.59358,
                0.62763,
                0.66244,
                0.69672,
                0.72918,
                0.75868,
                0.78573,
                0.81087,
                0.83445,
                0.85676,
                0.87774,
                0.89717,
                0.91506,
                0.93141,
                0.94569,
                0.95773,
                0.96857,
                0.97905

            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(2, 2), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #9
0
        public void FeedTeste()
        {
            LMAFunction f = new FuncaoGaussianaAcumulada();

            double[] parametrosEstimados = new[] { 0.111989183, 0.735 };
            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.12,
                0.14,
                0.16,
                0.18,
                0.2,
                0.22,
                0.24,
                0.26,
                0.28,
                0.3,
                0.32,
                0.34,
                0.36,
                0.38,
                0.4,
                0.42,
                0.44,
                0.46,
                0.48,
                0.5,
                0.52,
                0.54,
                0.56,
                0.58,
                0.6,
                0.62,
                0.64,
                0.66,
                0.68,
                0.7,
                0.72,
                0.74,
                0.76,
                0.78,
                0.8,
                0.82,
                0.84,
                0.86,
                0.88,
                0.9,
                0.92,
                0.94,
                0.96
            };

            double[] yExperimental = new[]
            {
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0.02532,
                0.03191,
                0.03557,
                0.03855,
                0.04199,
                0.05473,
                0.07439,
                0.09963,
                0.1324,
                0.17218,
                0.222,
                0.2795,
                0.34357,
                0.41488,
                0.48759,
                0.55907,
                0.62985,
                0.69556,
                0.75486,
                0.8067,
                0.85443,
                0.89529,
                0.9253,
                0.94629,
                0.96257,
                0.97404,
                0.98309
            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(parametrosEstimados.Length, parametrosEstimados.Length), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #10
0
        public void Produto0383Teste()
        {
            LMAFunction f = new FuncaoGaussianaAcumulada();

            double[] parametrosEstimados = new[] { 0.111989183, 0.735 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.12,
                0.14,
                0.16,
                0.18,
                0.2,
                0.22,
                0.24,
                0.26,
                0.28,
                0.3,
                0.32,
                0.34,
                0.36,
                0.38,
                0.4,
                0.42,
                0.44,
                0.46,
                0.48,
                0.5,
                0.52,
                0.54,
                0.56,
                0.58,
                0.6,
                0.62,
                0.64,
                0.66,
                0.68,
                0.7,
                0.72,
                0.74,
                0.76,
                0.78,
                0.8,
                0.82,
                0.84,
                0.86,
                0.88,
                0.9,
                0.92,
                0.94,
                0.96
            };

            double[] yExperimental = new[]
            {
                0,
                0,
                0.00874,
                0.0121,
                0.01537,
                0.01847,
                0.02116,
                0.02346,
                0.02575,
                0.02838,
                0.03166,
                0.0356,
                0.03978,
                0.04442,
                0.04979,
                0.05615,
                0.06377,
                0.07248,
                0.08224,
                0.09298,
                0.10462,
                0.11696,
                0.12955,
                0.14288,
                0.15755,
                0.17419,
                0.1933,
                0.21393,
                0.23625,
                0.26089,
                0.28852,
                0.31983,
                0.35482,
                0.39311,
                0.43451,
                0.47878,
                0.52576,
                0.57747,
                0.63319,
                0.69075,
                0.74798,
                0.802,
                0.85845,
                0.91109,
                0.94528,
                0.96223,
                0.97008,
                0.97396,
                0.97589

            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(2, 2), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #11
0
        public void Produto0383Teste()
        {
            var tempo = Math.Exp(0.383);

            FuncaoHidrocraqueamento f = new FuncaoHidrocraqueamento(8, 0.688622664823698, 0.186665545625228);

            f.mensagens = escreverMensagens;

            double alfa = 1.35;
            double kMax = 1.35; //1/hora;
            double a0 = 6.41;
            double a1 = 28.15;
            double delta = 2.6667e-5;

            double[] parametrosSugeridos = new[] {a0,a1};

            #region dmom/dt Calculados a partir da média e desvio padrão conhecidos (calculados)

            double[] xExperimental = new[] //Ordem do polinomio
            {
                0.0,
                1.0,
                2.0,
                3.0,
                4.0,
                5.0,
                6.0,
                7.0,
                8.0,
                9.0,
                10.0,
                11.0,
                12.0,
                13.0,
                14.0,
                15.0
            };

            double[] yExperimental = new[]
            {
                0.0,
                -0.169853777,
                -0.193208729,
                -0.169711401,
                -0.134584682,
                -0.100332106,
                -0.070889307,
                -0.046939058,
                -0.02800316,
                -0.013274678,
                -0.001938629,
                0.006717949,
                0.013281326,
                0.018218895,
                0.021897241,
                0.024601441
            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(escreverMensagens, f, parametrosSugeridos,
                dataPoints, null, new GeneralMatrix(parametrosSugeridos.Length, parametrosSugeridos.Length), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosSugeridos.Length; i++)
            {
                escreverMensagens("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #12
0
        public void LaxminaraEstimationTeste()
        {
            LaxminaraTeste f = new LaxminaraTeste(null);

            double alfa = 1.35;
            double kMax = 1.35; //1/hora;
            double a0 = 6.41;
            double a1 = 28.15;
            double delta = 2.6667e-5;

            double[] parametrosSugeridos = new[] {alfa, kMax,a0,a1};

            #region Dados Experimentais

            double[] xExperimental = new[] //Ordem do polinomio
            {
                0.0,
                1.0,
                2.0,
                3.0,
                4.0,
                5.0,
                6.0,
                7.0,
                8.0,
                9.0,
                10.0,
                11.0

            };

            double[] yExperimental = new[]
            {
                1.0,
            0.72317444741327097,
            0.53437823495320125,
            0.40292206645505568	,
            0.30958307055555123,
            0.24207872555219578	,
            0.192409225454721	,
            0.15526760641360315	,
            0.12707117279007443	,
            0.10536080255783097	,
            0.088421883423926081,
            0.075041064810312863

            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(escreverMensagens, f, parametrosSugeridos,
                dataPoints, null, new GeneralMatrix(parametrosSugeridos.Length, parametrosSugeridos.Length), 1d - 30,
                100);

            algorithm.Fit();

            for (int i = 0; i < parametrosSugeridos.Length; i++)
            {
                escreverMensagens("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #13
0
        public void FeedTeste()
        {
            LMAFunction f = new FuncaoGama();

            double[] parametrosEstimados = new[] { 1.0, 10, 0.3 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                0,
                0.05,
                0.1,
                0.15,
                0.2,
                0.25,
                0.3,
                0.35,
                0.4,
                0.43,
                0.45,
                0.47,
                0.49,
                0.51,
                0.53,
                0.55,
                0.57,
                0.59,
                0.61,
                0.63,
                0.65,
                0.67,
                0.69,
                0.71,
                0.73,
                0.75,
                0.77,
                0.79,
                0.81,
                0.83,
                0.85,
                0.87,
                0.89,
                0.91,
                0.93,
                0.95,
                0.97,
                1
            };

            double[] yExperimental = new[]
            {
                0,
                0.000477354,
                0.000954709,
                0.001432063,
                0.001909417,
                0.002386771,
                0.002864126,
                0.00334148,
                0.003818834,
                0.004105247,
                0.00777,
                0.00485,
                0.0031,
                0.00267,
                0.00787,
                0.01618,
                0.02244,
                0.02912,
                0.03585,
                0.04481,
                0.05397,
                0.0607,
                0.06801,
                0.07284,
                0.0717,
                0.07164,
                0.0687,
                0.0627,
                0.05525,
                0.04971,
                0.04483,
                0.03567,
                0.02498,
                0.01816,
                0.01397,
                0.00995,
                0.00872,
                0.01255
            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(3, 3), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }
コード例 #14
0
        public void FeedAdam2012Teste()
        {
            LMAFunction f = new FuncaoGama();

            double[] parametrosEstimados = new[] {110 ,6.0, 2.0, 10.0 };

            #region Dados Experimentais

            double[] xExperimental = new[]
            {
                6,
                6.5,
                7,
                7.5,
                8,
                8.5,
                9,
                9.5,
                10,
                10.5,
                11,
                11.5,
                12,
                12.5,
                13,
                13.5,
                14,
                14.5,
                15,
                15.5,
                16,
                16.5,
                17,
                17.5,
                18,
                18.5,
                19,
                19.5,
                20,
                20.5,
                21,
                21.5,
                22,
                22.5,
                23,
                23.5,
                24,
                24.5,
                25,
                25.5,
                26,
                26.5,
                27,
                27.5,
                28,
                28.5,
                29,
                29.5,
                30,
                30.5,
                31,
                31.5,
                32,
                32.5,
                33,
                33.5,
                34,
                34.5,
                35,
                35.5,
                36,
                36.5,
                37,
                37.5,
                38,
                38.5,
                39,
                39.5,
                40,
                40.5,
                41,
                41.5,
                42,
                42.5,
                43,
                43.5,
                44,
                44.5,
                45,
                45.5,
                46,
                46.5,
                47,
                47.5,
                48,
                48.5,
                49,
                49.5,
                50,
                50.5,
                51,
                51.5,
                52,
                52.5,
                53,
                53.5,
                54,
                54.5,
                55,
                55.5,
                56,
                56.5,
                57,
                57.5,
                58,
                58.5,
                59,
                59.5,
                60,
                60.5,
                61,
                61.5,
                62,
                62.5,
                63,
                63.5,
                64,
                64.5,
                65,
                65.5,
                66,
                66.5,
                67,
                67.5,
                68,
                68.5,
                69,
                69.5

            };

            double[] yExperimental = new[]
            {
                0.05038,
                0.26068,
                0.63623,
                0.98765,
                1.34988,
                1.70814,
                2.07049,
                2.46031,
                2.8452,
                3.13967,
                3.36847,
                3.54668,
                3.69239,
                3.81627,
                3.90255,
                3.94637,
                3.96881,
                3.99722,
                4.01619,
                4.00553,
                3.98141,
                3.95254,
                3.91177,
                3.89293,
                3.90277,
                3.85827,
                3.76256,
                3.70522,
                3.65271,
                3.58838,
                3.51878,
                3.45647,
                3.40999,
                3.37829,
                3.35271,
                3.34001,
                3.34441,
                3.30962,
                3.26256,
                3.22453,
                3.16822,
                2.77531,
                2.21383,
                2.44192,
                2.65645,
                2.5645,
                2.39322,
                2.26306,
                2.13443,
                2.00384,
                1.87456,
                1.76221,
                1.66783,
                1.59939,
                1.54273,
                1.47008,
                1.41341,
                1.4354,
                1.43696,
                1.39685,
                1.34782,
                1.30362,
                1.26077,
                1.22248,
                1.18638,
                1.14808,
                1.11094,
                1.11799,
                1.11113,
                1.03607,
                0.96056,
                0.935,
                0.95218,
                0.95174,
                0.92821,
                0.90443,
                0.87775,
                0.80971,
                0.72396,
                0.72258,
                0.74405,
                0.669,
                0.57887,
                0.54087,
                0.51708,
                0.49078,
                0.46682,
                0.44668,
                0.43057,
                0.41281,
                0.39397,
                0.37357,
                0.35218,
                0.33123,
                0.31164,
                0.29456,
                0.27949,
                0.26638,
                0.25576,
                0.24709,
                0.23974,
                0.23362,
                0.22827,
                0.22338,
                0.21878,
                0.21436,
                0.21001,
                0.20563,
                0.20107,
                0.19675,
                0.19276,
                0.18892,
                0.18502,
                0.18077,
                0.17552,
                0.16389,
                0.14573,
                0.19372,
                0.2433,
                0.22274,
                0.18939,
                0.15281,
                0.11896,
                0.09803,
                0.08244,
                0.06956,
                0.05915,
                0.05214

            };

            #endregion

            double[][] dataPoints = new double[2][];

            dataPoints[0] = xExperimental;
            dataPoints[1] = yExperimental;

            Net.Kniaz.LMA.LMA algorithm = new Net.Kniaz.LMA.LMA(f, parametrosEstimados,
                dataPoints, null, new GeneralMatrix(parametrosEstimados.Length, parametrosEstimados.Length), 1d - 30, 100);

            algorithm.Fit();

            for (int i = 0; i < parametrosEstimados.Length; i++)
            {
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }
        }