-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotif.cc
139 lines (136 loc) · 4.53 KB
/
motif.cc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "motif.hh"
#include "out.hh"
#include "subsequence.hh"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<fstream>
#include<unordered_map>
#include<string>
#include<vector>
#include<sstream>
#include<map>
#include<mutex>
static HashMap HairpinHashMap;
static HashMap InternalHashMap;
static bool initialized;
static bool initialized2;
std::vector<std::string> split(const std::string &s, char delim){
std::vector<std::string> result;
std::stringstream ss (s);
std::string item;
while (getline(ss,item,delim)) {
result.push_back(item);
}
return result;
}
HashMap globalMap_Hairpins(HashMap x) {
std::string Line;
std::ifstream infile("/mnt/c/Master/HairpinMotifs.csv"); //Insert Path to Hairpin loops library here
while (getline (infile, Line)) {
std::vector<std::string> v = split(Line,'+');
std::string key = v[0];
std::string prevalue = v[1];
char value[prevalue.length()+1];
strcpy(value,prevalue.c_str());
char value2=value[0];
x[key]=value2;
}
return x;
}
HashMap globalMap_Internals(HashMap x){
std::string Line;
std::ifstream Data("/mnt/c/Master/InternalMotifs.csv"); //Insert Path to Internal loops library here
while (getline (Data, Line)) {
std::vector<std::string> v = split(Line,'+');
std::string key = v[0];
std::string prevalue = v[1];
char value[prevalue.length()+1];
strcpy(value,prevalue.c_str());
char value2=value[0];
x[key]=value2;
}
return x;
}
std::string InputManagement(const Basic_Subsequence<char,unsigned int> &a){
std::string Motif;//Motif is initialized to later be the carrier of the actual sequence which is returned and later used to find the Motif in the HashMap
for(unsigned int p = 0; p < a.size();p++){
int sum;
sum = a.i + p;
if (base_t(a.seq->seq[sum]) == G_BASE){
Motif += "G";
} else if (base_t(a.seq->seq[sum]) == A_BASE){
Motif += "A";
} else if (base_t(a.seq->seq[sum]) == C_BASE){
Motif += "C";
} else {
Motif += "U";
}
}
//std::cout << Motif << std::endl;
return Motif; //Return the Motif string, correctly formatted for the HashMap
}
std::string InputManagement2(const Basic_Subsequence<char, unsigned int> &a, const Basic_Subsequence<char, unsigned int> &b){
std::string Motif1, Motif2, Motif;//Same as the Standard Version, except both sequences are converted to String first to then be connected via "$" sign
for(unsigned int t = 0; t < a.size();t++){
int sum;
sum = a.i + t;
if (base_t(a.seq->seq[sum]) == G_BASE){
Motif1 += "G";
} else if (base_t(a.seq->seq[sum]) == A_BASE){
Motif1 += "A";
} else if (base_t(a.seq->seq[sum]) == C_BASE){
Motif1 += "C";
} else {
Motif1 += "U";
}
}
for(unsigned int t2 = 0; t2 < b.size();t2++){
int sum;
sum = b.i + t2;
if (base_t(b.seq->seq[sum]) == G_BASE){
Motif2 += "G";
} else if (base_t(b.seq->seq[sum]) == A_BASE){
Motif2 += "A";
} else if (base_t(b.seq->seq[sum]) == C_BASE){
Motif2 += "C";
} else {
Motif2 += "U";
}
}
Motif = Motif1 + "$" + Motif2;
//std::cout << Motif << std::endl;
return Motif; //Return the Mtofi string, correctly formatted for the HashMap
}
char identify_motif(const Basic_Subsequence<char, unsigned int> &a) {
char res = '.';
if (!initialized){
initialized = true;
HairpinHashMap = globalMap_Hairpins(HairpinHashMap);
}
std::string Motif;
Motif = InputManagement(a);
if(HairpinHashMap.find(Motif) == HairpinHashMap.end()) {
return res;
} else {
res = HairpinHashMap[Motif];
return res;
}
}
char identify_motif(const Basic_Subsequence<char, unsigned int> &a, const Basic_Subsequence<char, unsigned int> &b){
char res = '.';
if (!initialized2){
initialized2 = true;
InternalHashMap = globalMap_Internals(InternalHashMap);
}
std::string Motif;
Motif = InputManagement2(a,b);
if(InternalHashMap.find(Motif) == InternalHashMap.end()) {
return res;
}
else {
res = InternalHashMap[Motif];
return res;
}
}