示例#1
0
        private void UpdateModsListboxes()
        {
            lstAllModifications.Items.Clear();
            lstSelectedFixedModifications.Items.Clear();

            lstAllModifications.DisplayMember           = "Text";
            lstSelectedFixedModifications.DisplayMember = "Text";
            List <OmssaModification> allMods = OmssaModification.GetAllModifications().ToList();

            foreach (OmssaModification modification in allMods.OrderByDescending(mod => mod.Name.Contains("*")).ThenBy(mod => mod.Name))
            {
                string text = (modification.UserMod) ? "*" :"";
                text += modification.ToString();
                ListViewItem list_view_item = new ListViewItem(text)
                {
                    Tag = modification
                };
                if (modification.Name == "carbamidomethyl C")
                {
                    lstSelectedFixedModifications.Items.Add(list_view_item);
                }
                else
                {
                    lstAllModifications.Items.Add(list_view_item);
                }
            }
        }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (ofdModsXml.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         OmssaModification.LoadOmssaModifications(ofdModsXml.FileName, true);
         UpdateModsListboxes();
     }
 }
示例#3
0
        public void Convert(string omssaCSV, MSDataFile dataFile)
        {
            string filePath = Path.ChangeExtension(omssaCSV, ".pepxml");

            using (PepXmlWriter writer = new PepXmlWriter(filePath))
            {
                writer.WriteSampleProtease(Protease);

                writer.StartSearchSummary("OMSSA", true, true);

                writer.WriteProteinDatabase(FastaDatabaseFile);

                writer.WriteSearchProtease(Protease, MissedClevages);

                foreach (int modNumber in FixedMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, true);
                    }
                }

                foreach (int modNumber in VariableMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, false);
                    }
                }


                writer.SetCurrentStage(PepXmlWriter.Stage.Spectra, true);

                using (OmssaCsvPsmReader reader = new OmssaCsvPsmReader(omssaCSV, UserModFile))
                {
                    reader.AddMSDataFile(dataFile);
                    reader.LoadProteins(FastaDatabaseFile);
                    foreach (PeptideSpectralMatch psm in reader.ReadNextPsm())
                    {
                        writer.StartSpectrum(psm.SpectrumNumber, psm.Spectrum.RetentionTime, psm.Spectrum.PrecursorMz, psm.Spectrum.PrecursorCharge);
                        writer.WritePSM(psm);
                        writer.EndSpectrum();
                    }
                }
            }
        }
示例#4
0
        public void LoadUserMods(string userModFile)
        {
            OmssaModification.LoadOmssaModifications(userModFile, true);

            listBox1.Items.Clear();
            listBox2.Items.Clear();
            foreach (OmssaModification mod in OmssaModification.GetAllModifications())
            {
                if (mod.Name.Equals("carbamidomethyl C"))
                {
                    listBox2.Items.Add(mod);
                }
                else
                {
                    listBox1.Items.Add(mod);
                }
            }
        }
示例#5
0
        private void AdditionalSetup()
        {
            Text = string.Format("Lotor ({0})", GetRunningVersion());

            comboBox1.DataSource   = Enum.GetValues(typeof(ToleranceUnit));
            comboBox1.SelectedItem = ToleranceUnit.DA;

            foreach (OmssaModification mod in OmssaModification.GetAllModifications())
            {
                if (mod.Name == "carbamidomethyl C")
                {
                    listBox2.Items.Add(mod);
                }
                else
                {
                    listBox1.Items.Add(mod);
                }
            }
        }
示例#6
0
        private void frmMain_DragDrop(object sender, DragEventArgs e)
        {
            string[] filepaths = (string[])e.Data.GetData(DataFormats.FileDrop);

            foreach (string filepath in filepaths)
            {
                if (Path.GetExtension(filepath).Equals(".csv", StringComparison.InvariantCultureIgnoreCase) &&
                    !lstOmssaCsvFiles.Items.Contains(filepath))
                {
                    lstOmssaCsvFiles.Items.Add(filepath);
                    UpdateOutputFolder(filepath);
                    UpdateRawFolder(filepath);
                }
                else if (Path.GetExtension(filepath).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
                {
                    OmssaModification.LoadOmssaModifications(filepath, true);
                    UpdateModsListboxes();
                }
            }
        }
示例#7
0
        private void UpdateVariableMods()
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                return;
            }
            _variableModifications.Clear();

            using (CsvReader reader = new CsvReader(new StreamReader(textBox1.Text), true))
            {
                while (reader.ReadNextRecord())
                {
                    foreach (
                        Tuple <string, int> modName in
                        OmssaModification.SplitModificationLine(reader["Mods"]))
                    {
                        _variableModifications.Add(modName.Item1);
                    }
                }
            }

            bool phospho = true;

            checkedListBox1.Items.Clear();
            foreach (string modName in _variableModifications)
            {
                if (modName.Contains("phosphorylation"))
                {
                    if (phospho)
                    {
                        checkedListBox1.Items.Add(Phosphorylation.Name);
                        phospho = false;
                    }
                    OmssaModification.GroupedModifications.Add(modName, Phosphorylation);
                }
                else
                {
                    checkedListBox1.Items.Add(modName);
                }
            }
        }
示例#8
0
文件: PSM.cs 项目: trishorts/Compass
 public void SetSequenceAndMods(string sequence, IList <Modification> fixedMods, string variableMods)
 {
     Peptide = new CSMSL.Proteomics.Peptide(sequence);
     Peptide.SetModifications(fixedMods);
     Modificationstring = variableMods;
     foreach (Tuple <Modification, int> modTuple in OmssaModification.ParseModificationLine(variableMods))
     {
         Modification mod  = modTuple.Item1;
         int          site = modTuple.Item2;
         if (site == 1 && mod.Sites.HasFlag(ModificationSites.NPep))
         {
             Peptide.AddModification(mod, Terminus.N);
         }
         else if (site == Peptide.Length && mod.Sites.HasFlag(ModificationSites.PepC))
         {
             Peptide.AddModification(mod, Terminus.C);
         }
         else
         {
             Peptide.AddModification(mod, site);
         }
     }
 }
示例#9
0
        private List <PSM> LoadAllPSMs(string csvFile, string rawFileDirectory, List <Modification> fixedMods)
        {
            ProgressUpdate(0.0); //force the progressbar to go into marquee mode
            Log("Reading PSMs from " + csvFile);

            Dictionary <string, ThermoRawFile> rawFiles =
                Directory.EnumerateFiles(rawFileDirectory, "*.raw", SearchOption.AllDirectories)
                .ToDictionary(Path.GetFileNameWithoutExtension, file => new ThermoRawFile(file));

            _dataFiles = new HashSet <MSDataFile>();

            List <PSM> psms = new List <PSM>();

            int totalPsms = 0;

            using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true))
            {
                while (reader.ReadNextRecord())
                {
                    string mods = reader["Mods"];

                    totalPsms++;

                    // Skip if there are no modifications
                    if (string.IsNullOrEmpty(mods))
                    {
                        continue;
                    }

                    // Convert the text mod line into a list of modification objects
                    List <Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).ToList();

                    // Only keep things with quantified Modifications
                    if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod)))
                    {
                        continue;
                    }

                    string filename = reader["Filename/id"];
                    string rawname  = filename.Split('.')[0];

                    int scanNumber = int.Parse(reader["Spectrum number"]);

                    PSM psm = new PSM(scanNumber, rawname);
                    psm.StartResidue = int.Parse(reader["Start"]);
                    psm.Charge       = int.Parse(reader["Charge"]);
                    psm.BasePeptide  = new Peptide(reader["Peptide"].ToUpper());
                    psm.Defline      = reader["Defline"];
                    psm.ProteinGroup = reader["Best PG Name"];
                    psm.NumberOfSharingProteinGroups = int.Parse(reader["# of Sharing PGs"]);
                    psm.Filename = filename;

                    // Apply all the fix modifications
                    psm.BasePeptide.SetModifications(fixedMods);

                    int i = 0;
                    while (i < variableMods.Count)
                    {
                        if (fixedMods.Contains(variableMods[i]))
                        {
                            variableMods.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    // Save all the variable mod types
                    psm.VariabledModifications = variableMods;

                    psms.Add(psm);
                }
            }

            Log(string.Format("{0:N0} PSMs were loaded....", totalPsms));
            Log(string.Format("{0:N0} PSMs were kept.... ({1:F2} %)", psms.Count, 100.0 * (double)psms.Count / totalPsms));

            Log("Reading Spectral Data...");
            ThermoRawFile currentRawFile     = null;
            string        currentRawFileName = null;
            int           counter            = 0;

            foreach (PSM psm in psms.OrderBy(psm => psm.RawFileName))
            {
                string rawfilename = psm.RawFileName;

                if (!rawfilename.Equals(currentRawFileName))
                {
                    currentRawFileName = rawfilename;
                    if (currentRawFile != null && currentRawFile.IsOpen)
                    {
                        currentRawFile.Dispose();
                    }

                    if (!rawFiles.TryGetValue(rawfilename, out currentRawFile))
                    {
                        throw new NullReferenceException(string.Format("Raw File: {0}.raw was not found! Aborting.", rawfilename));
                    }
                    currentRawFile.Open();
                }

                psm.SetRawFile(currentRawFile);
                counter++;
                if (counter % 25 == 0)
                {
                    ProgressUpdate((double)counter / psms.Count);
                }
            }

            return(psms);
        }
示例#10
0
        private List <Protein> CompileResults(List <LocalizedHit> hits, string csvFile, string outputDirectory, bool breakProteinsApart = false)
        {
            Dictionary <string, LocalizedHit> hitsdict = new Dictionary <string, LocalizedHit>();

            // Group all the localized Hits into proteins
            Dictionary <string, Protein> proteins = new Dictionary <string, Protein>();

            foreach (LocalizedHit hit in hits)
            {
                hitsdict.Add(hit.PSM.Filename, hit);


                string defline = hit.PSM.Defline;

                if (breakProteinsApart)
                {
                    string[] groups = hit.PSM.ProteinGroup.Split('|');
                    foreach (string group in groups)
                    {
                        Protein prot;
                        if (!proteins.TryGetValue(group, out prot))
                        {
                            prot = new Protein(group, defline);
                            proteins.Add(group, prot);
                        }
                        prot.AddHit(hit);
                    }
                }
                else
                {
                    Protein prot;
                    if (!proteins.TryGetValue(hit.PSM.ProteinGroup, out prot))
                    {
                        prot = new Protein(hit.PSM.ProteinGroup, defline);
                        proteins.Add(hit.PSM.ProteinGroup, prot);
                    }
                    prot.AddHit(hit);
                }
            }
            using (StreamWriter writer = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_all.csv")),
                   localizedWriter = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_localized.csv")))
            {
                using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true))
                {
                    LocalizedHit hit = null;
                    headerInfo = reader.GetFieldHeaders();
                    bool tqFound = false;
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        if (headerInfo[i].EndsWith("NL)"))
                        {
                            if (!tqFound)
                            {
                                FirstQuantColumn = i;
                                tqFound          = true;
                            }
                        }
                        if (headerInfo[i] == "Channels Detected")
                        {
                            LastQuantColumn = i - 1;
                        }
                    }
                    string header = string.Join(",", headerInfo) + ",# Isoforms,# of Considered Fragments,Localized?,Delta Score,Best Isoform,Spectral Matches,% TIC,Second Best Isoform,Second Spectral Matches,Second % TIC";
                    writer.WriteLine(header);
                    localizedWriter.WriteLine(header);
                    while (reader.ReadNextRecord())
                    {
                        string mods = reader["Mods"];
                        if (string.IsNullOrEmpty(mods))
                        {
                            continue;
                        }

                        List <Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).OfType <Modification>().ToList();

                        // Only keep things with quantified Modifications
                        if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod)))
                        {
                            continue;
                        }

                        string filename = reader["Filename/id"];
                        if (!hitsdict.TryGetValue(filename, out hit))
                        {
                            continue;
                        }

                        string[] data = new string[reader.FieldCount];
                        reader.CopyCurrentRecordTo(data);

                        hit.omssapsm = data;

                        StringBuilder sb = new StringBuilder();

                        foreach (string datum in data)
                        {
                            if (datum.Contains(','))
                            {
                                sb.Append("\"");
                                sb.Append(datum);
                                sb.Append("\"");
                            }
                            else
                            {
                                sb.Append(datum);
                            }
                            sb.Append(',');
                        }
                        sb.Append(hit.PSM.Isoforms);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.Fragments.Count);
                        sb.Append(',');
                        sb.Append(hit.IsLocalized);
                        sb.Append(',');
                        sb.Append(hit.MatchDifference);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SequenceWithModifications);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SpectralMatch.Matches);
                        sb.Append(',');
                        sb.Append(hit.LocalizedIsoform.SpectralMatch.PercentTIC);
                        if (hit.PSM.Isoforms > 1)
                        {
                            //sb.Append(',');
                            //sb.Append(hit.BestPeptideSDFCount);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SequenceWithModifications);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SpectralMatch.Matches);
                            sb.Append(',');
                            sb.Append(hit.SecondBestPeptideIsoform.SpectralMatch.PercentTIC);
                            //sb.Append(',');
                            //sb.Append(hit.SecondBestPeptideSDFCount);
                        }

                        if (hit.IsLocalized)
                        {
                            localizedWriter.WriteLine(sb.ToString());
                        }
                        writer.WriteLine(sb.ToString());
                    }
                }
            }

            return(proteins.Values.ToList());
        }
示例#11
0
        private void WriteFiles(IEnumerable <InputFile> csvFiles, bool isBatched = false)
        {
            Log("Writing output files...");
            List <StreamWriter> openWriters = new List <StreamWriter>();
            const string        headerLine  = "Spectrum number,Filename/id,Peptide,E-value,Mass,gi,Accession,Start,Stop,Defline,Mods,Charge,Theo Mass,P-value,NIST score,Precursor Isolation m/z (Th),Precursor Theoretical m/z (Th),Precursor Isotope Selected, Adjusted Precursor m/z (Th),Precursor Mass Error (ppm),Adjusted Precursor Mass Error (ppm)";

            string outputSummaryFile =
                Path.Combine(_outputFolder, string.Format("FDR summary_{0:yyyyMMddhhmmss}.csv", DateTime.Now));
            StreamWriter summaryWriter = new StreamWriter(outputSummaryFile);

            openWriters.Add(summaryWriter);
            Dictionary <PSM, Peptide> overallBestPsms = null;
            StreamWriter batchTargetUniqueWriter = null, batchDecoyUniqueWriter = null;
            bool         firstHeader = true;
            int          batchTotalPsms = 0;
            int          batchTotalPeptides      = 0;
            int          batchTotalDecoyPsms     = 0;
            int          batchTotalDecoyPeptides = 0;
            StreamWriter batchScansWriter        = new StreamWriter(Path.Combine(_outputFolder, "scans.csv"));
            StreamWriter batchDecoyWriter        = new StreamWriter(Path.Combine(_outputFolder, "decoy_psms.csv"));
            StreamWriter batchTargetWriter       = new StreamWriter(Path.Combine(_outputFolder, "psms.csv"));

            openWriters.Add(batchScansWriter);
            openWriters.Add(batchDecoyWriter);
            openWriters.Add(batchTargetWriter);
            if (isBatched)
            {
                batchTargetUniqueWriter = new StreamWriter(Path.Combine(_outputFolder, "peptides.csv"));
                batchDecoyUniqueWriter  = new StreamWriter(Path.Combine(_outputFolder, "decoy_peptides.csv"));
                openWriters.Add(batchTargetUniqueWriter);
                openWriters.Add(batchDecoyUniqueWriter);
                overallBestPsms = _allPeptides.ToDictionary(pep => pep.BestMatch);
            }

            summaryWriter.WriteLine("CSV File,Raw File,Total MS Spectra,Total MS/MS Spectra,Average MS/MS Inj Time (ms),Max MS/MS Inj Time (ms),Average # of MS/MS per Cycle, Max # of MS/MS per Cycle,Total Scored Spectra,Total PSMs,Systematic Precursor Mass Error (ppm),Maximum Precursor Mass Error (ppm),E-Value Threshold,PSMs,Decoy PSMs,PSM FDR (%),Peptides,Decoy Peptides,Peptide FDR (%)");
            StringBuilder summaryStringBuilder = new StringBuilder();
            int           totalPsms            = 0;
            double        totalError           = 0;
            double        totalMaximalError    = 0;
            int           totalPeptides        = 0;
            int           totalDecoyPeptides   = 0;
            double        totalThreshold       = 0;
            int           totalDecoyPsms       = 0;
            int           totalMS          = 0;
            int           totalInitialPsms = 0;
            int           totalMSMS        = 0;

            foreach (InputFile csvFile in csvFiles)
            {
                summaryStringBuilder.Clear();
                string outputTargetFile = Path.Combine(_outputPsmFolder,
                                                       Path.GetFileNameWithoutExtension(csvFile.FilePath) + "_psms.csv");
                string outputDecoyFile = Path.Combine(_outputPsmFolder,
                                                      Path.GetFileNameWithoutExtension(csvFile.FilePath) + "_decoy_psms.csv");
                string outputScansFile = Path.Combine(_outputScansFolder,
                                                      Path.GetFileNameWithoutExtension(csvFile.FilePath) + "_scans.csv");
                string outputTargetUniqueFile = Path.Combine(_outputPeptideFolder,
                                                             Path.GetFileNameWithoutExtension(csvFile.FilePath) + "_peptides.csv");
                string outputDecoyUniqueFile = Path.Combine(_outputPeptideFolder,
                                                            Path.GetFileNameWithoutExtension(csvFile.FilePath) + "_decoy_peptides.csv");
                Log("Writing output files for " + Path.GetFileNameWithoutExtension(csvFile.Name) + " in " +
                    _outputFolder + "...");

                summaryStringBuilder.Append(csvFile.FilePath);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.RawFilePath);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.TotalMSscans);
                totalMS += csvFile.TotalMSscans;
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.TotalMSMSscans);
                totalMSMS += csvFile.TotalMSMSscans;
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.AverageMSMSInjectionTime.ToString("F5"));
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.MaxMSMSInjectionTime);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.AverageMSMSSCansBetweenMS.ToString("F5"));
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.MaxMSMSScansBetweenMS);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.TotalScans);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.PsmCount);
                totalInitialPsms += csvFile.PsmCount;
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.SystematicPrecursorMassError.ToString("F5"));
                totalError += csvFile.SystematicPrecursorMassError;
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.PrecursorMassToleranceThreshold.ToString("F5"));
                totalMaximalError += csvFile.PrecursorMassToleranceThreshold;
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(csvFile.ScoreThreshold);
                totalThreshold += csvFile.ScoreThreshold;
                summaryStringBuilder.Append(',');

                int totalPSMs  = csvFile.FdrFilteredPSMs.Count;
                int targetPSMs = csvFile.FdrFilteredPSMs.Count(pep => !pep.IsDecoy);
                int decoyPSMs  = totalPSMs - targetPSMs;

                summaryStringBuilder.Append(targetPSMs);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(decoyPSMs);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(100 * decoyPSMs / (double)targetPSMs);
                summaryStringBuilder.Append(',');

                int total   = csvFile.FdrFilteredPeptides.Count;
                int targets = csvFile.FdrFilteredPeptides.Count(pep => !pep.IsDecoy);
                int decoys  = total - targets;

                summaryStringBuilder.Append(targets);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(decoys);
                summaryStringBuilder.Append(',');
                summaryStringBuilder.Append(100 * decoys / (double)targets);



                using (StreamWriter targetWriter = new StreamWriter(outputTargetFile),
                       decoyWriter = new StreamWriter(outputDecoyFile),
                       scansWriter = new StreamWriter(outputScansFile),
                       targetUniqueWriter = new StreamWriter(outputTargetUniqueFile),
                       decoyUniqueWriter = new StreamWriter(outputDecoyUniqueFile))
                {
                    Dictionary <string, PSM> allPsms = csvFile.PeptideSpectralMatches.ToDictionary(psm => psm.FileName + psm.Peptide.Sequence);

                    HashSet <PSM> fdrPSMs = new HashSet <PSM>(csvFile.FdrFilteredPSMs);

                    Dictionary <PSM, Peptide> fdrPeptides = csvFile.FdrFilteredPeptides.ToDictionary(pep => pep.BestMatch);

                    HashSet <int> scansProcessed = new HashSet <int>();
                    StringBuilder sb             = new StringBuilder();
                    using (CsvReader reader = new CsvReader(new StreamReader(csvFile.FilePath), true))
                    {
                        string[] headers           = reader.GetFieldHeaders();
                        int      headerCount       = headers.Length;
                        int      modsColumnIndex   = 10; //reader.GetFieldIndex("Mods");
                        int      chargeColumnIndex = 11;
                        string[] data = new string[headerCount];

                        decoyWriter.WriteLine(headerLine);
                        targetWriter.WriteLine(headerLine);
                        scansWriter.WriteLine(headerLine);
                        targetUniqueWriter.WriteLine(headerLine);
                        decoyUniqueWriter.WriteLine(headerLine);
                        if (firstHeader)
                        {
                            batchScansWriter.WriteLine(headerLine);
                            batchDecoyWriter.WriteLine(headerLine);
                            batchTargetWriter.WriteLine(headerLine);
                            if (isBatched)
                            {
                                batchDecoyUniqueWriter.WriteLine(headerLine);
                                batchTargetUniqueWriter.WriteLine(headerLine);
                            }
                            firstHeader = false;
                        }
                        while (reader.ReadNextRecord())
                        {
                            PSM psm;
                            int spectralNumber = int.Parse(reader["Spectrum number"]);
                            if (scansProcessed.Contains(spectralNumber))
                            {
                                continue;
                            }
                            string fileName = reader["Filename/id"];
                            string sequence = reader["Peptide"].ToUpper();

                            if (allPsms.TryGetValue(fileName + sequence, out psm))
                            {
                                bool isNegative = psm.Charge < 0;

                                scansProcessed.Add(spectralNumber);
                                sb.Clear();
                                reader.CopyCurrentRecordTo(data);
                                for (int i = 0; i < 15; i++)
                                {
                                    string datum = data[i];

                                    if (_includeFixedMods && i == modsColumnIndex)
                                    {
                                        datum = OmssaModification.WriteModificationString(psm.Peptide);
                                    }

                                    // Replace the charge if negative
                                    if (isNegative && i == chargeColumnIndex)
                                    {
                                        sb.Append(psm.Charge);
                                        sb.Append(',');
                                        continue;
                                    }

                                    if (datum.Contains('"'))
                                    {
                                        datum = datum.Replace("\"", "\"\"");
                                    }

                                    if (datum.Contains(','))
                                    {
                                        sb.Append('"');
                                        sb.Append(datum);
                                        sb.Append('"');
                                    }
                                    else
                                    {
                                        sb.Append(datum);
                                    }

                                    sb.Append(',');
                                }
                                sb.Append(psm.IsolationMz);
                                sb.Append(',');
                                sb.Append(Mass.MzFromMass(psm.MonoisotopicMass, psm.Charge));
                                sb.Append(',');
                                sb.Append(psm.IsotopeSelected);
                                sb.Append(',');
                                sb.Append(Mass.MzFromMass(psm.AdjustedIsolationMass, psm.Charge));
                                sb.Append(',');
                                sb.Append(psm.PrecursorMassError);
                                sb.Append(',');
                                sb.Append(psm.CorrectedPrecursorMassError);

                                string line = sb.ToString();

                                scansWriter.WriteLine(line);
                                batchScansWriter.WriteLine(line);

                                // Passes FDR, write out
                                if (fdrPSMs.Contains(psm))
                                {
                                    if (psm.IsDecoy)
                                    {
                                        totalDecoyPsms++;
                                        batchTotalDecoyPsms++;
                                        decoyWriter.WriteLine(line);
                                        batchDecoyWriter.WriteLine(line);
                                    }
                                    else
                                    {
                                        totalPsms++;
                                        batchTotalPsms++;
                                        targetWriter.WriteLine(line);
                                        batchTargetWriter.WriteLine(line);
                                    }

                                    Peptide pep;
                                    // Is this the best unique psm?
                                    if (fdrPeptides.TryGetValue(psm, out pep))
                                    {
                                        if (pep.IsDecoy)
                                        {
                                            totalDecoyPeptides++;
                                            decoyUniqueWriter.WriteLine(line);
                                        }
                                        else
                                        {
                                            totalPeptides++;
                                            targetUniqueWriter.WriteLine(line);
                                        }
                                    }

                                    if (isBatched && overallBestPsms.TryGetValue(psm, out pep))
                                    {
                                        if (pep.IsDecoy)
                                        {
                                            batchTotalDecoyPeptides++;
                                            batchDecoyUniqueWriter.WriteLine(line);
                                        }
                                        else
                                        {
                                            batchTotalPeptides++;
                                            batchTargetUniqueWriter.WriteLine(line);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                summaryWriter.WriteLine(summaryStringBuilder.ToString());
            }

            summaryWriter.WriteLine();

            //int count = csvFiles.Count;
            //totalPsms /= count;
            //totalDecoyPsms /= count;
            //double totalPsmFdr = 100*totalDecoyPsms/(double) totalPsms;
            //totalPeptides /= count;
            //totalDecoyPeptides /= count;
            //double totalPeptideFdr = 100*totalDecoyPeptides/(double) totalPeptides;
            //summaryWriter.WriteLine("Average Results,,{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", totalMS / count, totalMSMS / count, "", "", totalScans / count, totalInitialPsms / count, totalError / count, totalMaximalError / count, totalThreshold / count, totalPsms, totalDecoyPsms, "", totalPeptides, totalDecoyPeptides, "");

            if (isBatched)
            {
                double psmFDR     = 100 * batchTotalDecoyPsms / (double)batchTotalPsms;
                double peptideFDR = 100 * batchTotalDecoyPeptides / (double)batchTotalPeptides;

                summaryWriter.WriteLine("Batched Results,,,,,,,,,,,,,{0},{1},{2},{3},{4},{5}", batchTotalPsms, batchTotalDecoyPsms, psmFDR, batchTotalPeptides, batchTotalDecoyPeptides, peptideFDR);
                Log(string.Format("{0:N0} peptides ({1:N0} decoys FDR = {2:F4}) in total [Batched]", batchTotalPeptides, batchTotalDecoyPeptides, peptideFDR));
            }

            foreach (StreamWriter writer in openWriters)
            {
                writer.Close();
            }
        }
示例#12
0
        public void Run()
        {
            logTB.Clear();
            logTB.BackColor = Color.White;

            string rawFileDirectory = textBox3.Text;
            string inputcsvfile     = textBox1.Text;

            if (!File.Exists(inputcsvfile))
            {
                UpdateLog("Cannot open input csvfile: " + inputcsvfile + ", aborting!");
                return;
            }
            string outputDirectory = textBox2.Text;

            if (string.IsNullOrWhiteSpace(outputDirectory))
            {
                UpdateLog("Must provide a valid output folder!");
                return;
            }
            if (!Directory.Exists(outputDirectory))
            {
                UpdateLog("Output directory " + outputDirectory + " doesn't exist, creating it...");
                Directory.CreateDirectory(outputDirectory);
            }

            List <Modification> fixedModifications      = listBox2.Items.OfType <Modification>().ToList();
            List <Modification> quantifiedModifications = new List <Modification>();

            List <string> modNames = checkedListBox1.CheckedItems.OfType <string>().ToList();

            if (modNames.Count > 0)
            {
                foreach (string modName in modNames)
                {
                    if (modName == Phosphorylation.Name)
                    {
                        quantifiedModifications.Add(Phosphorylation);
                    }
                    else
                    {
                        OmssaModification mod;
                        if (!OmssaModification.TryGetModification(modName, out mod))
                        {
                            UpdateLog("Unable to load mod " + modName + ". Did you load the correct modification file?");
                            return;
                        }
                        quantifiedModifications.Add(mod);
                    }
                }
            }
            else
            {
                UpdateLog("No modifications were selected to be quantified, please select mods from the list or one of the default options");
                return;
            }

            //double ascoreThreshold = (double)numericUpDown2.Value;
            double prodThreshold      = (double)numericUpDown3.Value / 100.0;
            bool   separateGroups     = checkBox3.Enabled && checkBox3.Checked;
            bool   ignoreCTerminal    = checkBox2.Checked;
            bool   reduceSites        = checkBox1.Checked;
            int    scoreCutoff        = (int)numericUpDown2.Value;
            bool   phosphoNeutralLoss = phosphoNeutralLossCB.Checked && quantifiedModifications.Contains(Phosphorylation);

            Tolerance prodTolerance = GetProductTolerance();

            _lotor = new Lotor(rawFileDirectory, inputcsvfile, outputDirectory, fixedModifications,
                               quantifiedModifications, prodTolerance, scoreCutoff, separateGroups, prodThreshold, ignoreCTerminal, reduceSites,
                               FragmentTypes.b | FragmentTypes.y, phosphoNeutralLoss);
            _lotor.UpdateLog        += lotor_UpdateLog;
            _lotor.UpdateProgress   += lotor_UpdateProgress;
            _lotor.Completed        += _lotor_Completed;
            localizeB.Enabled        = false;
            _mainThread              = new Thread(_lotor.Localize);
            _mainThread.IsBackground = true;
            _mainThread.Start();
        }