Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <algorithm>
- #include <sstream>
- #include <bitset>
- #include <cmath>
- #include <iterator>
- #define FASTA "D:\\studia\\III\\AKwB\\zadIII\\1.txt"
- #define QUAL "D:\\studia\\III\\AKwB\\zadIII\\1.qual.txt"
- using namespace std;
- struct sekwencja {
- string zrodlo;
- string sek;
- vector<int> qual;
- };
- struct Wierzcholek {
- string zrodlo;
- string sekwencja;
- vector<int> qual;
- unsigned int pozycja = 0;
- vector<Wierzcholek*> krawedzie;
- bool operator==(Wierzcholek &other) {
- return zrodlo == other.zrodlo && sekwencja == other.sekwencja && pozycja == other.pozycja;
- }
- };
- vector<Wierzcholek> V;
- bool find_node(vector<Wierzcholek *> &krawedzie, Wierzcholek &node1) {
- for (auto &it : krawedzie) {
- if (*it == node1) return true;
- }
- return false;
- }
- vector<string> splitString(string s)
- {
- stringstream iss(s);
- vector<string> tokens{istream_iterator<string>{iss},
- istream_iterator<string>{}};
- return tokens;
- }
- vector<sekwencja> wczytywanie() {
- vector<sekwencja> wszystkie;
- sekwencja jedna;
- ifstream file(FASTA);
- while (file.good()) {
- getline(file, jedna.zrodlo);
- getline(file, jedna.sek);
- wszystkie.push_back(jedna);
- }
- file.close();
- file.open(QUAL);
- string zrodlo;
- string linia;
- int temp_qual;
- while (getline(file, zrodlo))
- for (auto &sekwencja_r : wszystkie) {
- if (zrodlo == sekwencja_r.zrodlo) {
- getline(file, linia);
- // istringstream l(linia);
- vector<string>temp = splitString(linia);
- for (auto &i : temp)
- {
- sekwencja_r.qual.push_back(atoi(i.c_str()));
- }
- // while (l >> temp_qual) sekwencja_r.qual.push_back(temp_qual);
- if (sekwencja_r.sek.size() != sekwencja_r.qual.size()) {
- cout << "Wielkość sekwencji nukleotydów nie zgadza się z liczbą oceny wiarygodności nukleotydów"
- << endl;
- cout << "Nukleotydów: " << sekwencja_r.sek.size() << endl << "Wiarygodności: "
- << sekwencja_r.qual.size() << endl;
- exit(1);
- }
- break;
- }
- }
- file.close();
- cout << endl << endl;
- return wszystkie;
- }
- void tworzenie_gafu(vector<sekwencja> wszystkie,int n, int dop)
- {
- for (auto &it: wszystkie) {
- int j = 0;
- cout << "pierwszy for" << endl;
- for (int i = 0; i < it.sek.size() - n + 1; i ++) {
- Wierzcholek *v = new Wierzcholek;
- string a = it.sek.substr(j, n);
- v->sekwencja = a;
- for (int q = j; q < j+n; q++) {
- v->qual.push_back(it.qual[q]);
- }
- v->zrodlo = it.zrodlo;
- v->pozycja = j;
- V.push_back(*v);
- j++;
- }
- }
- cout << "mamy wierzchołki" << endl;
- for (auto &it: V) {
- for (auto &it2: V) {
- if (it.zrodlo != it2.zrodlo &&
- it.sekwencja == it2.sekwencja) {
- if (!find_node(it.krawedzie, it2))
- it.krawedzie.push_back(&it2);
- if (!find_node(it2.krawedzie, it))
- it2.krawedzie.push_back(&it);
- }
- }
- }
- cout << "połączenia1" << endl;
- for (auto &it: V)
- {
- for(int i=0; i<it.qual.size(); i++)
- {
- // cout<<it.qual[i]<<" ";
- if(it.qual[i]<dop)
- {
- it.qual.erase(it.qual.begin()+i);
- it.sekwencja.erase(it.sekwencja.begin()+i);
- }
- }
- }
- cout << "usuwanie skończone" << endl;
- for (auto &it: V) {
- for (auto &it2: V) {
- if (it.zrodlo != it2.zrodlo &&
- (it.sekwencja == it2.sekwencja || it.sekwencja.find(it2.sekwencja) != string::npos)) {
- if (!find_node(it.krawedzie, it2))
- it.krawedzie.push_back(&it2);
- if (!find_node(it2.krawedzie, it))
- it2.krawedzie.push_back(&it);
- }
- }
- }
- cout << "połączenia2" << endl;
- // vector<Wierzcholek> :: iterator it3;
- vector<Wierzcholek *> :: iterator dupa;
- cout<<endl<<endl<<endl;
- for (auto &chuj : V){
- cout << chuj.zrodlo << " " << chuj.pozycja << endl;
- }
- for(auto &it3 : V)
- {
- cout<<it3.zrodlo<<" "<<it3.pozycja<<" "<<it3.sekwencja<<" "<<it3.krawedzie.size()<<endl << "Sąsiedzi: "<< endl;
- for(dupa=it3.krawedzie.begin(); dupa!=it3.krawedzie.end(); ++dupa)
- {
- cout<<(*dupa)->zrodlo<<" "<< (*dupa)->pozycja<<" "<<(*dupa)->sekwencja<<" " << (*dupa)->krawedzie.size()<<endl;
- }
- cout<<endl<<endl<<endl<<"***"<<endl;
- }
- }
- int main()
- {
- vector<sekwencja> wszystkie=wczytywanie();
- cout << "wczytywanie zrobione" << endl;
- int n=4;
- int dop=25;
- tworzenie_gafu(wszystkie,n, dop);
- cout << "tworzenie zakończone" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement