From 0bf5733046e146109a4fb3ff3b55d9327982928f Mon Sep 17 00:00:00 2001 From: Lucas Czech Date: Sat, 8 Jun 2024 16:25:14 +0200 Subject: [PATCH] Add numerical filters and subsampling to sync command --- src/commands/convert/sync.cpp | 20 ++++++++++++++++++++ src/commands/convert/sync.hpp | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/commands/convert/sync.cpp b/src/commands/convert/sync.cpp index 24eb8f6..697f438 100644 --- a/src/commands/convert/sync.cpp +++ b/src/commands/convert/sync.cpp @@ -49,6 +49,13 @@ void setup_sync( CLI::App& app ) // Required input of some frequency format (mpileup or vcf at the moment). options->variant_input.add_variant_input_opts_to_app( sub ); + // Add the numerical filters + options->filter_numerical.add_sample_filter_opts_to_app( sub ); + options->filter_numerical.add_total_filter_opts_to_app( sub ); + + // Also offer subsampling options for this command. + options->transform_subsample.add_subsample_opts_to_app( sub ); + // ------------------------------------------------------------------------- // Settings // ------------------------------------------------------------------------- @@ -189,6 +196,19 @@ void run_sync( SyncOptions const& options ) ); } + // Before accessing the variant input, we need to add the filters to it. + options.variant_input.add_combined_filter_and_transforms( + options.filter_numerical.make_sample_filter() + ); + options.variant_input.add_combined_filter_and_transforms( + options.filter_numerical.make_total_filter() + ); + + // Lastly, apply the subsampling. It is important that this happens after the above numercial + // filters above, as otherwise we might subsample to a lower read depth, and then want to apply + // a read depth filter, which would not work any more. + options.transform_subsample.add_subsample_transformation( options.variant_input ); + // If we want to create a gsync file, activate this in the input stream. // Needs to be set before any reading access to the stream. if( options.gapless.value ) { diff --git a/src/commands/convert/sync.hpp b/src/commands/convert/sync.hpp index 558518f..0b51be4 100644 --- a/src/commands/convert/sync.hpp +++ b/src/commands/convert/sync.hpp @@ -3,7 +3,7 @@ /* grenedalf - Genome Analyses of Differential Allele Frequencies - Copyright (C) 2020-2023 Lucas Czech + Copyright (C) 2020-2024 Lucas Czech This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ #include "options/file_output.hpp" #include "options/variant_input.hpp" +#include "options/variant_filter_numerical.hpp" +#include "options/variant_transform_subsample.hpp" #include #include @@ -41,6 +43,8 @@ class SyncOptions public: VariantInputOptions variant_input; + VariantFilterNumericalOptions filter_numerical; + VariantTransformSubsampleOptions transform_subsample; CliOption without_header = false; CliOption without_missing = false;