CandidateSearch 1.1.2
Proof-of-concept implementation of a search engine that uses sparse matrix multiplication to identify the best peptide candidates for a given mass spectrum.
Loading...
Searching...
No Matches
Result.cs
Go to the documentation of this file.
2{
6 public class Result
7 {
11 public Dictionary<int, List<Peptide>> result { get; }
12
20 public Result(ref int[] SearchResult, ref List<Peptide> Peptides, ref List<Spectrum> Spectra, int TopN) {
21
22 result = new Dictionary<int, List<Peptide>>();
23
24 int currentSearchResultIdx = 0;
25 foreach (var spectrum in Spectra)
26 {
27 if (!result.ContainsKey(spectrum.scanNumber))
28 {
29 result.Add(spectrum.scanNumber, new List<Peptide>());
30 for (int i = currentSearchResultIdx; i < currentSearchResultIdx + TopN; i++)
31 {
32 result[spectrum.scanNumber].Add(Peptides[SearchResult[i]]);
33 }
34 }
35 else
36 {
37 Console.WriteLine($"Warning: Found duplicate scan number {spectrum.scanNumber}. Skipping scan number...");
38 }
39
40 currentSearchResultIdx += TopN;
41 }
42 }
43
49 public int export(string filename)
50 {
51 int status;
52
53 try
54 {
55 var lines = new List<string>(){"ScanNumber;Peptides"};
56 foreach (var item in result) {
57 var scanNr = item.Key;
58 var peptides = item.Value;
59 var line = scanNr.ToString() + ";";
60 foreach (var peptide in peptides)
61 {
62 line += (peptide.ToString() + ",");
63 }
64 lines.Add(line);
65 }
66
67 using (StreamWriter sw = new StreamWriter(filename))
68 {
69 foreach (var line in lines)
70 {
71 sw.WriteLine(line);
72 }
73 }
74
75 status = 0;
76 }
77 catch (Exception ex)
78 {
79 Console.WriteLine("Something went wrong:");
80 Console.WriteLine(ex.ToString());
81 status = 1;
82 }
83
84 return status;
85 }
86 }
87}
Result class to transform and store the returned integer array of VectorSearch.
Definition Result.cs:7
Result(ref int[] SearchResult, ref List< Peptide > Peptides, ref List< Spectrum > Spectra, int TopN)
Constructor creating a result item that stores the processed VectorSearch result.
Definition Result.cs:20
Dictionary< int, List< Peptide > > result
Dictionary that maps scan numbers to lists of peptide candidates.
Definition Result.cs:11
int export(string filename)
Exports the results to csv format into a file with the given filename.
Definition Result.cs:49