-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (100 loc) · 3.83 KB
/
main.cpp
File metadata and controls
127 lines (100 loc) · 3.83 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
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
#include <iostream>
#include <vector>
#include <string>
#include "graph.h"
#include <fstream>
#include <vector>
#include <string>
#include <kseq++/seqio.hpp>
using namespace klibpp;
// Function to read FASTQ files and return a vector of sequences
std::vector<std::string> readFastqSequences(const std::string& filename) {
std::vector<std::string> sequences;
KSeq record;
// Corrección: Convertir std::string a const char* usando c_str()
SeqStreamIn iss(filename.c_str()); // Usa c_str() para convertir std::string a const char*
// Verificar si el archivo se abrió correctamente
if (!iss) {
std::cerr << "Error al abrir el archivo: " << filename << std::endl;
return sequences;
}
// Leer cada registro del archivo FASTQ
while (iss >> record) {
sequences.push_back(record.seq); // Almacenar solo la secuencia
}
return sequences;
}
void runTest(const std::vector<std::string>& reads, int k, const std::string& testName) {
std::cout << "Test: " << testName << std::endl;
// Construir el grafo
std::unordered_map<std::string, Node*> graph = buildGraph(reads, k);
// Imprimir el grafo
std::cout << "Graph structure:" << std::endl;
printGraph(graph);
// Encontrar el circuito Euleriano si existe
std::vector<Node*> circuit = fleuryAlgorithm(graph);
std::cout << "Eulerian Circuit:";
if (circuit.empty()) {
std::cout << " No Eulerian Circuit found.";
} else {
for (Node* node : circuit) {
std::cout << " " << node->kmer << " ->";
}
}
std::cout << " END" << std::endl << std::endl;
// Limpiar la memoria
for (auto& pair : graph) {
delete pair.second;
}
}
void runTests() {
std::vector<std::string> readsPerfectEulerian = {"AGT", "GTA", "TAG", "AGT"};
std::vector<std::string> readsNonEulerian = {"AGT", "GTC", "TCA", "CAT"};
std::vector<std::string> readsEulerianWithDeadEnds = {"AGT", "GTA", "TAG", "AGC", "GCT"};
int k = 3;
runTest(readsPerfectEulerian, k, "Perfect Eulerian Cycle");
runTest(readsNonEulerian, k, "No Eulerian Cycle");
runTest(readsEulerianWithDeadEnds, k, "Eulerian Cycle with Extras");
}
void calculateKmerFrequencyFastq(const std::string& fastqPath) {
std::vector<std::string> sequences = readFastqSequences(fastqPath);
std::unordered_map<std::string, Node*> graph = buildGraph(sequences, 5);
getKmerFrequency(sequences, graph);
}
int main_assembly(int argc, char* argv[]) {
if (argc < 3) {
std::cout << "Uso: " << argv[0] << " <kmerfreq|testFleury> <ruta_archivo|modo_prueba>" << std::endl;
return 1;
}
std::string mode = argv[1];
std::string input = argv[2];
if (mode == "kmerfreq") {
// Llama directamente a la función con la ruta proporcionada
calculateKmerFrequencyFastq(input);
} else if (mode == "testFleury") {
std::vector<std::string> reads;
int k = 3;
if (input == "readsPerfectEulerian") {
reads = {"AGT", "GTA", "TAG", "AGT"};
runTest(reads, k, "Perfect Eulerian Cycle");
} else if (input == "readsNonEulerian") {
reads = {"AGT", "GTC", "TCA", "CAT"};
runTest(reads, k, "No Eulerian Cycle");
} else if (input == "readsEulerianWithDeadEnds") {
reads = {"AGT", "GTA", "TAC", "ACT", "CTG", "TGA", "ACG", "GAG", "CTT"};
runTest(reads, k, "Eulerian Cycle with Extras");
} else if (input == "laboratory"){
reads = {"ATGCTAGCAC"};
runTest(reads, k, "Assembly Lab Reads");
} else {
std::cout << "Modo de prueba inválido." << std::endl;
return 1;
}
} else {
std::cout << "Modo inválido. Use 'kmerfreq' o 'testFleury'." << std::endl;
return 1;
}
}
int main() {
return 0;
}