Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GA4GHTT-276: 4.4 changes - optional meta, format CN, CICN, PSL, PSO, PSQ #254

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions inc/util/string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ namespace ebi
output.swap(ret);
}

/** extended version of string_split
* Splits `s` using `delims` as separator and fills the container `ret` with the parts.
* The delimiter can be retained based on parameter @withdelim
* An empty string results in an empty container `ret`.
* With false for withdelim, 1st leading delimiter will result in an empty string (/1 -> "", "1")
* @param s input string to split
* @param delims any character here acts as a separator
* @param withdelim - true to retain delimiter and false to split without delimiter
* @param ret return by reference the container filled with the string split.
*/
template<typename C>
void string_split_ex(std::string const & s, char const * delims, C & ret, bool withdelim)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need to keep both implementation ?
If you don't want to replace all calls to the extended version I would at least use string_split_ex in string_split

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was retained to avoid any impact.
Updated to use _ex with no delimiter and tests succeeded without any failure.
Updated PR with the change.

{
C output;

if (s.size() > 0) {
char const* p = s.c_str();
char const* q = strpbrk(p + (withdelim ? 1 : 0), delims);

// Insert first to last-1 elements
for( ; q != NULL; q = strpbrk(p + (withdelim ? 1 : 0), delims) )
{
output.push_back(typename C::value_type(p, q));
p = q + (withdelim ? 0 : 1);
}

// Insert last element
if (p < &(s.back()) + 1) {
output.push_back(typename C::value_type(p));
}
}

output.swap(ret);
}
/**
* Temporal implementation for mismatch with 2 starts and 2 ends. It is not in STL for c++11, but it will in c++14.
*
Expand Down
34 changes: 30 additions & 4 deletions inc/vcf/file_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ namespace ebi
{ ADF, { INTEGER, R } },
{ ADR, { INTEGER, R } },
{ AHAP, { INTEGER, "1" } },
{ CICN, { FLOAT, "2" } },
{ CN, { FLOAT, "1" } },
{ CNL, { FLOAT, G } },
{ CNP, { FLOAT, G } },
Expand All @@ -283,7 +284,10 @@ namespace ebi
{ NQ, { INTEGER, "1" } },
{ PL, { INTEGER, G } },
{ PQ, { INTEGER, "1" } },
{ PS, { INTEGER, "1" } }
{ PS, { INTEGER, "1" } },
{ PSL, { STRING, P } },
{ PSO, { INTEGER, P } },
{ PSQ, { INTEGER, P } },
};

const std::set<std::string> PREDEFINED_INFO_SVTYPES{
Expand Down Expand Up @@ -662,22 +666,24 @@ namespace ebi

/**
* returns the expected number of elements, given a string code
* @param number one of ["A", "R", "G", ".", number], where
* @param number one of ["A", "R", "G", ".", number, "P"], where
* - "A" is the amount of alleles,
* - "R" the amount of reference (1) plus alleles (A)
* - "G" is `ploidy`-combination with repetition: ((R + ploidy -1) choose ploidy)
* (e.g. with 1 reference, 2 alternate alleles (3 total alleles) and ploidy 2, it's 3 + 2 -1 choose 2, which is 6: 00, 01, 11, 02, 12, 22)
* - "." means unknown number of elements
* - number is a positive number [0, +inf)
* - "P" is the alleles in GT
vasudeva8 marked this conversation as resolved.
Show resolved Hide resolved
* @param alternate_allele_number the number of alternate alleles
* @param ploidy is the number of copies of a chromosome in a sample, so a given genotype in said chromosome needs `ploidy` alleles to be completely specified
* @param expected_cardinality return by reference [0, +inf) for valid numbers. -1 if unknown number.
* @param isinfo indicates whether the check is for info field or not
* @throw std::invalid_argument if it's not a number
* @throw std::out_of_range if it's out of range.
* @return bool: whether the number was valid or not
*/
bool is_valid_cardinality(std::string const &number, size_t alternate_allele_number, size_t ploidy,
long &expected_cardinality) const;
long &expected_cardinality, bool isinfo) const;

/**
* Checks that the values match either their type specified in the meta or the VCF specification for predefined tags not in meta
Expand All @@ -699,7 +705,7 @@ namespace ebi
* @throw std::invalid_argument
*/
void check_sample_field_cardinality(std::vector<std::string> const &values, std::string const &number,
size_t ploidy, long &expected_cardinality) const;
size_t ploidy, long &expected_cardinality, bool isinfo = false) const;

/**
* Checks that every field in a column matches the Type specification in the meta
Expand Down Expand Up @@ -734,6 +740,26 @@ namespace ebi
*/
int check_info_field_cardinality_explicit(std::vector<std::string> const & values, size_t expected,
const std::string field) const;

/**
* Checks CICN field is present along with CN field
*/
void check_format_CICN() const;

/**
* Checks specific SV alleles have same SVLEN when format CN is present
*/
void check_format_allele_SVLEN() const;

/**
* Gets alleles from GT with phasing information
*/
void get_phased_alleles(std::string GT, std::vector<std::string>& alleles) const;

/**
* Gets PSL values from samples
*/
void get_PSL_values(size_t i, std::vector<std::string>& pslvalues) const;
};

std::ostream &operator<<(std::ostream &os, const Record &record);
Expand Down
2 changes: 1 addition & 1 deletion inc/vcf/meta_entry_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ebi
void check_filter(std::map<std::string, std::string> & value) const;
void check_filter_id(std::string const & id_field) const;
void check_format(std::map<std::string, std::string> & value) const;
void check_format_or_info_number(std::string const & number_field, std::string const & field) const;
void check_format_or_info_number(std::string const & number_field, std::string const & field, bool isinfo) const;
void check_format_type(std::string const & type_field) const;
void check_info(std::map<std::string, std::string> & value) const;
void check_info_type(std::string const & type_field) const;
Expand Down
1 change: 1 addition & 0 deletions inc/vcf/optional_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace ebi
void check_filter_meta(ParsingState & state, Record const & record) const;
void check_info_meta(ParsingState & state, Record const & record) const;
void check_format_meta(ParsingState & state, Record const & record) const;
void check_body_entry_sample_confidence_interval(ParsingState & state, Record const & record) const;
};

}
Expand Down
4 changes: 4 additions & 0 deletions inc/vcf/string_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace ebi
const std::string G = "G";
const std::string R = "R";
const std::string UNKNOWN_CARDINALITY = ".";
const std::string P = "P";

// Pass value for Filter
const std::string PASS = "PASS";
Expand Down Expand Up @@ -192,6 +193,9 @@ namespace ebi
const std::string PL = "PL";
const std::string PQ = "PQ";
const std::string PS = "PS";
const std::string PSL = "PSL";
const std::string PSO = "PSO";
const std::string PSQ = "PSQ";

// File extensions
const std::string VCF_EXT = ".vcf";
Expand Down
Loading