-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmass_parts.cpp
More file actions
57 lines (47 loc) · 1.82 KB
/
mass_parts.cpp
File metadata and controls
57 lines (47 loc) · 1.82 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
#include "mass_parts.h"
#include <algorithm>
#include <iostream>
class MassRatioCounter {
private:
std::vector < int > counters;
std::unordered_map < int, Scan > &reference_scans;
static const size_t SECTIONS_NUMBER = 21;
public:
MassRatioCounter(std::unordered_map < int, Scan > &reference_map) :
counters(SECTIONS_NUMBER), reference_scans(reference_map) {}
void operator ()(Scan &scan) {
std::unordered_map < int, Scan >::iterator scan_in_ref = reference_scans.find(scan.id);
if (scan_in_ref != reference_scans.end()) {
Scan &reference_scan = scan_in_ref->second;
double ratio = scan.mass / reference_scan.mass;
int section = std::min(static_cast <int>(ratio * 10), 20);
counters[section]++;
}
}
std::vector < int > get_results() {
return counters;
}
};
void calc_mass_parts(std::vector < std::string > filenames) {
const std::string output_filename_pref = "thermo_mass_ratio_distribution";
for (std::string pref : filenames) {
std::cout << "Calculating mass part distribution for " << pref + XTRACT_SUF << std::endl;
ScansMapCreator theoretic_collector;
go_through_tsv(pref + TSV_SUF, theoretic_collector);
std::unordered_map < int, Scan > theoretic_scans = theoretic_collector.get_map();
MassRatioCounter ratio_counter(theoretic_scans);
go_through_mgf(Thermo_Xtract, pref + XTRACT_SUF, ratio_counter);
std::vector < int > distribution = ratio_counter.get_results();
std::ofstream fout(output_filename_pref + pref + ".txt");
for (int j = 0; j < distribution.size(); ++j) {
if (j == distribution.size() - 1) {
fout << j * 10 << "%+ " << distribution[j] << std::endl;
}
else {
fout << j * 10 << "%-" << (j + 1) * 10 << "% " << distribution[j] << std::endl;
}
}
fout.close();
std::cout << "Done." << std::endl;
}
}