Skip to content

Commit

Permalink
Add numerical filters and subsampling to sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed Jun 8, 2024
1 parent 69efb51 commit 0bf5733
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/commands/convert/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -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 ) {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/convert/sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <string>
#include <vector>
Expand All @@ -41,6 +43,8 @@ class SyncOptions
public:

VariantInputOptions variant_input;
VariantFilterNumericalOptions filter_numerical;
VariantTransformSubsampleOptions transform_subsample;

CliOption<bool> without_header = false;
CliOption<bool> without_missing = false;
Expand Down

0 comments on commit 0bf5733

Please sign in to comment.