Skip to content

Commit

Permalink
Merge pull request #29 from veg/develop
Browse files Browse the repository at this point in the history
Adding delimiter options for tn93
  • Loading branch information
spond authored Oct 21, 2022
2 parents 5e3012f + a9a2f55 commit 6fdf379
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ set(CMAKE_CONFIGURATION_TYPES Release)
# SET VERSION FROM FILE
file (STRINGS "VERSION.txt" VERSION_NUMBER)
add_definitions (-DVERSION_NUMBER=\"${VERSION_NUMBER}\")
add_compile_options (-O3 -std=c++14 -march=native -funroll-loops )
add_link_options(-O3 -std=c++14 -march=native -funroll-loops)
add_compile_options (-O3 -std=c++14 -funroll-loops )
add_link_options(-O3 -std=c++14 -funroll-loops)

include_directories(
src/
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.9
v1.0.10
14 changes: 7 additions & 7 deletions src/TN93.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ int main(int argc, const char *argv[]) {
if (args.format != hyphy) {
if (args.do_count == false) {
if (args.format == csv)
fprintf(args.output, "ID1,ID2,Distance\n");
fprintf(args.output, "ID1%cID2%cDistance\n", args.delimiter, args.delimiter);
else
fprintf(args.output, "Seq1,Seq2,Distance\n");
fprintf(args.output, "Seq1%cSeq2%cDistance\n", args.delimiter, args.delimiter);
}
} else {
distanceMatrix = new double[sequenceCount * sequenceCount];
Expand Down Expand Up @@ -375,11 +375,11 @@ int main(int argc, const char *argv[]) {
// to self as 0
if (args.format == csv) {
#pragma omp critical
fprintf(args.output, "%s,%s,%g\n", n1, n1, 0.0);
fprintf(args.output, "%s%c%s%c%g\n", n1, args.delimiter, n1, args.delimiter, 0.0);
} else {
if (args.format == csvn) {
#pragma omp critical
fprintf(args.output, "%ld,%ld,%g\n", mapped_id, mapped_id, 0.0);
fprintf(args.output, "%ld%c%ld%c%g\n", mapped_id, args.delimiter, mapped_id, args.delimiter, 0.0);
}
}
}
Expand Down Expand Up @@ -425,12 +425,12 @@ int main(int argc, const char *argv[]) {
if (!args.do_count) {
if (args.format == csv) {
#pragma omp critical
fprintf(args.output, "%s,%s,%g\n", n1,
stringText(names, nameLengths, mapped_id2), thisD);
fprintf(args.output, "%s%c%s%c%g\n", n1,args.delimiter,
stringText(names, nameLengths, mapped_id2), args.delimiter,thisD);
} else {
if (args.format == csvn) {
#pragma omp critical
fprintf(args.output, "%ld,%ld,%g\n", mapped_id, mapped_id2,
fprintf(args.output, "%ld%c%ld%c%g\n", mapped_id, args.delimiter, mapped_id2, args.delimiter,
thisD);

} else {
Expand Down
38 changes: 26 additions & 12 deletions src/argparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace argparse
"[-c] "
"[-0] "
"[-q] "
"[-D DELIMITER]"
"[FASTA]\n";

const char help_msg[] =
Expand Down Expand Up @@ -68,6 +69,7 @@ namespace argparse
" -m compute inter- and intra-population means suitable for FST caclulations\n"
" only applied when -s is used to provide a second file\n"
" -u PROBABILITY subsample sequences with specified probability (a value between 0 and 1, default = " TO_STR ( DEFAULT_INCLUDE_PROB) ")\n"
" -D DELIMITER use this character as a delimiter in the output column-file (a character, default = " TO_STR ( DEFAULT_DELIMITER) ")\n"
" -0 report distances between each sequence and itself (as 0); this is useful to ensure every sequence\n"
" in the input file appears in the output, e.g. for network construction to contrast clustered/unclustered\n"
" -q do not report progress updates and other diagnostics to stderr \n"
Expand Down Expand Up @@ -126,7 +128,8 @@ namespace argparse
counts_in_name ( DEFAULT_COUNTS_IN_NAME ),
include_prob( DEFAULT_INCLUDE_PROB ),
ambigs_to_resolve(NULL),
resolve_fraction(DEFAULT_FRACTION)
resolve_fraction(DEFAULT_FRACTION),
delimiter (DEFAULT_DELIMITER)
{
// skip arg[0], it's just the program name
for (int i = 1; i < argc; ++i ) {
Expand All @@ -149,6 +152,7 @@ namespace argparse
else if ( arg[1] == 's') parse_second_in( next_arg (i, argc, argv) );
else if ( arg[1] == 'd') parse_counts_in_name( next_arg (i, argc, argv) );
else if ( arg[1] == 'u') parse_include_prob( next_arg (i, argc, argv) );
else if ( arg[1] == 'D') parse_delimiter ( next_arg (i, argc, argv) );
else if ( arg[1] == 'b') parse_bootstrap();
else if ( arg[1] == 'r') parse_bootstrap_two_files ();
else if ( arg[1] == 'c') parse_count();
Expand Down Expand Up @@ -275,19 +279,29 @@ namespace argparse
strcpy (ambigs_to_resolve, str);
}
}

void args_t::parse_delimiter( const char * str )
{
if (strlen (str) == 1) {
delimiter = str[0];
} else {
ERROR( "invalid output format: %s", str );
}
}

void args_t::parse_format( const char * str )
{
if (!strcmp (str, "csv")) {
format = csv;
} else if (!strcmp (str, "csvn")) {
format = csvn;
} else if (!strcmp (str, "hyphy")) {
format = hyphy;
} else {
ERROR( "invalid output format: %s", str );

void args_t::parse_format( const char * str )
{
if (!strcmp (str, "csv")) {
format = csv;
} else if (!strcmp (str, "csvn")) {
format = csvn;
} else if (!strcmp (str, "hyphy")) {
format = hyphy;
} else {
ERROR( "invalid output format: %s", str );
}
}
}

void args_t::parse_count()
{
Expand Down
3 changes: 3 additions & 0 deletions src/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define DEFAULT_COUNTS_IN_NAME ':'
#define DEFAULT_OVERLAP 100
#define DEFAULT_INCLUDE_PROB 1.0
#define DEFAULT_DELIMITER ','

#ifndef VERSION_NUMBER
#define VERSION_NUMBER "UNKNOWN"
Expand Down Expand Up @@ -56,6 +57,7 @@ namespace argparse
double include_prob;
char *ambigs_to_resolve;
double resolve_fraction;
char delimiter;

args_t( int, const char ** );
~args_t();
Expand All @@ -69,6 +71,7 @@ namespace argparse
void parse_overlap ( const char * );
void parse_format ( const char * );
void parse_ambig ( const char * );
void parse_delimiter ( const char * );
void parse_include_prob ( const char * );
void parse_counts_in_name
( const char * );
Expand Down

0 comments on commit 6fdf379

Please sign in to comment.