Skip to content

Commit

Permalink
Oct 7, 2024: Bug with -p fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
AldhairMedico committed Oct 7, 2024
1 parent ddc0916 commit 4eae9f5
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ int main(int argc, char **argv) {
{"patterns", required_argument, 0, 'p'},
{"window", required_argument, 0, 'w'},
{"step", required_argument, 0, 's'},
{"mode", required_argument, 0, 'm'},
{"canonical", required_argument, 0, 'c'},
{"threads", required_argument, 0, 'j'},
{"keep-window-data", no_argument, 0, 'k'},
{"mode", required_argument, 0, 'm'},

{"verbose", no_argument, &verbose_flag, 1},
{"cmd", no_argument, &cmd_flag, 1},
Expand All @@ -61,7 +62,7 @@ int main(int argc, char **argv) {

int option_index = 0;

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

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

Expand Down Expand Up @@ -92,13 +93,15 @@ int main(int argc, char **argv) {
break;
default: // handle positional arguments


case 0: // case for long options without short options, none yet

// if (strcmp(long_options[option_index].name,"line-length") == 0)
// splitLength = atoi(optarg);

break;


case 'f': // input sequence

if (isPipe && userInput.pipeType == 'n') { // check whether input is from pipe and that pipe input was not already set
Expand All @@ -114,11 +117,18 @@ int main(int argc, char **argv) {

break;


case 'j': // max threads
maxThreads = atoi(optarg);
userInput.stats_flag = 1;
break;


// case 'c': // canonical pattern
// userInput.canPatterns = optarg;
// break;


case 'm': {
std::istringstream modeStream(optarg);
std::string mode;
Expand Down Expand Up @@ -162,14 +172,15 @@ int main(int argc, char **argv) {
}
break;


case 'p':
{
std::istringstream patternStream(optarg);
std::string pattern;

while (std::getline(patternStream, pattern, ',')) {
if (pattern.empty()) continue;

if (std::any_of(pattern.begin(), pattern.end(), ::isdigit)) {
std::cerr << "Error: Pattern '" << pattern << "' contains numerical characters.\n";
exit(EXIT_FAILURE);
Expand All @@ -182,18 +193,24 @@ int main(int argc, char **argv) {
userInput.patterns.emplace_back(revCom(pattern));
}

std::unique(userInput.patterns.begin(), userInput.patterns.end());
if (userInput.patterns.empty()) {
userInput.patterns = {"TTAGGG", "CCCTAA"};
std::cout << "No patterns provided. Using canonical patterns: TTAGGG, CCCTAA" << "\n";
} else {
// Remove duplicates
std::sort(userInput.patterns.begin(), userInput.patterns.end());
auto last = std::unique(userInput.patterns.begin(), userInput.patterns.end());
userInput.patterns.erase(last, userInput.patterns.end());
}
}
break;


case 'w':
userInput.windowSize = std::stoi(optarg);
break;


case 's':
userInput.step = std::stoi(optarg);
printf("/// Teloscope v%s\n", version.c_str());
Expand All @@ -212,12 +229,14 @@ int main(int argc, char **argv) {
}
break;


case 'v': // software version
printf("/// Teloscope v%s\n", version.c_str());
printf("\nDeveloped by:\nGiulio Formenti [email protected]\n");
printf("Jack A. Medico [email protected]\n");
exit(0);



case 'h': // help
printf("teloscope [commands]\n");
printf("\nRequired Parameters:\n");
Expand All @@ -236,6 +255,7 @@ int main(int argc, char **argv) {
printf("\t--verbose\tverbose output.\n");
exit(0);


case 'k':
userInput.keepWindowData = true;
break;
Expand All @@ -259,7 +279,7 @@ int main(int argc, char **argv) {

}

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

Input in;
in.load(userInput); // load user input
Expand Down

0 comments on commit 4eae9f5

Please sign in to comment.