/// A recursive helper function for `generate_haps`. Generates possible haplotypes for a variant cluster
///  from the k-th variant onwards.
///
/// #Arguments
/// -`var_cluster`: vector of variants
///- `k`: an integer
/// #Returns
/// Returns a vector of all possible haplotypes from the k-th variant onward,
/// where each haplotype is a vector of u8s representing sequence of alleles
A recursive helper function for `generate_haps`. Generates possible haplotypes for a variant cluster
from the k-th variant onwards.
A recursive helper function for ` generate_haps ` . Generates possible haplotypes for a variant cluster from the k - th variant onwards .
fn generate_haps_k_onward(var_cluster: &Vec<Var>, k: usize) -> Vec<Vec<u8>> {
    // base case
    // return a haplotype list with a single empty haplotype
    if k >= var_cluster.len() {
        return vec![vec![]];
    }
    // recursive call
    // we generate the haplotypes from k onward by generating all the haplotype suffixes from k+1 onward
    let hap_suffixes = generate_haps_k_onward(var_cluster, k + 1);
    let c = (hap_suffixes.len() * var_cluster[k].alleles.len()) as usize;
    let mut hap_list: Vec<Vec<u8>> = Vec::with_capacity(c);
    // we iterate over the possible alleles for the k-th variant and for each one, append it
    // to each of those haplotype suffixes.
    for a in 0..var_cluster[k].alleles.len() {
        for mut hap_suffix in hap_suffixes.clone() {
            let mut hap = Vec::with_capacity(var_cluster.len() - k);
            hap.push(a as u8);
            hap.append(&mut hap_suffix);
            hap_list.push(hap);
        }
    }
    hap_list
}
fn generate_haps_k_onward ( var_cluster : & Vec < Var > , k : usize ) -> Vec < Vec < u8 > > { // base case // return a haplotype list with a single empty haplotype if k >= var_cluster . len ( ) { return vec ! [ vec [ ] ] ; } // recursive call // we generate the haplotypes from k onward by generating all the haplotype suffixes from k+1 onward let hap_suffixes = generate_haps_k_onward ( var_cluster , k + 1 ) ; let c = ( hap_suffixes . len ( ) * var_cluster [ k ] . alleles . len ( ) ) as usize ; let mut hap_list : Vec < Vec < u8 > > = Vec :: with_capacity ( c ) ; // we iterate over the possible alleles for the k-th variant and for each one, append it // to each of those haplotype suffixes. for a in 0 .. var_cluster [ k ] . alleles . len ( ) { for mut hap_suffix in hap_suffixes . clone ( ) { let mut hap = Vec :: with_capacity ( var_cluster . len ( ) - k ) ; hap . push ( a as u8 ) ; hap . append ( & mut hap_suffix ) ; hap_list . push ( hap ) ; } } hap_list }
A recursive helper function for `generate_haps`.
A recursive helper function for ` generate_haps ` .
Returns a vector of all possible haplotypes from the k-th variant onward,
where each haplotype is a vector of u8s representing sequence of alleles
Returns a vector of all possible haplotypes from the k - th variant onward where each haplotype is a vector of u8s representing sequence of alleles
var_cluster
&Vec<Var>
vector of variants
`k`: an integer
vector of variants ` k ` : an integer
k
usize