SetRawFile() public method

public SetRawFile ( MSDataFile dataFile ) : void
dataFile MSDataFile
return void
コード例 #1
0
ファイル: Lotor.cs プロジェクト: B-Rich/Compass
        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;
        }
コード例 #2
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);
        }