Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <sstream>
  6. #include <bitset>
  7. #include <cmath>
  8. #include <iterator>
  9.  
  10. #define FASTA "D:\\studia\\III\\AKwB\\zadIII\\1.txt"
  11. #define QUAL "D:\\studia\\III\\AKwB\\zadIII\\1.qual.txt"
  12.  
  13. using namespace std;
  14. struct sekwencja {
  15. string zrodlo;
  16. string sek;
  17. vector<int> qual;
  18. };
  19.  
  20. struct Wierzcholek {
  21. string zrodlo;
  22. string sekwencja;
  23. vector<int> qual;
  24. unsigned int pozycja = 0;
  25. vector<Wierzcholek*> krawedzie;
  26.  
  27. bool operator==(Wierzcholek &other) {
  28. return zrodlo == other.zrodlo && sekwencja == other.sekwencja && pozycja == other.pozycja;
  29. }
  30. };
  31.  
  32. vector<Wierzcholek> V;
  33.  
  34. bool find_node(vector<Wierzcholek *> &krawedzie, Wierzcholek &node1) {
  35. for (auto &it : krawedzie) {
  36. if (*it == node1) return true;
  37. }
  38. return false;
  39. }
  40.  
  41. vector<string> splitString(string s)
  42. {
  43. stringstream iss(s);
  44. vector<string> tokens{istream_iterator<string>{iss},
  45. istream_iterator<string>{}};
  46. return tokens;
  47. }
  48.  
  49. vector<sekwencja> wczytywanie() {
  50. vector<sekwencja> wszystkie;
  51. sekwencja jedna;
  52. ifstream file(FASTA);
  53. while (file.good()) {
  54. getline(file, jedna.zrodlo);
  55. getline(file, jedna.sek);
  56. wszystkie.push_back(jedna);
  57. }
  58. file.close();
  59.  
  60. file.open(QUAL);
  61. string zrodlo;
  62. string linia;
  63. int temp_qual;
  64. while (getline(file, zrodlo))
  65. for (auto &sekwencja_r : wszystkie) {
  66. if (zrodlo == sekwencja_r.zrodlo) {
  67. getline(file, linia);
  68. // istringstream l(linia);
  69. vector<string>temp = splitString(linia);
  70. for (auto &i : temp)
  71. {
  72. sekwencja_r.qual.push_back(atoi(i.c_str()));
  73. }
  74.  
  75. // while (l >> temp_qual) sekwencja_r.qual.push_back(temp_qual);
  76. if (sekwencja_r.sek.size() != sekwencja_r.qual.size()) {
  77. cout << "Wielkość sekwencji nukleotydów nie zgadza się z liczbą oceny wiarygodności nukleotydów"
  78. << endl;
  79. cout << "Nukleotydów: " << sekwencja_r.sek.size() << endl << "Wiarygodności: "
  80. << sekwencja_r.qual.size() << endl;
  81. exit(1);
  82. }
  83. break;
  84. }
  85. }
  86. file.close();
  87.  
  88. cout << endl << endl;
  89. return wszystkie;
  90. }
  91.  
  92. void tworzenie_gafu(vector<sekwencja> wszystkie,int n, int dop)
  93. {
  94. for (auto &it: wszystkie) {
  95. int j = 0;
  96. cout << "pierwszy for" << endl;
  97. for (int i = 0; i < it.sek.size() - n + 1; i ++) {
  98. Wierzcholek *v = new Wierzcholek;
  99. string a = it.sek.substr(j, n);
  100. v->sekwencja = a;
  101. for (int q = j; q < j+n; q++) {
  102. v->qual.push_back(it.qual[q]);
  103. }
  104. v->zrodlo = it.zrodlo;
  105. v->pozycja = j;
  106. V.push_back(*v);
  107. j++;
  108. }
  109. }
  110. cout << "mamy wierzchołki" << endl;
  111. for (auto &it: V) {
  112. for (auto &it2: V) {
  113. if (it.zrodlo != it2.zrodlo &&
  114. it.sekwencja == it2.sekwencja) {
  115. if (!find_node(it.krawedzie, it2))
  116. it.krawedzie.push_back(&it2);
  117. if (!find_node(it2.krawedzie, it))
  118. it2.krawedzie.push_back(&it);
  119. }
  120. }
  121. }
  122. cout << "połączenia1" << endl;
  123. for (auto &it: V)
  124. {
  125. for(int i=0; i<it.qual.size(); i++)
  126. {
  127. // cout<<it.qual[i]<<" ";
  128. if(it.qual[i]<dop)
  129. {
  130. it.qual.erase(it.qual.begin()+i);
  131. it.sekwencja.erase(it.sekwencja.begin()+i);
  132. }
  133. }
  134. }
  135. cout << "usuwanie skończone" << endl;
  136.  
  137. for (auto &it: V) {
  138. for (auto &it2: V) {
  139. if (it.zrodlo != it2.zrodlo &&
  140. (it.sekwencja == it2.sekwencja || it.sekwencja.find(it2.sekwencja) != string::npos)) {
  141. if (!find_node(it.krawedzie, it2))
  142. it.krawedzie.push_back(&it2);
  143. if (!find_node(it2.krawedzie, it))
  144. it2.krawedzie.push_back(&it);
  145. }
  146. }
  147. }
  148.  
  149. cout << "połączenia2" << endl;
  150. // vector<Wierzcholek> :: iterator it3;
  151. vector<Wierzcholek *> :: iterator dupa;
  152. cout<<endl<<endl<<endl;
  153. for (auto &chuj : V){
  154. cout << chuj.zrodlo << " " << chuj.pozycja << endl;
  155. }
  156. for(auto &it3 : V)
  157. {
  158. cout<<it3.zrodlo<<" "<<it3.pozycja<<" "<<it3.sekwencja<<" "<<it3.krawedzie.size()<<endl << "Sąsiedzi: "<< endl;
  159. for(dupa=it3.krawedzie.begin(); dupa!=it3.krawedzie.end(); ++dupa)
  160. {
  161. cout<<(*dupa)->zrodlo<<" "<< (*dupa)->pozycja<<" "<<(*dupa)->sekwencja<<" " << (*dupa)->krawedzie.size()<<endl;
  162. }
  163. cout<<endl<<endl<<endl<<"***"<<endl;
  164. }
  165. }
  166. int main()
  167. {
  168. vector<sekwencja> wszystkie=wczytywanie();
  169. cout << "wczytywanie zrobione" << endl;
  170. int n=4;
  171. int dop=25;
  172. tworzenie_gafu(wszystkie,n, dop);
  173. cout << "tworzenie zakończone" << endl;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement