Skip to content

Commit

Permalink
Replaced yaggo with argparse.hpp. Removes dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcais committed Sep 28, 2024
1 parent 5d44516 commit aabb3a4
Show file tree
Hide file tree
Showing 38 changed files with 2,386 additions and 553 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ See below for a list of programs available.

### Requirements

The `tup` build system and the `yaggo` argument parsing library are required.
The `tup` build system is required.
On Ubuntu, install with:

``` shell
sudo apt install tup yaggo build-essential libxxhash-dev
sudo apt install tup fuse3 build-essential libxxhash-dev pkg-config
```

### Alphabet and K-mer size
Expand Down
592 changes: 592 additions & 0 deletions argparse.hpp

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions champarnaud_set.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include <cstdlib>
#include <vector>
#include <bitset>

#include "divisor.hpp"
#include "misc.hpp"
#include "common.hpp"
#include "dbg.hpp"
#include "champarnaud.hpp"
#include "champarnaud_set.hpp"
#include "argparse.hpp"

#ifndef K
#error Must define k-mer length K
Expand All @@ -22,6 +18,21 @@
typedef mer_op_type<K, ALPHA> mer_ops;
typedef mer_ops::mer_t mer_t;

struct ChamparnaudArgs : argparse::Args {
bool& brute_flag = flag("brute", "Brute force");
bool& notsorted_flag = flag("notsorted", "Do not sort output");

void welcome() override {
std::cout <<
"For each PCR, find the minimal k-mer m, do a principal division:\n"
"\n"
"m = l^n u, with l a Lyndon word, the smallest one, and |l|<|u|\n"
"\n"
"Output u l^n for each PCR."
<< std::endl;
}
};

template<typename Fn>
void enumerate_champarnaud(Fn fn) {
index_t<mer_ops> index(K);
Expand All @@ -47,7 +58,7 @@ void brute_champarnaud(Fn fn) {
}

int main(int argc, char* argv[]) {
champarnaud_set args(argc, argv);
auto args = argparse::parse<ChamparnaudArgs>(argc, argv);

if(args.notsorted_flag) {
bool first = true;
Expand Down
20 changes: 0 additions & 20 deletions champarnaud_set.yaggo

This file was deleted.

20 changes: 17 additions & 3 deletions comp2rankdot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
#include <memory>
#include <fstream>

#include "argparse.hpp"
#include "mer_op.hpp"
#include "mds_op.hpp"
#include "longest_path.hpp"
#include "misc.hpp"
#include "common.hpp"
#include "comp2rankdot.hpp"

struct Comp2RankdotArgs : argparse::Args {
bool& longest_flag = flag("l,longest", "Annotate with longest remaining path");
std::string& output_arg = kwarg("o,output", "Dot file output").set_default("/dev/stdout");
bool& progress_flag = flag("p,progress", "Show progress");
std::vector<const char*>& mds_arg = arg("MDS");

void welcome() override {
std::cout <<
"Generate dot file for 1 component, with rank for proper plotting\n\n"
"From 1 MDS, do a BFS and layout each layer with same rank"
<< std::endl;
}
};

struct mds_info {
static size_t total; // Total number of MDSs found. Used to set index
Expand Down Expand Up @@ -85,7 +99,7 @@ void update_ranges(std::vector<std::pair<mer_t, mer_t>>& fm_ranges, mer_t fmi) {

int main(int argc, char* argv[]) {
std::ios::sync_with_stdio(false);
comp2rankdot args(argc, argv);
const auto args = argparse::parse<Comp2RankdotArgs>(argc, argv);

std::vector<tristate_t> first_bmds;
std::vector<mer_t> first_fms, mds;
Expand All @@ -100,7 +114,7 @@ int main(int argc, char* argv[]) {

std::ofstream dot_fd;

if(strlen(args.output_arg) > 0) {
if(args.output_arg.size() > 0) {
dot_fd.open(args.output_arg);
if(!dot_fd.good()) {
std::cerr << "Failed to open dot output file '" << args.output_arg << '\'' << std::endl;
Expand Down
22 changes: 0 additions & 22 deletions comp2rankdot.yaggo

This file was deleted.

5 changes: 1 addition & 4 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ variables:
CXXFLAGS Compilation flags
LDFLAGS Linker flags
LDLIBS Extra libraries flags
YAGGO Path to yaggo
PKG_CONFIG_PATH Used by pkg-config
Enable testing the -r and -f flags. -r gives the number of repeats for an
Expand Down Expand Up @@ -68,10 +67,9 @@ fi

NAME="A${ALPHA}K${K}${SUFFIX}"

[ -z "$YAGGO" ] && YAGGO=$(which yaggo || true)
[ -z "$TUP" ] && TUP=$(which tup || true)

[[ -z "$TUP" || -z "$YAGGO" ]] && { echo >&2 "Missing required dependencies: tup and/or yaggo"; false; }
[[ -z "$TUP" ]] && { echo >&2 "Missing required dependencies: tup"; false; }

detect_compiledb() {
tup compiledb >& /dev/null && echo yes || true
Expand Down Expand Up @@ -115,7 +113,6 @@ CONFIG_CXX=$GCXX
CONFIG_CXXFLAGS=$XXHASH_CFLAGS $OPTFLAGS $CXXFLAGS
CONFIG_LDFLAGS=$XXHASH_LDFLAGS $LDFLAGS
CONFIG_LDLIBS=$XXHASH_LDLIBS $LDLIBS
CONFIG_YAGGO=$YAGGO
CONFIG_COMPILEDB=$COMPILEDB
EOF

Expand Down
14 changes: 11 additions & 3 deletions create_seed.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#include "create_seed.hpp"
#include "argparse.hpp"
#include "random_seed.hpp"

struct CreateSeedArgs : argparse::Args {
std::string& seed_arg = arg("Output seed file");

void welcome() {
std::cout << "Create a random seed file" << std::endl;
}
};

int main(int argc, char* argv[]) {
create_seed args(argc, argv);
seeded_prg<std::mt19937_64>(args.seed_arg, nullptr);
const auto args = argparse::parse<CreateSeedArgs>(argc, argv);
seeded_prg<std::mt19937_64>(args.seed_arg.c_str(), nullptr);
return EXIT_SUCCESS;
}
7 changes: 0 additions & 7 deletions create_seed.yaggo

This file was deleted.

20 changes: 12 additions & 8 deletions find_longest_path.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "argparse.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "find_longest_path.hpp"

#ifndef K
#error Must define k-mer length K
Expand All @@ -14,19 +10,27 @@
#endif

#include "mer_op.hpp"
#include "mds_op.hpp"
#include "misc.hpp"
#include "longest_path.hpp"

typedef mer_op_type<K, ALPHA> mer_ops;
typedef mer_ops::mer_t mer_t;
typedef longest_path_type<mer_ops> longest_path;

struct LongestPathArgs : argparse::Args {
std::optional<const char*>& mds_arg = kwarg("f,mds", "File with MDS");
std::vector<const char*>& comp_arg = arg("component");

void welcome() override {
std::cout << "Find longest remaining path" << std::endl;
}
};

int main(int argc, char* argv[]) {
find_longest_path args(argc, argv);
const auto args = argparse::parse<LongestPathArgs>(argc, argv);
longest_path lp;

const auto mds = args.mds_given ? mds_from_file<mer_t>(args.mds_arg) : mds_from_arg<mer_t>(args.comp_arg);
const auto mds = args.mds_arg ? mds_from_file<mer_t>(*args.mds_arg) : mds_from_arg<mer_t>(args.comp_arg);
std::cout << (size_t)lp.longest_path(mds) << '\n';

return EXIT_SUCCESS;
Expand Down
11 changes: 0 additions & 11 deletions find_longest_path.yaggo

This file was deleted.

11 changes: 9 additions & 2 deletions fms2mds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
#include <string>
#include <vector>

#include "argparse.hpp"
#include "mer_op.hpp"
#include "mds_op.hpp"
#include "fms2mds.hpp"
#include "misc.hpp"
#include "common.hpp"

typedef mer_op_type<K, ALPHA> mer_ops;
typedef mer_ops::mer_t mer_t;

struct FMS2MDSArgs : argparse::Args {

void welcome() {
std::cout << "Transform list of FMs to an mers in an MDS" << std::endl;
}
};

int main(int argc, char* argv[]) {
std::ios::sync_with_stdio(false);
fms2mds args(argc, argv);
const auto args = argparse::parse<FMS2MDSArgs>(argc, argv);
mds_op_type<mer_ops> mds_op;

std::string line;
Expand Down
9 changes: 0 additions & 9 deletions fms2mds.yaggo

This file was deleted.

29 changes: 18 additions & 11 deletions frac_set.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <vector>
#include <random>
#include <numeric>

#include "argparse.hpp"
#include "random_seed.hpp"
#include "common.hpp"
#include "frac_set.hpp"

#ifndef K
#error Must define k-mer length K
Expand All @@ -16,33 +15,41 @@

#include "mer_op.hpp"

struct FracSetArgs : argparse::Args {
std::optional<double>& fraction_arg = kwarg("f,fraction", "Fraction of k-mers to keep");
std::optional<double>& size_arg = kwarg("s,size", "Size of fractional set");
std::optional<const char*>& iseed_arg = kwarg("i,iseed", "Input seed file");
std::optional<const char*>& oseed_arg = kwarg("o,ioeed", "Output seed file");

};

typedef mer_op_type<K, ALPHA> mer_ops;
typedef mer_ops::mer_t mer_t;

int main(int argc, char* argv[]) {
frac_set args(argc, argv);
const auto args = argparse::parse<FracSetArgs>(argc, argv);

size_t set_size;
if(args.fraction_given) {
if(args.fraction_arg < 0.0 || args.fraction_arg > 1.0) {
if(args.fraction_arg) {
if(*args.fraction_arg < 0.0 || *args.fraction_arg > 1.0) {
std::cerr << "Frace must be in [0, 1]" << std::endl;
return EXIT_FAILURE;
}
set_size = std::min((size_t)mer_ops::nb_mers, (size_t)std::round(args.fraction_arg * mer_ops::nb_mers));
} else if(args.size_given) {
if(args.size_arg > mer_ops::nb_mers) {
set_size = std::min((size_t)mer_ops::nb_mers, (size_t)std::round(*args.fraction_arg * mer_ops::nb_mers));
} else if(args.size_arg) {
if(*args.size_arg > mer_ops::nb_mers) {
std::cerr << "Size must be in [0, " << (size_t)mer_ops::nb_mers << ']' << std::endl;
return EXIT_FAILURE;
}
set_size = args.size_arg;
set_size = *args.size_arg;
} else {
set_size = mer_ops::nb_necklaces;
}
std::cerr << "size " << set_size << '\n';

// The properly seeded PRG
auto prg = seeded_prg<std::mt19937_64>(args.oseed_given ? args.oseed_arg : nullptr,
args.iseed_given ? args.iseed_arg : nullptr);
auto prg = seeded_prg<std::mt19937_64>(args.oseed_arg ? *args.oseed_arg : nullptr,
args.iseed_arg ? *args.iseed_arg : nullptr);

std::vector<mer_t> all_mers(mer_ops::nb_mers);
for(mer_t m = 0; m < all_mers.size(); ++m)
Expand Down
24 changes: 0 additions & 24 deletions frac_set.yaggo

This file was deleted.

Loading

0 comments on commit aabb3a4

Please sign in to comment.