-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPeptidesFile.cs
More file actions
83 lines (72 loc) · 2.3 KB
/
Copy pathPeptidesFile.cs
File metadata and controls
83 lines (72 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections;
using System.IO;
namespace MPToolkit.AScore.Interface
{
/// <summary>
/// Stores information for a single row in the peptides file.
/// </summary>
public struct PeptidesFileEntry {
/// <summary>
/// Not used in AScore, can be any unique number for
/// identification purposes.
/// </summary>
public string Id;
/// <summary>
/// The scan number is used to look up the scan from the
/// scans file.
/// </summary>
public int ScanNumber;
/// <summary>
/// The annotated peptide sequence. This includes
/// flanking residues and mod symbols
/// Ex. "K.M*LAES#DDS#GDEESVSQTDK.T"
/// </summary>
public string Peptide;
/// <summary>
/// The accurate precursor m/z of the identified peptide.
/// </summary>
public double PrecursorMz;
}
/// <summary>
/// Class to parse the peptides csv and returns an enumerator
/// that can be used in a foreach loop.
/// </summary>
public class PeptidesFile : IEnumerable
{
private string Path;
/// <summary>
/// Constructor
/// </summary>
/// <param name="path">The full path to the input file.</param>
public PeptidesFile(string path)
{
Path = path;
}
public IEnumerator GetEnumerator()
{
var lines = File.ReadLines(Path);
foreach (var line in lines) {
if (string.IsNullOrWhiteSpace(line)) {
continue;
}
if (line.Contains("\tpeptide\t")) {
// header line
continue;
}
yield return ParsePeptide(line.Trim());
}
}
/// <summary>
/// Reads a line from the csv file and returns the PeptideEntry
/// </summary>
private PeptidesFileEntry ParsePeptide(string line) {
var entry = new PeptidesFileEntry();
string[] pieces = line.Split("\t");
entry.Id = pieces[0];
entry.ScanNumber = int.Parse(pieces[1]);
entry.Peptide = pieces[2];
entry.PrecursorMz = double.Parse(pieces[3]);
return entry;
}
}
}