Skip to content

Commit

Permalink
Control float print precision
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaliun committed May 5, 2020
1 parent bba9692 commit f7c1f07
Show file tree
Hide file tree
Showing 5 changed files with 2,599 additions and 10 deletions.
36 changes: 27 additions & 9 deletions metal/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ bool strictColumnCounting = true;
bool verbose = false;
bool logPValue = false;
bool trackPositions = false;
int effectPrintPrecision = 4;
int stderrPrintPrecision = 4;

String genomicControlFilter;
double genomicControlLambda = 0.0;
Expand Down Expand Up @@ -646,9 +648,9 @@ void Analyze(bool heterogeneity) {
fprintf(f, "%.4f\t%.4f\t", minFrequency, maxFrequency);

fprintf(f, "%.*f\t%.*f\t",
useStandardErrors ? 4 : 2,
useStandardErrors ? effectPrintPrecision : 2,
useStandardErrors ? statistics[marker] / weights[marker] : weights[marker],
useStandardErrors ? 4 : 3,
useStandardErrors ? stderrPrintPrecision : 3,
useStandardErrors ? sqrt(1.0 / weights[marker]) : statistic);

if (studyOverlap) {
Expand Down Expand Up @@ -1708,12 +1710,14 @@ void ShowHelp(bool startup)
"# ZCUTOFF [NUMBER] (%s = %.1f)\n"
"#\n"
"# Options for general analysis control ...\n"
"# PROCESSFILE [FILENAME]\n"
"# OUTFILE [PREFIX SUFFIX] (default = 'METAANALYSIS','.TBL')\n"
"# MAXWARNINGS [NUMBER] (%s = %d)\n"
"# VERBOSE [ON|OFF] (%s = '%s')\n"
"# LOGPVALUE [ON|OFF] (%s = '%s')\n"
"# ANALYZE [HETEROGENEITY]\n"
"# PROCESSFILE [FILENAME]\n"
"# OUTFILE [PREFIX SUFFIX] (default = 'METAANALYSIS','.TBL')\n"
"# MAXWARNINGS [NUMBER] (%s = %d)\n"
"# VERBOSE [ON|OFF] (%s = '%s')\n"
"# LOGPVALUE [ON|OFF] (%s = '%s')\n"
"# EFFECT_PRINT_PRECISION [NUMBER] (%s = '%d')\n"
"# STDERR_PRINT_PRECISION [NUMBER] (%s = '%d')\n"
"# ANALYZE [HETEROGENEITY]\n"
"# CLEAR\n\n"
"# Options for general run control ...\n"
"# SOURCE [SCRIPTFILE]\n"
Expand Down Expand Up @@ -1742,7 +1746,9 @@ void ShowHelp(bool startup)
setting, zCutoff,
setting, maxWarnings,
setting, verbose ? "ON" : "OFF",
setting, logPValue ? "ON" : "OFF");
setting, logPValue ? "ON" : "OFF",
setting, effectPrintPrecision,
setting, stderrPrintPrecision);
}

void RunScript(FILE * file)
Expand Down Expand Up @@ -2131,6 +2137,18 @@ void RunScript(FILE * file)
}
}

if ((tokens[0].MatchesBeginningOf("EFFECT_PRINT_PRECISION") == 0) && (tokens.Length() > 1)) {
effectPrintPrecision = tokens[1].AsInteger();
printf("## Set print pecision for Effect to %d ...\n", effectPrintPrecision);
continue;
}

if ((tokens[0].MatchesBeginningOf("STDERR_PRINT_PRECISION") == 0) && (tokens.Length() > 1)) {
stderrPrintPrecision = tokens[1].AsInteger();
printf("## Set print pecision for StdErr to %d ...\n", stderrPrintPrecision);
continue;
}

if (tokens[0].MatchesBeginningOf("ZCUTOFF") == 0) {
zCutoff = tokens[1].AsDouble();
printf("## Set Z cutoff to %.2f ...\n", zCutoff);
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ add_test(NAME TRACK_POSITIONS WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test
COMMAND ${CMAKE_COMMAND}
-DMETAL=${CMAKE_BINARY_DIR}/metal/metal
-DMETAL_TBL=${CMAKE_CURRENT_SOURCE_DIR}/test_09/METAANALYSIS1.TBL
-P ${CMAKE_CURRENT_SOURCE_DIR}/compare.cmake)

file(COPY test_10 DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME PRINT_PRECISION WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_10
COMMAND ${CMAKE_COMMAND}
-DMETAL=${CMAKE_BINARY_DIR}/metal/metal
-DMETAL_TBL=${CMAKE_CURRENT_SOURCE_DIR}/test_10/METAANALYSIS1.TBL
-P ${CMAKE_CURRENT_SOURCE_DIR}/compare.cmake)
Loading

0 comments on commit f7c1f07

Please sign in to comment.