fn reassemble_contigs<K: Kmer + Copy, V: Vmer + Clone>(contigs: Vec<Vec<u8>>, stranded: bool) {
        let ctg_lens: Vec<_> = contigs.iter().map(|c| c.len()).collect();
        println!("Reassembling contig sizes: {:?}", ctg_lens);

        // kmer vector
        let mut kmers = Vec::new();
        for c in contigs.iter() {
            let mut _kmers = K::kmers_from_bytes(&c);
            kmers.extend(_kmers.iter().map(|k| k.min_rc()));
        }

        // True kmer set
        let mut kmer_set = HashSet::new();
        kmer_set.extend(kmers.iter());

        // Bsps of kmers
        let p = 6;

        let mut seqs: Vec<(V, Exts, u8)> = Vec::new();
        let permutation: Vec<usize> = (0..1 << (2 * p)).collect();
        for c in contigs.iter() {
            let msps =
                msp::msp_sequence::<Kmer6, V>(K::k(), c.as_slice(), Some(&permutation), true);
            seqs.extend(msps.clone().into_iter().map(|(_, e, v)| (v, e, 0u8)));
            seqs.extend(msps.into_iter().map(|(_, e, v)| (v, e, 1u8)));
        }

        // kmer set from bsps
        let mut msp_kmers = HashSet::new();
        for &(ref v, _, _) in seqs.iter() {
            for k in v.iter_kmers::<K>() {
                msp_kmers.insert(k.min_rc());
            }
        }

        // Kmer extensions from BSP match raw kmers
        if kmer_set != msp_kmers {
            println!("{:?}", kmer_set);
            println!("{:?}", msp_kmers);
        }

        // Raw kmers and BSP kmers match
        assert!(kmer_set == msp_kmers);

        // Check the correctness of the process_kmer_shard kmer filtering function
        let (valid_kmers, _): (BoomHashMap2<K, Exts, u16>, _) = filter::filter_kmers(
            &seqs,
            &Box::new(filter::CountFilter::new(2)),
            stranded,
            false,
            4,
        );
        let mut process_kmer_set: HashSet<K> = HashSet::new();
        for k in valid_kmers.iter().map(|x| x.0) {
            process_kmer_set.insert(k.clone());
        }
        assert_eq!(process_kmer_set, kmer_set);

        // Every kmer should be reachable as the extension of a kmer.
        // No new kmers should be reachable
        let mut extension_kmer_set: HashSet<K> = HashSet::new();
        for (kmer, exts, _) in &valid_kmers {
            for e in kmer.get_extensions(*exts, Dir::Left) {
                extension_kmer_set.insert(e.min_rc());
            }

            for e in kmer.get_extensions(*exts, Dir::Right) {
                extension_kmer_set.insert(e.min_rc());
            }
        }

        // Kmer extensions from BSP match raw kmers
        if kmer_set != extension_kmer_set {
            println!("n:{}, {:?}", kmer_set.len(), kmer_set);
            println!("n:{}, {:?}", extension_kmer_set.len(), extension_kmer_set);

            if extension_kmer_set.is_superset(&kmer_set) {
                let invented = extension_kmer_set.sub(&kmer_set);
                println!("Invented kmers: {:?}", invented);
            }
        }

        assert!(kmer_set == extension_kmer_set);

        let spec = SimpleCompress::new(|d1: u16, d2: &u16| d1.saturating_add(*d2));

        // Generate compress DBG for these kmers
        let graph = compress_kmers_with_hash(stranded, &spec, &valid_kmers);

        // Check that all the lines have valid kmers,
        // and have extensions into other valid kmers
        let mut all_contig_set = HashSet::new();

        for seq_id in 0..graph.len() {
            let seq = graph.sequences.get(seq_id);
            let exts = graph.exts[seq_id];

            let contig_set = HashSet::from_iter(seq.iter_kmers().map(|km: K| km.min_rc()));
            all_contig_set.extend(contig_set.iter());
            assert!(kmer_set.is_superset(&contig_set));

            for l_ext in exts.get(Dir::Left) {
                let f: K = seq.first_kmer();
                let ext_kmer: K = f.extend_left(l_ext);
                assert!(kmer_set.contains(&(ext_kmer.min_rc())));
            }

            for r_ext in exts.get(Dir::Right) {
                let f: K = seq.last_kmer();
                let ext_kmer: K = f.extend_right(r_ext);
                assert!(kmer_set.contains(&(ext_kmer.min_rc())));
            }
        }

        assert_eq!(kmer_set, all_contig_set);
    }
// Take some input contig, which likely form a complicated graph,
// and test the kmer, bsp, sedge and edge construction machinery
Take some input contig, which likely form a complicated graph,
and test the kmer, bsp, sedge and edge construction machinery
Take some input contig which likely form a complicated graph and test the kmer bsp sedge and edge construction machinery
fn reassemble_contigs<K: Kmer + Copy, V: Vmer + Clone>(contigs: Vec<Vec<u8>>, stranded: bool) {
        let ctg_lens: Vec<_> = contigs.iter().map(|c| c.len()).collect();
        println!("Reassembling contig sizes: {:?}", ctg_lens);
        // kmer vector
        let mut kmers = Vec::new();
        for c in contigs.iter() {
            let mut _kmers = K::kmers_from_bytes(&c);
            kmers.extend(_kmers.iter().map(|k| k.min_rc()));
        }
        // True kmer set
        let mut kmer_set = HashSet::new();
        kmer_set.extend(kmers.iter());
        // Bsps of kmers
        let p = 6;
        let mut seqs: Vec<(V, Exts, u8)> = Vec::new();
        let permutation: Vec<usize> = (0..1 << (2 * p)).collect();
        for c in contigs.iter() {
            let msps =
                msp::msp_sequence::<Kmer6, V>(K::k(), c.as_slice(), Some(&permutation), true);
            seqs.extend(msps.clone().into_iter().map(|(_, e, v)| (v, e, 0u8)));
            seqs.extend(msps.into_iter().map(|(_, e, v)| (v, e, 1u8)));
        }
        // kmer set from bsps
        let mut msp_kmers = HashSet::new();
        for &(ref v, _, _) in seqs.iter() {
            for k in v.iter_kmers::<K>() {
                msp_kmers.insert(k.min_rc());
            }
        }
        // Kmer extensions from BSP match raw kmers
        if kmer_set != msp_kmers {
            println!("{:?}", kmer_set);
            println!("{:?}", msp_kmers);
        }
        // Raw kmers and BSP kmers match
        assert!(kmer_set == msp_kmers);
        // Check the correctness of the process_kmer_shard kmer filtering function
        let (valid_kmers, _): (BoomHashMap2<K, Exts, u16>, _) = filter::filter_kmers(
            &seqs,
            &Box::new(filter::CountFilter::new(2)),
            stranded,
            false,
            4,
        );
        let mut process_kmer_set: HashSet<K> = HashSet::new();
        for k in valid_kmers.iter().map(|x| x.0) {
            process_kmer_set.insert(k.clone());
        }
        assert_eq!(process_kmer_set, kmer_set);
        // Every kmer should be reachable as the extension of a kmer.
        // No new kmers should be reachable
        let mut extension_kmer_set: HashSet<K> = HashSet::new();
        for (kmer, exts, _) in &valid_kmers {
            for e in kmer.get_extensions(*exts, Dir::Left) {
                extension_kmer_set.insert(e.min_rc());
            }
            for e in kmer.get_extensions(*exts, Dir::Right) {
                extension_kmer_set.insert(e.min_rc());
            }
        }
        // Kmer extensions from BSP match raw kmers
        if kmer_set != extension_kmer_set {
            println!("n:{}, {:?}", kmer_set.len(), kmer_set);
            println!("n:{}, {:?}", extension_kmer_set.len(), extension_kmer_set);
            if extension_kmer_set.is_superset(&kmer_set) {
                let invented = extension_kmer_set.sub(&kmer_set);
                println!("Invented kmers: {:?}", invented);
            }
        }
        assert!(kmer_set == extension_kmer_set);
        let spec = SimpleCompress::new(|d1: u16, d2: &u16| d1.saturating_add(*d2));
        // Generate compress DBG for these kmers
        let graph = compress_kmers_with_hash(stranded, &spec, &valid_kmers);
        // Check that all the lines have valid kmers,
        // and have extensions into other valid kmers
        let mut all_contig_set = HashSet::new();
        for seq_id in 0..graph.len() {
            let seq = graph.sequences.get(seq_id);
            let exts = graph.exts[seq_id];
            let contig_set = HashSet::from_iter(seq.iter_kmers().map(|km: K| km.min_rc()));
            all_contig_set.extend(contig_set.iter());
            assert!(kmer_set.is_superset(&contig_set));
            for l_ext in exts.get(Dir::Left) {
                let f: K = seq.first_kmer();
                let ext_kmer: K = f.extend_left(l_ext);
                assert!(kmer_set.contains(&(ext_kmer.min_rc())));
            }
            for r_ext in exts.get(Dir::Right) {
                let f: K = seq.last_kmer();
                let ext_kmer: K = f.extend_right(r_ext);
                assert!(kmer_set.contains(&(ext_kmer.min_rc())));
            }
        }
        assert_eq!(kmer_set, all_contig_set);
    }
fn reassemble_contigs < K : Kmer + Copy , V : Vmer + Clone > ( contigs : Vec < Vec < u8 > > , stranded : bool ) { let ctg_lens : Vec < _ > = contigs . iter ( ) . map ( | c | c . len ( ) ) . collect ( ) ; println ! ( " " ctg_lens ) ; // kmer vector let mut kmers = Vec :: new ( ) ; for c in contigs . iter ( ) { let mut _kmers = K :: kmers_from_bytes ( & c ) ; kmers . extend ( _kmers . iter ( ) . map ( | k | k . min_rc ( ) ) ) ; } // True kmer set let mut kmer_set = HashSet :: new ( ) ; kmer_set . extend ( kmers . iter ( ) ) ; // Bsps of kmers let p = 6 ; let mut seqs : Vec < ( V , Exts , u8 ) > = Vec :: new ( ) ; let permutation : Vec < usize > = ( 0 .. 1 << ( 2 * p ) ) . collect ( ) ; for c in contigs . iter ( ) { let msps = msp :: msp_sequence :: < Kmer6 , V > ( K :: k ( ) , c . as_slice ( ) , Some ( & permutation ) , true ) ; seqs . extend ( msps . clone ( ) . into_iter ( ) . map ( | ( _ , e , v ) | ( v , e , 0u8 ) ) ) ; seqs . extend ( msps . into_iter ( ) . map ( | ( _ , e , v ) | ( v , e , 1u8 ) ) ) ; } // kmer set from bsps let mut msp_kmers = HashSet :: new ( ) ; for & ( ref v , _ , _ ) in seqs . iter ( ) { for k in v . iter_kmers :: < K > ( ) { msp_kmers . insert ( k . min_rc ( ) ) ; } } // Kmer extensions from BSP match raw kmers if kmer_set != msp_kmers { println ! ( " " kmer_set ) ; println ! ( " " msp_kmers ) ; } // Raw kmers and BSP kmers match assert ! ( kmer_set msp_kmers ) ; // Check the correctness of the process_kmer_shard kmer filtering function let ( valid_kmers , _ ) : ( BoomHashMap2 < K , Exts , u16 > , _ ) = filter :: filter_kmers ( & seqs , & Box :: new ( filter :: CountFilter :: new ( 2 ) ) , stranded , false , 4 , ) ; let mut process_kmer_set : HashSet < K > = HashSet :: new ( ) ; for k in valid_kmers . iter ( ) . map ( | x | x . 0 ) { process_kmer_set . insert ( k . clone ( ) ) ; } assert_eq ! ( process_kmer_set kmer_set ) ; // Every kmer should be reachable as the extension of a kmer. // No new kmers should be reachable let mut extension_kmer_set : HashSet < K > = HashSet :: new ( ) ; for ( kmer , exts , _ ) in & valid_kmers { for e in kmer . get_extensions ( * exts , Dir :: Left ) { extension_kmer_set . insert ( e . min_rc ( ) ) ; } for e in kmer . get_extensions ( * exts , Dir :: Right ) { extension_kmer_set . insert ( e . min_rc ( ) ) ; } } // Kmer extensions from BSP match raw kmers if kmer_set != extension_kmer_set { println ! ( " " kmer_set len ( ) kmer_set ) ; println ! ( " " extension_kmer_set len ( ) extension_kmer_set ) ; if extension_kmer_set . is_superset ( & kmer_set ) { let invented = extension_kmer_set . sub ( & kmer_set ) ; println ! ( " " invented ) ; } } assert ! ( kmer_set extension_kmer_set ) ; let spec = SimpleCompress :: new ( | d1 : u16 , d2 : & u16 | d1 . saturating_add ( * d2 ) ) ; // Generate compress DBG for these kmers let graph = compress_kmers_with_hash ( stranded , & spec , & valid_kmers ) ; // Check that all the lines have valid kmers, // and have extensions into other valid kmers let mut all_contig_set = HashSet :: new ( ) ; for seq_id in 0 .. graph . len ( ) { let seq = graph . sequences . get ( seq_id ) ; let exts = graph . exts [ seq_id ] ; let contig_set = HashSet :: from_iter ( seq . iter_kmers ( ) . map ( | km : K | km . min_rc ( ) ) ) ; all_contig_set . extend ( contig_set . iter ( ) ) ; assert ! ( kmer_set is_superset ( contig_set ) ) ; for l_ext in exts . get ( Dir :: Left ) { let f : K = seq . first_kmer ( ) ; let ext_kmer : K = f . extend_left ( l_ext ) ; assert ! ( kmer_set contains ( ( ext_kmer min_rc ( ) ) ) ) ; } for r_ext in exts . get ( Dir :: Right ) { let f : K = seq . last_kmer ( ) ; let ext_kmer : K = f . extend_right ( r_ext ) ; assert ! ( kmer_set contains ( ( ext_kmer min_rc ( ) ) ) ) ; } } assert_eq ! ( kmer_set all_contig_set ) ; }
Take some input contig, which likely form a complicated graph,
and test the kmer, bsp, sedge and edge construction machinery
Take some input contig which likely form a complicated graph and test the kmer bsp sedge and edge construction machinery
contigs
Vec<Vec<u8>>
stranded
bool
contigs
Vec<Vec<u8>>
stranded
bool