fn reassemble_sharded<K: Kmer + Copy + Sync + Send, 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 kmer_set = HashSet::new();
        for c in contigs.iter() {
            let mut _kmers = K::kmers_from_bytes(&c);
            kmer_set.extend(_kmers.iter().map(|k| k.min_rc()));
        }

        // Bsps of kmers
        let mut shards = HashMap::new();

        for ctg in contigs.iter() {
            let msps = msp::msp_sequence::<Kmer6, V>(K::k(), ctg.as_slice(), None, true);

            for (shard, exts, seq) in msps {
                let shard_vec = shards.entry(shard).or_insert_with(|| Vec::new());
                shard_vec.push((seq.clone(), exts, 0u8));
                shard_vec.push((seq, exts, 1u8));
            }
        }

        let mut shard_asms = Vec::new();

        // Do a subassembly in each shard
        for seqs in shards.values() {
            // 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,
            );

            // Generate compress DBG for this shard
            let spec = SimpleCompress::new(|d1: u16, d2: &u16| d1.saturating_add(*d2));

            //print!("{:?}", valid_kmers);
            let graph = compress_kmers_with_hash(stranded, &spec, &valid_kmers);
            shard_asms.push(graph.clone());
            //graph.finish().print();
        }

        // Shove the subassemblies into a partially compress base graph
        let combined_graph = BaseGraph::combine(shard_asms.into_iter()).finish();
        let cmp = SimpleCompress::new(|a: u16, b: &u16| max(a, *b));
        let dbg_graph = compress_graph(false, &cmp, combined_graph, None);

        // Switch on for debugging
        //dbg_graph.print();
        //dbg_graph.write_gfa(&mut std::io::stdout().lock());

        let graph = dbg_graph.base;

        // 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 the msp / shard_asm / main_asm loop
Take some input contig, which likely form a complicated graph,
and the msp / shard_asm / main_asm loop
Take some input contig which likely form a complicated graph and the msp / shard_asm / main_asm loop
fn reassemble_sharded<K: Kmer + Copy + Sync + Send, 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 kmer_set = HashSet::new();
        for c in contigs.iter() {
            let mut _kmers = K::kmers_from_bytes(&c);
            kmer_set.extend(_kmers.iter().map(|k| k.min_rc()));
        }
        // Bsps of kmers
        let mut shards = HashMap::new();
        for ctg in contigs.iter() {
            let msps = msp::msp_sequence::<Kmer6, V>(K::k(), ctg.as_slice(), None, true);
            for (shard, exts, seq) in msps {
                let shard_vec = shards.entry(shard).or_insert_with(|| Vec::new());
                shard_vec.push((seq.clone(), exts, 0u8));
                shard_vec.push((seq, exts, 1u8));
            }
        }
        let mut shard_asms = Vec::new();
        // Do a subassembly in each shard
        for seqs in shards.values() {
            // 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,
            );
            // Generate compress DBG for this shard
            let spec = SimpleCompress::new(|d1: u16, d2: &u16| d1.saturating_add(*d2));
            //print!("{:?}", valid_kmers);
            let graph = compress_kmers_with_hash(stranded, &spec, &valid_kmers);
            shard_asms.push(graph.clone());
            //graph.finish().print();
        }
        // Shove the subassemblies into a partially compress base graph
        let combined_graph = BaseGraph::combine(shard_asms.into_iter()).finish();
        let cmp = SimpleCompress::new(|a: u16, b: &u16| max(a, *b));
        let dbg_graph = compress_graph(false, &cmp, combined_graph, None);
        // Switch on for debugging
        //dbg_graph.print();
        //dbg_graph.write_gfa(&mut std::io::stdout().lock());
        let graph = dbg_graph.base;
        // 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_sharded < K : Kmer + Copy + Sync + Send , 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 kmer_set = HashSet :: new ( ) ; for c in contigs . iter ( ) { let mut _kmers = K :: kmers_from_bytes ( & c ) ; kmer_set . extend ( _kmers . iter ( ) . map ( | k | k . min_rc ( ) ) ) ; } // Bsps of kmers let mut shards = HashMap :: new ( ) ; for ctg in contigs . iter ( ) { let msps = msp :: msp_sequence :: < Kmer6 , V > ( K :: k ( ) , ctg . as_slice ( ) , None , true ) ; for ( shard , exts , seq ) in msps { let shard_vec = shards . entry ( shard ) . or_insert_with ( | | Vec :: new ( ) ) ; shard_vec . push ( ( seq . clone ( ) , exts , 0u8 ) ) ; shard_vec . push ( ( seq , exts , 1u8 ) ) ; } } let mut shard_asms = Vec :: new ( ) ; // Do a subassembly in each shard for seqs in shards . values ( ) { // 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 , ) ; // Generate compress DBG for this shard let spec = SimpleCompress :: new ( | d1 : u16 , d2 : & u16 | d1 . saturating_add ( * d2 ) ) ; //print!("{:?}", valid_kmers); let graph = compress_kmers_with_hash ( stranded , & spec , & valid_kmers ) ; shard_asms . push ( graph . clone ( ) ) ; //graph.finish().print(); } // Shove the subassemblies into a partially compress base graph let combined_graph = BaseGraph :: combine ( shard_asms . into_iter ( ) ) . finish ( ) ; let cmp = SimpleCompress :: new ( | a : u16 , b : & u16 | max ( a , * b ) ) ; let dbg_graph = compress_graph ( false , & cmp , combined_graph , None ) ; // Switch on for debugging //dbg_graph.print(); //dbg_graph.write_gfa(&mut std::io::stdout().lock()); let graph = dbg_graph . base ; // 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 the msp / shard_asm / main_asm loop
Take some input contig which likely form a complicated graph and the msp / shard_asm / main_asm loop
contigs
Vec<Vec<u8>>
stranded
bool
contigs
Vec<Vec<u8>>
stranded
bool