Skip to content

Commit

Permalink
Aug 12, 2024: Verbose ok
Browse files Browse the repository at this point in the history
  • Loading branch information
AldhairMedico committed Aug 12, 2024
1 parent 404147d commit 4509e17
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 29 deletions.
2 changes: 1 addition & 1 deletion include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern std::chrono::high_resolution_clock::time_point start;

// flags are global variables
extern short int tabular_flag;
extern int tabular_flag;
extern int verbose_flag;
extern int seqReport_flag;
extern int outSequence_flag;
Expand Down
2 changes: 1 addition & 1 deletion include/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct UserInputTeloscope : UserInput {
uint32_t step = 500;
double maxMem = 0;
std::string prefix = ".", outFile = "";
bool modeMatch = true, modeEntropy = true, modeGC = true;
bool modeMatch = true, modeEntropy = true, modeGC = true; // Change to: de novo, user-defined
};


Expand Down
2 changes: 2 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <fstream>
#include <sstream>
#include <map>
#include <set>


#include <getopt.h>

Expand Down
2 changes: 1 addition & 1 deletion include/teloscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Teloscope {
std::cout << "Min GC Content:\t" << getMin(gcContentValues) << "\n";
}

void teloAnnotation() {
void annotateTelomeres() {
/// For each path we need two telomeric coordinates: p (start) and q (end)
/// For p telomere: Start to last semi-continous repeat
/// For q telomere: First semi-continous repeat to end
Expand Down
29 changes: 23 additions & 6 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void Input::load(UserInputTeloscope userInput) {
void Input::read(InSequences &inSequences) {

loadGenome(userInput, inSequences); // load from FA/FQ/GFA to templated object
lg.verbose("Finished loading genome assembly");

std::vector<InPath> inPaths = inSequences.getInPaths();
std::vector<InSegment*> *inSegments = inSequences.getInSegments();
Expand All @@ -39,33 +40,44 @@ void Input::read(InSequences &inSequences) {
Teloscope teloscope(userInput);

for (InPath& inPath : inPaths)

threadPool.queueJob([&inPath, this, inSegments, inGaps, &teloscope]() {
return teloscope.walkPath(&inPath, *inSegments, *inGaps);
});

std::cout << "Waiting for jobs to complete" << "\n";
lg.verbose("Waiting for jobs to complete");
std::cout << "Waiting for jobs to complete" << std::endl;

jobWait(threadPool); // Wait for all jobs to complete
std::cout << "All jobs completed" << "\n";
lg.verbose("All jobs completed");
std::cout << "All jobs completed" << std::endl;

teloscope.sortWindowsBySeqPos();
lg.verbose("\nPaths sorted by original position");

teloscope.generateBEDFile();
lg.verbose("\nBED/BEDgraph files generated");

teloscope.printSummary();
lg.verbose("\nSummary printed");
}


bool Teloscope::walkPath(InPath* path, std::vector<InSegment*> &inSegments, std::vector<InGap> &inGaps) {

Log threadLog;

unsigned int cUId = 0, gapLen = 0, seqPos = path->getSeqPos();
std::vector<PathComponent> pathComponents = path->getComponents();
uint64_t absPos = 0;
std::vector<WindowData> pathWindows;
std::string header = removeCarriageReturns(path->getHeader());
threadLog.add("\n\tWalking path:\t" + path->getHeader());

// std::string header = path->getHeader();
// eraseChar(header, '\r');

for (std::vector<PathComponent>::iterator component = pathComponents.begin(); component != pathComponents.end(); component++) {

cUId = component->id;

if (component->componentType == SEGMENT) {
Expand Down Expand Up @@ -96,8 +108,13 @@ bool Teloscope::walkPath(InPath* path, std::vector<InSegment*> &inSegments, std:

}

std::unique_lock<std::mutex> lck (mtx);
insertWindowData(seqPos, header, pathWindows);
// std::unique_lock<std::mutex> lck (mtx);
std::lock_guard<std::mutex> lck(mtx);
insertWindowData(seqPos, header, pathWindows);

threadLog.add("\tCompleted walking path:\t" + path->getHeader());
// std::lock_guard<std::mutex> lck(mtx); // Jack: does the first lock_guard protect both?
logs.push_back(threadLog);

return true;
}
60 changes: 40 additions & 20 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#include "main.h"
#include <input.h> // check
#include <main.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <set>


std::string version = "0.0.1";

// global
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();

short int tabular_flag;
int tabular_flag;
int verbose_flag;
int cmd_flag;

int maxThreads = 0;
std::mutex mtx;
ThreadPool<std::function<bool()>> threadPool;

Log lg;
std::vector<Log> logs;
std::string outRoute;
Expand All @@ -35,23 +34,24 @@ int main(int argc, char **argv) {

if (argc == 1) { // case: with no arguments

printf("teloscope -f input.[fasta] \n-h for additional help. Use -f to initiate the tool.\n");
printf("teloscope -f input.[fa/fa.gz] \n-h for additional help. Use -f to initiate the tool.\n");
exit(0);

}

static struct option long_options[] = { // struct mapping long options
{"input-sequence", required_argument, 0, 'f'},
{"verbose", no_argument, &verbose_flag, 1},
{"cmd", no_argument, &cmd_flag, 1},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'}, // giulio: expand the arguments, tax ID
{"patterns", required_argument, 0, 'p'},
{"window", required_argument, 0, 'w'},
{"step", required_argument, 0, 's'},
{"mode", required_argument, 0, 'm'},
{"output", required_argument, 0, 'o'},
{"threads", required_argument, 0, 'j'},

{"verbose", no_argument, &verbose_flag, 1},
{"cmd", no_argument, &cmd_flag, 1},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
// {"taxid", no_argument, 0, 't'},
{0, 0, 0, 0}
};
Expand All @@ -61,6 +61,18 @@ int main(int argc, char **argv) {
int option_index = 0;

c = getopt_long(argc, argv, "-:f:j:m:o:p:s:w:vh", long_options, &option_index);

// if (optind < argc && !isPipe) { // if pipe wasn't assigned already

// isPipe = isDash(argv[optind]) ? true : false; // check if the argument to the option is a '-' and set it as pipe input

// }

// if (optarg != nullptr && !isPipe) { // case where pipe input is given as positional argument (input sequence file)

// isPipe = isDash(optarg) ? true : false;

// }

if (c == -1) { // exit the loop if run out of options
break;
Expand Down Expand Up @@ -206,15 +218,16 @@ int main(int argc, char **argv) {
exit(0);

case 'h': // help
printf("teloscope [command]\n");
printf("teloscope [commands]\n");
printf("\nRequired Parameters:\n");
printf("--input-sequence '-f' Initiate tool with fasta file.\n");
printf("--patterns '-p' Set patterns to explore.\n");
printf("--window '-w' Set sliding window size.\n");
printf("--step '-s' Set sliding window step.\n");
printf("\t'-f'\t--input-sequence\tInitiate tool with fasta file.\n");
printf("\t'-p'\t--patterns\tSet patterns to explore.\n");
printf("\t'-w'\t--window\tSet sliding window size.\n");
printf("\t'-s'\t--step\tSet sliding window step.\n");
printf("\nOptional Parameters:\n");
printf("--version -v Print current software version.\n");
printf("--help -h Print current software options.\n");
printf("\t'-v'\t--version\tPrint current software version.\n");
printf("\t'-h'\t--help\tPrint current software options.\n");
printf("\t--verbose\tverbose output.\n");
exit(0);
}

Expand All @@ -225,6 +238,8 @@ int main(int argc, char **argv) {
}

}

lg.verbose("Input variables assigned");

if (cmd_flag) { // print command line
for (unsigned short int arg_counter = 0; arg_counter < argc; arg_counter++) {
Expand All @@ -234,7 +249,7 @@ int main(int argc, char **argv) {

}

threadPool.init(maxThreads); // initialize threadpool
threadPool.init(maxThreads); // initialize threadpool, giulio?

Input in;
in.load(userInput); // load user input
Expand All @@ -244,8 +259,13 @@ int main(int argc, char **argv) {
lg.verbose("Sequence object generated");
in.read(inSequences); // read input content to inSequences container

lg.verbose("Finished reading input files");
if(verbose_flag) {std::cerr<<"\n";}; // giulio?

threadPool.join();

lg.verbose("Generated output");

exit(EXIT_SUCCESS);

}
Expand Down

0 comments on commit 4509e17

Please sign in to comment.