Example #1
0
        public override IEnumerable <string> Process(string filename)
        {
            var parser = new OutParser();

            string resultFilename;

            if (null == this.targetDir)
            {
                resultFilename = FileUtils.ChangeExtension(filename, ".xml");
            }
            else
            {
                resultFilename = targetDir + "/" + FileUtils.ChangeExtension(new FileInfo(filename).Name, ".xml");
            }


            using (PepXmlWriter writer = new PepXmlWriter("out"))
            {
                writer.Open(resultFilename);

                writer.OpenMsmsRunSummary(filename);

                SequestParam sp = new SequestParamFile().ReadFromFile(filename);

                writer.WriteSequestParam(sp);

                using (var reader = new OutsReader(filename))
                {
                    int totalCount = reader.FileCount;
                    Progress.SetRange(0, totalCount);
                    int currentCount = 0;

                    while (reader.HasNext)
                    {
                        if (Progress.IsCancellationPending())
                        {
                            throw new UserTerminatedException();
                        }

                        List <string>       contents = reader.NextContent();
                        IIdentifiedSpectrum sph      = parser.Parse(contents);
                        if (sph == null)
                        {
                            continue;
                        }

                        writer.WriteSequestPeptideHit(sph);

                        currentCount++;
                        Progress.SetPosition(currentCount);
                    }
                    Progress.SetPosition(totalCount);
                }
                writer.CloseMsmsRunSummary();
            }

            return(new[] { resultFilename });
        }
Example #2
0
    public void TestException()
    {
      using (var reader = new OutsReader(@"../../../data/20030428_4_29L_15.outs"))
      {
        for (int i = 0; i < 731; i++)
        {
          reader.NextContent();
        }

        //expect to throw exception
        reader.NextContent();
      }
    }
Example #3
0
    public void TestAll()
    {
      using (var reader = new OutsReader(@"../../../data/20030428_4_29L_15.outs"))
      {
        Assert.AreEqual(731, reader.FileCount);
        for (int i = 0; i < 731; i++)
        {
          Assert.AreEqual(true, reader.HasNext);
          reader.NextContent();
        }

        Assert.AreEqual(false, reader.HasNext);
      }
    }
        private void ExtractFileByPeptide(OutsReader reader, Dictionary <string, IIdentifiedSpectrum> outFilenamePeptideMap, string toDirectory)
        {
            Progress.SetRange(0, 1, reader.FileCount);
            int count = 0;

            while (outFilenamePeptideMap.Count > 0 && reader.HasNext)
            {
                if (Progress.IsCancellationPending())
                {
                    throw new UserTerminatedException();
                }

                string filename = reader.NextFilename;
                if (outFilenamePeptideMap.ContainsKey(filename))
                {
                    List <string> content = reader.NextContent();

                    IIdentifiedSpectrum sph = outFilenamePeptideMap[filename];

                    IIdentifiedSpectrum parsed = parser.Parse(content);

                    if (sph.Sequence.Equals(parsed.Sequence))
                    {
                        string targetFilename = toDirectory + "/" + filename;
                        using (StreamWriter sw = new StreamWriter(targetFilename))
                        {
                            foreach (string line in content)
                            {
                                sw.WriteLine(line);
                            }
                        }

                        outFilenamePeptideMap.Remove(filename);
                    }
                }
                else
                {
                    reader.SkipNextContent();
                }

                Progress.SetPosition(0, count++);
            }

            Progress.SetPosition(0, reader.FileCount);
        }
        private void ExtractMultipleRaw(string raw, List <string> rawFiles, List <IIdentifiedSpectrum> peptides)
        {
            string toDirectory = CreateToDirectory(raw);

            List <string> dtaFilenames = GetDtaFilenames(peptides);
            string        dtasFile     = new DtaOutFilenameConverter(rawFiles[0]).GetDtasFilename();

            using (DtasReader dtas = new DtasReader(dtasFile))
            {
                Progress.SetMessage(0, "Extracting from " + dtasFile + " ...");
                ExtractFile(dtas, dtaFilenames, toDirectory);
            }

            Dictionary <string, IIdentifiedSpectrum> outFilenamePeptideMap = GetOutFilenamePeptideMap(peptides);

            foreach (string rawFile in rawFiles)
            {
                string outsFile = new DtaOutFilenameConverter(rawFiles[0]).GetOutsFilename();
                Progress.SetMessage(0, "Extracting from " + outsFile + " ...");
                using (OutsReader outs = new OutsReader(outsFile))
                {
                    ExtractFileByPeptide(outs, outFilenamePeptideMap, toDirectory);
                }
            }

            if (outFilenamePeptideMap.Count > 0)
            {
                StringBuilder sb;
                if (outFilenamePeptideMap.Count == 1)
                {
                    sb = new StringBuilder("There is a file not found in dtas/outs file");
                }
                else
                {
                    sb = new StringBuilder("There are a few files not found in dtas/outs file");
                }

                foreach (string key in outFilenamePeptideMap.Keys)
                {
                    sb.Append("\n" + key);
                }

                throw new Exception(sb.ToString());
            }
        }
        private void ExtractSingleRaw(string raw, string rawFile, List <IIdentifiedSpectrum> peptides)
        {
            string toDirectory = CreateToDirectory(raw);

            List <string> dtaFilenames = GetDtaFilenames(peptides);
            string        dtasFile     = new DtaOutFilenameConverter(rawFile).GetDtasFilename();

            using (DtasReader dtas = new DtasReader(dtasFile))
            {
                Progress.SetMessage(0, MyConvert.Format("Extracting dta from {0} ...", dtasFile));
                ExtractFile(dtas, dtaFilenames, toDirectory);
            }

            List <string> outFilenames = GetOutFilenames(peptides);
            string        outsFile     = new DtaOutFilenameConverter(rawFile).GetOutsFilename();

            using (OutsReader outs = new OutsReader(outsFile))
            {
                Progress.SetMessage(0, MyConvert.Format("Extracting out from {0} ...", outsFile));
                ExtractFile(outs, outFilenames, toDirectory);
            }
        }