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 }); }
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); }