# Notebook from fedarko/sheepgut
Path: notebooks/Phasing-LJA.ipynb

# Perform read smoothing then assemble with LJA_____no_output_____

%run "Header.ipynb"
%run "../main-workflow/utils.py"_____no_output_____import os
import time
import pickle
import pysam
import skbio
from collections import defaultdict, Counter
from statistics import mean
from linked_mutations_utils import find_mutated_positions_____no_output_____

## 0. Quick sanity check: ensure that all $k$-mers ($k$ = 5,001) are unique in each MAG_____no_output_____

# (Commenting out for now, because I've already checked this and I don't see any reason to keep rerunning this
# for the same set of MAGs.)
# # I know there are actual k-mer counting tools you can use but no reason to overcomplicate things for now

# k = 5001

# for seq in SEQS:
#     fasta = skbio.DNA.read(f"../seqs/{seq}.fasta")
#     bargain_bin_kmer_counter = Counter()

#     # The skbio.DNA object is 0-indexed, so 0 is the leftmost k-mer start position and
#     # ((seq length) - k) is the rightmost k-mer start position. The + 1 is because python ranges don't include
#     # the right endpoint.
#     for start_pos in range(0, seq2len[seq] - k + 1):

#         # NOTE: this is a terrible no good very bad way to do this; it's more efficient to use a "sliding window"
#         # approach where you store the entire k-mer and then, with each step, just remove the first character and
#         # add on a new last character. "But, uh, this code will only be run on these three MAGs, so I'm gonna
#         # prioritize clarity over optimization," says me, the insane person who just spent like a minute writing
#         # this comment when I could've been optimizing this code instead look WHATEVER this counts k-mers and it's
#         # 4am let's not overcomplicate it, look if you're on GitHub right now and you see this inane comment
#         # we can both just pretend that you were looking at some really optimized code and we'll both walk away
#         # satisfied, capisce
#         kmer = fasta[start_pos : start_pos + k]

#         bargain_bin_kmer_counter[str(kmer)] += 1
#         if start_pos % 1000000 == 0: print(f"On start pos {start_pos:,} in {seq2name[seq]}.")

#     mckc = bargain_bin_kmer_counter.most_common(1)[0][1]
#     print(f"The most common k = {k:,}-mer in {seq2name[seq]} occurred {mckc:,} time(s).")_____no_output_____

## 1. Smooth reads

Lots of this code is duplicated from the `Phasing-01-MakeGraph.ipynb` notebook in this folder._____no_output_____

# Set this to True to actually generate ordinary smoothed reads that include called mutations;
# set this to False to generate "sanity check" perfect smoothed reads, where no mutations are included
# and the read entirely matches the reference
actually_include_mutations_in_the_smoothed_reads = True

add_virtual_reads = True_____no_output_____# We'll need to know the mean coverage of each sequence when computing virtual reads.
seq2meancov = get_meancovs()
seq2meancovSequence edge_6104 has average coverage 4,158.57 and median coverage 4,122.00.
Sequence edge_1671 has average coverage 1,415.07 and median coverage 1,436.00.
Sequence edge_2358 has average coverage 2,993.46 and median coverage 2,936.00.
bf = pysam.AlignmentFile("../main-workflow/output/fully-filtered-and-sorted-aln.bam", "rb")
output_dir = "phasing-data/smoothed-reads/"

# verbose?
no_indoor_voice = False

def write_out_reads(filepath, readname2seq):
    # Notably, this uses the "a" (append) method in order to add to the end of a file.
    # Be careful -- if you're rerunning this, you'll
    with open(filepath, "a") as of:
        for readname in readname2seq:
            # Write out both the header and the sequence for each read
            of.write(f">{readname}\n{str(readname2seq[readname])}\n")

ALN_UPDATE_FREQ = 5000
ALN_BUFFER_FREQ = 1000
VR_EXTRA_SPAN = 100
# in the range [0, 1]
MIN_WELL_COV_FRAC = 0.95

P = 1

t1 = time.time()
for seq in SEQS:

    # How much coverage does a given position require to be classified as not "low coverage"?
    # Defined as some fraction of the average coverage of this MAG.
    min_well_cov = MIN_WELL_COV_FRAC * seq2meancov[seq]

    # As we construct smoothed reads, identify which positions (0-indexed) have
    # "low coverage" (a coverage of < min_well_cov). We'll add "virtual reads" that
    # span runs of these positions.
    pos2srcov = {pos: 0 for pos in range(0, seq2len[seq])}

    fasta = skbio.DNA.read(f"../seqs/{seq}.fasta")

    output_smoothed_reads_file = os.path.join(output_dir, f"{seq}_smoothed_reads_delignore_vrlow.fasta")
    try:
        os.remove(output_smoothed_reads_file)
    except FileNotFoundError:
        # it's fine if this file doesn't exist yet. what we DON'T want to happen is this file to already exist after
        # this point in the code; since we only use "append" file-writing to write out smoothed reads, if we don't
        # manually remove this file then running this script twice will cause weird behavior where the file contains
        # the same smoothed reads multiple times, etc.
        pass

    # Identify all (0-indexed, so compatible with skbio / pysam!)
    # mutated positions in this genome up front to save time.
    #
    # Equivalently, we could also just take in an arbitrary VCF as input
    # (e.g. one produced from another variant calling tool), although we'd
    # need to be careful to only include SNVs and not indels/etc...

    print("=" * 70)
    print(f"Identifying mutated positions (p = {P}%) in genome {seq2name[seq]}...")
    mutpos2pileup = find_mutated_positions(seq, p_to_use=P, incl_pileup=True)
    # We sort because the code below relies on these being in ascending order
    mutated_positions = sorted(mutpos2pileup.keys())
    print(f"Found {len(mutated_positions):,} mutated positions (p = {P}%) in {seq2name[seq]}.")
    print(
        f"Note that this tally is higher than you'd see in e.g. the CP1/2/3 plots, because now we're including "
        "both 'rare' and non-rare mutations. Just so you don't waste five minutes sanity-checking this like I did."
    )

    print("Going through these positions...")

    num_ignored_alns = 0

    # Instead of just writing out every smoothed alignment as soon as we generate it, we build up a "buffer"
    # of these alignments and then write a bunch out at once. This way we limit slowdown due to constantly
    # having to open/close files. I don't really have a good source for this as best practice, but I remembered
    # to do it while writing this code, so somewhere in College Park the CS faculty at Maryland are smiling
    #
    # Also fyi this maps read name to smoothed alignment (well, at this point, just read) sequence. The read name
    # is useful to preserve in fasta files so we have some idea of provenance (where smoothed reads came from)
    smoothed_aln_buffer = {}

    # The first time we see an alignment of a read, it's 1; if we see a supp aln of this read, it's 2; etc.
    # Lets us distinguish alignments with different names
    readname2freq_so_far = defaultdict(int)

    # Go through all linear alignments of each read to this genome, focusing (for now) on just the primary
    # alignments...
    ts1 = time.time()
    for ai, aln in enumerate(bf.fetch(seq), 1):

        if ai % ALN_UPDATE_FREQ == 0:
            print(
                f"\tOn aln {ai:,} in seq {seq2name[seq]}. "
                f"Time spent on {seq2name[seq]} so far: {time.time() - ts1:,.2f} sec."
            )

        if aln.is_secondary:
            raise ValueError(
                "Not to get political or anything, but you should've already filtered secondary alns out"
            )

        # Note that supplementary alignments are ok, though! We implicitly handle these here.
        #
        # Different alignments of the same read will have different new_readnames, because we're gonna
        # be treating them as distinct "reads". We should have already filtered reference-overlapping
        # supp alns so this shouldn't be a problem

        readname = aln.query_name
        readname2freq_so_far[readname] += 1
        new_readname = f"{readname}_{readname2freq_so_far[readname]}"

        # should never happen
        if new_readname in smoothed_aln_buffer:
            raise ValueError("This exact read alignment has already been smoothed? Weird.")

        # Figure out where on the MAG this alignment "hits." These are 0-indexed positions from Pysam.
        # (reference_end points to the position after the actual final position, since these are designed to
        # be interoperable with Python's half-open intervals.)
        #
        # Of course, there likely will be indels within this range: we're purposefully ignoring those here.
        ref_start = aln.reference_start
        ref_end = aln.reference_end - 1

        # This should never happen (TM)
        if ref_start >= ref_end:
            # Du sollst jetzt mit Gott sprechen.
            raise ValueError(
                f"Ref start {ref_start:,} >= ref end {ref_end:,} for read {new_readname}?"
            )

        # Smoothed sequence; we'll edit this so that if this read has (mis)matches to any called mutated
        # positions, these positions are updated with the read's aligned nucleotides at these positions.
        smoothed_aln_seq = fasta[ref_start: ref_end + 1]

        if actually_include_mutations_in_the_smoothed_reads:
            # just for debugging: track the exact edits made to smoothed_aln_seq
            replacements_made = {}

            # We may choose to ignore this linear alignment, if we think it is error-prone or
            # otherwise not useful. If this gets set to True in the loop below, then we'll notice this
            # and ignore this alignment.
            ignoring_this_aln = False

            # Notably, include skips -- this way, we can figure out if the aln has a deletion at a mutated
            # position, and if so ignore this aln
            ap = aln.get_aligned_pairs(matches_only=False)

            # Iterating through the aligned pairs is expensive. Since read lengths are generally in the thousands
            # to tens of thousands of bp (which is much less than the > 1 million bp length of any bacterial genome),
            # we set things up so that we only iterate through the aligned pairs once. We maintain an integer, mpi,
            # that is a poor man's "pointer" to an index in mutated_positions.

            mpi = 0

            # Go through this aln's aligned pairs. As we see each pair, compare the pair's reference position
            # (refpos) to the mpi-th mutated position (herein referred to as "mutpos").
            #
            # If refpos >  mutpos, increment mpi until refpos <= mutpos (stopping as early as possible).
            # If refpos == mutpos, we have a match! Update readname2mutpos2ismutated[mutpos] based on
            #                      comparing the read to the reference at the aligned positions.
            # If refpos <  mutpos, continue to the next pair.

            for pair in ap:

                refpos = pair[1]

                # Since we set matches_only (for get_aligned_pairs()) to False, the alignment could include
                # insertions (which are encoded as the reference pos being set to None). We inherently ignore
                # these insertions as part of the read smoothing process.
                if refpos is None:
                    continue

                mutpos = mutated_positions[mpi]

                no_mutations_to_right_of_here = False

                # Increment mpi until we get to the next mutated position at or after the reference pos for this
                # aligned pair (or until we run out of mutated positions).
                while refpos > mutpos:
                    mpi += 1
                    if mpi < len(mutated_positions):
                        mutpos = mutated_positions[mpi]
                    else:
                        no_mutations_to_right_of_here = True
                        break

                # I expect this should happen only for reads aligned near the right end of the genome.
                if no_mutations_to_right_of_here:
                    break

                # If the next mutation occurs after this aligned pair, continue on to a later pair.
                if refpos < mutpos:
                    continue

                # If we've made it here, refpos == mutpos!
                # (...unless I messed something up in how I designed this code.)
                if refpos != mutpos:
                    raise ValueError("This should never happen!")

                # Finally, get the nucleotide aligned to this mutated position from this read.
                readpos = pair[0]

                # Since we set matches_only (for get_aligned_pairs()) to False, there's a chance a read
                # contains deletions aligned to mutated positions. This is accounted for by this case.
                # If this happens, we ignore this alignment (the same as if it would contain a nt that
                # isn't the first or second most common).
                if readpos is None:
                    if no_indoor_voice:
                        print(
                            f"Read {new_readname} has deletion at mutpos {mutpos + 1:,}: "
                            f"pileup = {mutpos2pileup[mutpos]}"
                        )
                    ignoring_this_aln = True
                    break

                read_nt = aln.query_sequence[readpos]

                # If this aln doesn't have match the first or second most common nucleotide at this position,
                # ignore it. In the future, when we perform read  smoothing based on an arbitrary set of
                # SNV calls, we can be more careful about this; but for now we make the simplifiying assumption
                # that a mutation likely only has one alternate nucleotide, and that the 3rd and 4th most
                # common nucleotides indicate errors. (Also, note that we break ties here arbitrarily.)
                nt2ct = dict(zip("ACGT", mutpos2pileup[mutpos][0]))
                nt1 = max(nt2ct, key=nt2ct.get)
                del nt2ct[nt1]
                nt2 = max(nt2ct, key=nt2ct.get)

                if read_nt != nt1 and read_nt != nt2:
                    if no_indoor_voice:
                        print(
                            f"Read {new_readname} has 3rd or 4th most common nt at mutpos {mutpos + 1:,}: "
                            f"pileup = {mutpos2pileup[mutpos]}, read = {read_nt}"
                        )
                    ignoring_this_aln = True
                    break

                # Notably, the nucleotide at a mutated position in a smoothed read will always be the first
                # or second most common nucleotide at this position. So "unreasonable" positions, in which
                # the ref nt != the consensus nt, will not be treated as you might expect -- we ignore the
                # reference in this particular case. Shouldn't make a big difference, since in most cases
                # the ref and consensus nt agree.
                #
                # Note that we aren't even looking at the reference nt at this point -- in many cases
                # the .replace() operation done below won't change anything. Shouldn't matter.
                relative_pos_on_aln = mutpos - ref_start
                smoothed_aln_seq = smoothed_aln_seq.replace([relative_pos_on_aln], read_nt)
                replacements_made[relative_pos_on_aln] = read_nt
                if no_indoor_voice:
                    print(
                        f"Updated read {new_readname} re: nt at mutpos {mutpos + 1:,}: "
                        f"pileup = {mutpos2pileup[mutpos]}, read = {read_nt}"
                    )

            if no_indoor_voice:
                print(f"Read {new_readname} involved {len(replacements_made):,} replacements!")

        if ignoring_this_aln:
            num_ignored_alns += 1
        else:
            # Now that we've finished processing all called mutations that this alignment spans, prepare it
            # to be written out to a FASTA file. See comments above on smoothed_aln_buffer, and why we don't
            # just write everything out as soon as it's ready.
            #
            # (Also, we've already guaranteed readname isn't already in smoothed_aln_buffer, so no need to worry
            # about accidentally overwriting something from earlier.)
            smoothed_aln_buffer[new_readname] = smoothed_aln_seq

            # Record which positions this smoothed read covers (of course, the original read may not exactly
            # "cover" these positions due to indels, but the smoothed version will cover them).
            #
            # We purposefully delay performing this update until right now -- this way, if we choose to "ignore"
            # this linear alignment at any point in the process above, we won't increase anything in pos2srcov
            # for this linear alignment.
            for pos_in_sr in range(ref_start, ref_end + 1):
                pos2srcov[pos_in_sr] += 1

            if ai % ALN_BUFFER_FREQ == 0:
                write_out_reads(output_smoothed_reads_file, smoothed_aln_buffer)
                # Clear the buffer
                smoothed_aln_buffer = {}

    # We're probably going to have left over smoothed reads that we still haven't written out, unless things
    # worked out so that on the final alignment we saw ai was exactly divisible by ALN_BUFFER_FREQ (and that's
    # pretty unlikely unless you set the buffer freq to a low number). So make one last dump of the buffer.
    if len(smoothed_aln_buffer) > 0:
        write_out_reads(output_smoothed_reads_file, smoothed_aln_buffer)

    print(f"We ignored {num_ignored_alns:,} linear alignments, fyi.")

    low_cov_positions = []
    for pos in range(0, seq2len[seq]):
        if pos2srcov[pos] < min_well_cov:
            low_cov_positions.append(pos)

    if add_virtual_reads and len(low_cov_positions) > 0:
        print(f"For reference, there are {len(low_cov_positions):,} low-coverage positions in {seq2name[seq]}.")

        # convert_to_runs (which is defined in Header.ipynb, btw) depends on the input list being sorted.
        # This is implicitly true because of how we constructed low_cov_positions above, so we're good.
        lc_runs = convert_to_runs(low_cov_positions)
        print(f'And there are {len(lc_runs)} "runs" of low-coverage positions.')
        print(lc_runs)

        print(f'Adding "virtual reads" spanning each of these runs to account for this...')

        # Sanity check: if the MAG is bizarrely short relative to the virtual read spanning stuff, complain
        # (We could probably move this sanity check to further up in the code if this becomes a problem, but
        # I don't think this is a big deal -- esp since short MAGs imply the above read smoothing stuff going
        # by relatively quickly, right?)
        if seq2len[seq] <= (2 * VR_EXTRA_SPAN):
            raise ValueError(
                f"Sequence {seq} has a length of {seq2len[seq]:,}. "
                f"This cannot be <= (2 * VR_EXTRA_SPAN), which is {2 * VR_EXTRA_SPAN:,}."
            )

        num_vr = 0
        vr_buffer = {}
        for run in lc_runs:

            # How many copies of this virtual read should we add?
            # Our goal is, essentially, "lifting" the coverage of this region back up to the average coverage
            # of this MAG. Of course, the average coverage of this MAG takes into account the relatively low
            # coverage of these positions, so you could argue that this is a somewhat silly way of doing this,
            # but it should be decent enough for our purposes (convincing the assembler later on that no, these
            # positions really do connect to elsewhere in the MAG).
            #
            # First, let's figure out the average coverage of this corresponding run of low-coverage positions
            # (just considering the "interior" positions that were truly labelled as "low-coverage", and not
            # the VR_EXTRA_SPAN positions we'll add in later).
            run_avgcov = mean([pos2srcov[lcpos] for lcpos in range(run[0], run[1] + 1)])

            # Now, we can figure out the (rounded) difference between the MAG's average coverage and this run's
            # average coverage. We'll add this many copies of the virtual read corresponding to this run.
            vr_cov = round(seq2meancov[seq] - run_avgcov)

            # Construct a virtual read that includes this entire run of uncovered positions as well
            # as VR_EXTRA_SPAN positions before and after (clamping to the start/end of the seq if needed).
            #
            # Notably, we could try to make this loop around from end -> start if this is a cyclic MAG, but
            # to remain consistent with how we handle supplementary alignments above -- and because implementing
            # the loop around would be a lot of work and it's like 3am -- we ignore this for now.
            #
            # Also, note that run_start can equal run_end, if only a single isolated position is uncovered.
            # This is fine -- the code handles this case automatically.

            run_start = max(run[0] - VR_EXTRA_SPAN, 0)
            run_end = min(run[1] + VR_EXTRA_SPAN, seq2len[seq] - 1)

            # Generate a sequence matching the "reference" MAG at these positions. We of course don't have
            # any info about mutations here, because these positions are uncovered by the real reads!
            vr_seq = fasta[run_start: run_end + 1]

            # We need to assign reads unique names, and including the run coordinates here is a nice way
            # to preserve uniqueness across runs and also make our smoothed reads files easier to interpret
            vr_name_prefix = f"vr_{run[0]}_{run[1]}"

            # Add vr_cov copies of this virtual read
            for vr_num in range(1, vr_cov + 1):
                vr_name = f"{vr_name_prefix}_{vr_num}"
                vr_buffer[vr_name] = vr_seq
                num_vr += 1

        write_out_reads(output_smoothed_reads_file, vr_buffer)
        print(f"Wrote out {num_vr:,} virtual reads.")

    print(f"Done with {seq}! Took {time.time() - ts1:,.2f} sec.")

print(f"Time taken: {time.time() - t1:,} sec.")======================================================================
Identifying mutated positions (p = 1%) in genome CAMP...
Found 83 mutated positions (p = 1%) in CAMP.
Note that this tally is higher than you'd see in e.g. the CP1/2/3 plots, because now we're including both 'rare' and non-rare mutations. Just so you don't waste five minutes sanity-checking this like I did.
Going through these positions...
	On aln 5,000 in seq CAMP. Time spent on CAMP so far: 15.28 sec.
	On aln 10,000 in seq CAMP. Time spent on CAMP so far: 40.01 sec.
	On aln 15,000 in seq CAMP. Time spent on CAMP so far: 64.44 sec.
	On aln 20,000 in seq CAMP. Time spent on CAMP so far: 89.49 sec.
	On aln 25,000 in seq CAMP. Time spent on CAMP so far: 114.12 sec.
	On aln 30,000 in seq CAMP. Time spent on CAMP so far: 138.35 sec.
	On aln 35,000 in seq CAMP. Time spent on CAMP so far: 162.91 sec.
	On aln 40,000 in seq CAMP. Time spent on CAMP so far: 188.02 sec.
	On aln 45,000 in seq CAMP. Time spent on CAMP so far: 213.44 sec.
	On aln 50,000 in seq CAMP. Time spent on CAMP so far: 236.58 sec.
	On aln 55,000 in seq CAMP. Time spent on CAMP so far: 260.57 sec.
	On aln 60,000 in seq CAMP. Time spent on CAMP so far: 284.89 sec.
	On aln 65,000 in seq CAMP. Time spent on CAMP so far: 309.56 sec.
	On aln 70,000 in seq CAMP. Time spent on CAMP so far: 334.58 sec.
	On aln 75,000 in seq CAMP. Time spent on CAMP so far: 359.41 sec.
	On aln 80,000 in seq CAMP. Time spent on CAMP so far: 384.29 sec.
	On aln 85,000 in seq CAMP. Time spent on CAMP so far: 409.14 sec.
	On aln 90,000 in seq CAMP. Time spent on CAMP so far: 435.16 sec.
	On aln 95,000 in seq CAMP. Time spent on CAMP so far: 459.35 sec.
	On aln 100,000 in seq CAMP. Time spent on CAMP so far: 483.30 sec.
	On aln 105,000 in seq CAMP. Time spent on CAMP so far: 507.93 sec.
	On aln 110,000 in seq CAMP. Time spent on CAMP so far: 532.69 sec.
	On aln 115,000 in seq CAMP. Time spent on CAMP so far: 557.67 sec.
	On aln 120,000 in seq CAMP. Time spent on CAMP so far: 582.69 sec.
	On aln 125,000 in seq CAMP. Time spent on CAMP so far: 607.18 sec.
	On aln 130,000 in seq CAMP. Time spent on CAMP so far: 631.91 sec.
	On aln 135,000 in seq CAMP. Time spent on CAMP so far: 657.42 sec.
	On aln 140,000 in seq CAMP. Time spent on CAMP so far: 682.60 sec.
	On aln 145,000 in seq CAMP. Time spent on CAMP so far: 708.86 sec.
	On aln 150,000 in seq CAMP. Time spent on CAMP so far: 733.32 sec.
	On aln 155,000 in seq CAMP. Time spent on CAMP so far: 757.76 sec.
	On aln 160,000 in seq CAMP. Time spent on CAMP so far: 783.96 sec.
	On aln 165,000 in seq CAMP. Time spent on CAMP so far: 808.69 sec.
	On aln 170,000 in seq CAMP. Time spent on CAMP so far: 832.46 sec.
	On aln 175,000 in seq CAMP. Time spent on CAMP so far: 856.98 sec.
	On aln 180,000 in seq CAMP. Time spent on CAMP so far: 881.44 sec.
	On aln 185,000 in seq CAMP. Time spent on CAMP so far: 905.27 sec.
	On aln 190,000 in seq CAMP. Time spent on CAMP so far: 927.59 sec.
	On aln 195,000 in seq CAMP. Time spent on CAMP so far: 946.38 sec.
	On aln 200,000 in seq CAMP. Time spent on CAMP so far: 971.03 sec.
	On aln 205,000 in seq CAMP. Time spent on CAMP so far: 995.86 sec.
	On aln 210,000 in seq CAMP. Time spent on CAMP so far: 1,020.59 sec.
	On aln 215,000 in seq CAMP. Time spent on CAMP so far: 1,046.48 sec.
	On aln 220,000 in seq CAMP. Time spent on CAMP so far: 1,071.08 sec.
	On aln 225,000 in seq CAMP. Time spent on CAMP so far: 1,095.54 sec.
	On aln 230,000 in seq CAMP. Time spent on CAMP so far: 1,120.30 sec.
	On aln 235,000 in seq CAMP. Time spent on CAMP so far: 1,145.53 sec.
	On aln 240,000 in seq CAMP. Time spent on CAMP so far: 1,170.07 sec.
	On aln 245,000 in seq CAMP. Time spent on CAMP so far: 1,194.24 sec.
	On aln 250,000 in seq CAMP. Time spent on CAMP so far: 1,218.56 sec.
	On aln 255,000 in seq CAMP. Time spent on CAMP so far: 1,242.46 sec.
	On aln 260,000 in seq CAMP. Time spent on CAMP so far: 1,267.08 sec.
	On aln 265,000 in seq CAMP. Time spent on CAMP so far: 1,292.68 sec.
	On aln 270,000 in seq CAMP. Time spent on CAMP so far: 1,318.59 sec.
	On aln 275,000 in seq CAMP. Time spent on CAMP so far: 1,344.37 sec.
	On aln 280,000 in seq CAMP. Time spent on CAMP so far: 1,369.54 sec.
	On aln 285,000 in seq CAMP. Time spent on CAMP so far: 1,394.03 sec.
	On aln 290,000 in seq CAMP. Time spent on CAMP so far: 1,417.84 sec.
	On aln 295,000 in seq CAMP. Time spent on CAMP so far: 1,441.56 sec.
	On aln 300,000 in seq CAMP. Time spent on CAMP so far: 1,465.79 sec.
	On aln 305,000 in seq CAMP. Time spent on CAMP so far: 1,490.74 sec.
	On aln 310,000 in seq CAMP. Time spent on CAMP so far: 1,514.14 sec.
	On aln 315,000 in seq CAMP. Time spent on CAMP so far: 1,537.98 sec.
	On aln 320,000 in seq CAMP. Time spent on CAMP so far: 1,562.28 sec.
	On aln 325,000 in seq CAMP. Time spent on CAMP so far: 1,585.85 sec.
	On aln 330,000 in seq CAMP. Time spent on CAMP so far: 1,612.00 sec.
	On aln 335,000 in seq CAMP. Time spent on CAMP so far: 1,637.62 sec.
	On aln 340,000 in seq CAMP. Time spent on CAMP so far: 1,662.53 sec.
	On aln 345,000 in seq CAMP. Time spent on CAMP so far: 1,686.74 sec.
	On aln 350,000 in seq CAMP. Time spent on CAMP so far: 1,710.93 sec.
	On aln 355,000 in seq CAMP. Time spent on CAMP so far: 1,735.86 sec.
	On aln 360,000 in seq CAMP. Time spent on CAMP so far: 1,761.10 sec.
	On aln 365,000 in seq CAMP. Time spent on CAMP so far: 1,786.77 sec.
	On aln 370,000 in seq CAMP. Time spent on CAMP so far: 1,812.09 sec.
	On aln 375,000 in seq CAMP. Time spent on CAMP so far: 1,837.22 sec.
	On aln 380,000 in seq CAMP. Time spent on CAMP so far: 1,866.43 sec.
	On aln 385,000 in seq CAMP. Time spent on CAMP so far: 1,895.51 sec.
	On aln 390,000 in seq CAMP. Time spent on CAMP so far: 1,920.20 sec.
	On aln 395,000 in seq CAMP. Time spent on CAMP so far: 1,944.44 sec.
	On aln 400,000 in seq CAMP. Time spent on CAMP so far: 1,969.30 sec.
	On aln 405,000 in seq CAMP. Time spent on CAMP so far: 1,994.20 sec.
	On aln 410,000 in seq CAMP. Time spent on CAMP so far: 2,019.13 sec.
	On aln 415,000 in seq CAMP. Time spent on CAMP so far: 2,042.64 sec.
	On aln 420,000 in seq CAMP. Time spent on CAMP so far: 2,067.83 sec.
	On aln 425,000 in seq CAMP. Time spent on CAMP so far: 2,092.23 sec.
	On aln 430,000 in seq CAMP. Time spent on CAMP so far: 2,117.11 sec.
	On aln 435,000 in seq CAMP. Time spent on CAMP so far: 2,141.92 sec.
	On aln 440,000 in seq CAMP. Time spent on CAMP so far: 2,167.09 sec.
	On aln 445,000 in seq CAMP. Time spent on CAMP so far: 2,200.54 sec.
	On aln 450,000 in seq CAMP. Time spent on CAMP so far: 2,214.97 sec.
	On aln 455,000 in seq CAMP. Time spent on CAMP so far: 2,227.75 sec.
	On aln 460,000 in seq CAMP. Time spent on CAMP so far: 2,240.43 sec.
	On aln 465,000 in seq CAMP. Time spent on CAMP so far: 2,253.40 sec.
	On aln 470,000 in seq CAMP. Time spent on CAMP so far: 2,266.38 sec.
	On aln 475,000 in seq CAMP. Time spent on CAMP so far: 2,279.19 sec.
We ignored 3,742 linear alignments, fyi.
For reference, there are 459,562 low-coverage positions in CAMP.
And there are 350 "runs" of low-coverage positions.
[(103341, 103341), (103346, 125162), (292046, 292070), (292073, 292126), (292129, 292135), (292137, 292173), (292213, 292213), (292392, 292433), (292960, 292960), (292979, 293016), (293018, 293046), (293050, 293060), (293087, 293097), (293108, 293109), (293133, 301422), (301450, 301450), (314318, 314320), (314326, 314394), (314481, 314482), (314484, 314510), (314606, 314606), (314611, 314791), (314794, 314810), (314837, 314889), (314912, 314928), (314930, 314930), (314935, 314936), (314956, 314956), (314963, 314966), (314969, 314977), (314988, 315165), (315167, 315202), (315204, 315204), (315207, 315209), (315211, 315216), (315561, 315646), (339205, 339279), (339302, 339339), (339365, 339367), (339369, 339369), (339372, 339372), (339375, 339377), (339385, 339386), (339391, 339639), (339650, 339653), (339682, 339687), (339689, 371159), (371167, 371182), (392169, 392187), (392189, 392208), (392316, 392316), (392318, 392318), (392329, 392396), (392605, 393362), (393367, 393657), (393659, 393667), (393682, 393683), (393685, 394243), (394245, 394380), (394383, 394476), (394486, 394586), (396831, 396876), (396898, 396933), (396952, 396964), (396971, 397001), (397013, 397016), (397018, 397022), (397025, 397025), (397032, 397041), (397043, 397055), (397069, 397069), (397074, 397263), (397599, 397600), (397604, 397705), (397716, 397720), (397729, 397733), (397785, 398024), (398050, 398083), (398096, 398102), (398108, 398117), (398135, 398141), (398143, 398212), (398230, 398230), (398243, 398335), (398339, 398623), (398633, 398633), (398638, 398746), (399291, 399710), (399798, 399799), (416737, 416741), (416743, 416748), (416818, 416819), (416840, 441120), (441122, 441143), (441202, 441207), (441217, 441332), (441471, 441518), (453709, 453712), (453724, 453724), (453738, 453738), (453742, 453743), (453746, 453748), (453758, 453760), (453766, 453766), (453773, 453774), (453790, 548977), (548980, 549350), (549492, 549493), (549534, 549535), (549537, 549562), (556242, 556320), (556327, 556585), (556593, 556602), (556605, 556613), (556615, 556626), (556672, 557454), (557456, 557897), (557899, 558288), (558492, 558511), (558517, 775099), (775107, 775107), (775110, 775110), (775252, 775545), (775577, 775577), (775729, 775854), (777086, 777088), (777094, 777189), (777205, 777206), (777209, 777209), (777218, 777218), (777248, 777248), (777261, 777265), (777277, 777295), (777303, 777303), (777307, 777307), (777313, 777322), (777365, 777373), (777376, 777446), (777449, 777449), (779065, 779065), (779067, 779067), (779074, 779176), (779192, 779195), (779198, 781759), (781764, 781783), (781786, 781792), (781796, 781798), (781805, 781811), (781818, 781822), (781896, 781903), (782109, 782109), (782117, 782120), (782877, 782884), (782899, 782901), (782903, 782904), (782907, 782918), (782920, 782926), (783535, 783548), (783763, 783883), (784019, 784022), (784030, 784031), (784058, 784108), (784110, 784125), (784133, 784135), (784138, 784143), (784145, 784148), (784152, 784171), (784193, 784193), (784198, 784310), (784312, 784376), (784378, 784382), (784386, 784441), (784555, 784729), (784738, 784789), (784791, 784793), (784820, 784828), (785000, 785000), (785007, 785026), (785029, 785066), (785106, 785219), (785232, 785243), (785257, 785274), (785284, 785289), (785303, 785310), (785330, 785330), (785347, 785347), (785395, 785395), (785397, 785398), (785420, 785420), (785423, 785437), (785528, 787271), (787279, 787287), (787292, 787476), (787482, 787499), (787509, 787576), (787589, 787602), (788796, 788819), (788848, 788880), (788914, 788916), (788919, 788922), (788929, 788929), (788937, 789052), (789056, 789080), (798839, 798846), (798853, 798910), (798913, 798971), (798973, 798975), (798979, 798983), (799018, 799048), (799280, 799283), (799286, 799316), (799325, 799446), (799490, 808689), (808691, 808704), (808707, 808806), (808810, 808811), (808816, 808816), (816702, 816752), (816768, 816770), (816773, 816794), (816796, 816809), (816812, 816819), (816824, 816828), (816831, 816833), (816845, 816856), (816859, 816874), (816876, 816880), (816898, 816899), (816912, 816925), (816936, 816936), (817081, 817084), (817086, 821472), (821474, 821519), (821523, 821527), (821532, 821533), (821536, 821536), (829915, 829977), (830007, 830008), (830010, 830013), (830247, 830248), (830268, 830275), (830279, 830354), (830438, 830736), (830738, 838512), (838531, 838564), (838566, 838803), (838822, 838917), (838972, 838972), (838975, 838975), (839516, 839516), (839520, 839526), (839889, 839927), (839936, 840037), (840040, 840041), (840044, 840091), (871656, 871656), (871658, 871659), (871669, 871675), (871714, 872397), (872399, 880718), (880786, 880793), (880811, 880824), (880827, 880834), (880838, 880839), (880930, 880963), (880969, 880972), (881004, 881007), (881009, 881095), (881101, 881101), (881105, 881105), (881107, 881107), (881112, 881122), (881124, 881296), (881301, 881301), (881323, 881414), (881439, 881450), (881453, 881461), (881525, 881605), (881607, 881613), (881623, 881624), (881627, 881645), (881652, 881654), (881704, 881705), (881707, 881707), (881709, 881710), (881727, 881862), (881864, 881864), (881868, 881870), (881875, 881877), (882035, 882037), (882058, 882063), (882066, 882067), (882092, 882092), (882104, 882105), (882108, 882110), (882943, 882950), (882954, 882974), (882978, 882981), (882984, 882987), (883049, 883049), (1012394, 1012394), (1012398, 1012401), (1012419, 1012618), (1012622, 1012634), (1012636, 1012652), (1013100, 1013131), (1013133, 1013152), (1013162, 1013166), (1013184, 1013185), (1013188, 1013450), (1013453, 1013459), (1013462, 1013467), (1013480, 1013487), (1013499, 1013680), (1013685, 1013689), (1013707, 1013707), (1013721, 1013730), (1013734, 1014248), (1014282, 1014712), (1014714, 1014719), (1014722, 1019723), (1019740, 1019759), (1019768, 1019789), (1019791, 1019797), (1019799, 1019821), (1019823, 1019823), (1019825, 1019831), (1019849, 1019852), (1019855, 1019945), (1020198, 1020208), (1020213, 1020213), (1020215, 1020247), (1020249, 1020253), (1020258, 1020260), (1020283, 1020296), (1020306, 1020307), (1020312, 1020317), (1020320, 1020325), (1020327, 1020399), (1020534, 1020537), (1020539, 1020539), (1020545, 1020545), (1020550, 1020551), (1020553, 1020563), (1020623, 1020624), (1020628, 1020630), (1020632, 1020632), (1020634, 1020764), (1020766, 1020820), (1281798, 1289243)]
Adding "virtual reads" spanning each of these runs to account for this...
Wrote out 78,175 virtual reads.
Done with edge_6104! Took 2,282.88 sec.
======================================================================
Identifying mutated positions (p = 1%) in genome BACT1...
Found 22,144 mutated positions (p = 1%) in BACT1.
Note that this tally is higher than you'd see in e.g. the CP1/2/3 plots, because now we're including both 'rare' and non-rare mutations. Just so you don't waste five minutes sanity-checking this like I did.
Going through these positions...
	On aln 5,000 in seq BACT1. Time spent on BACT1 so far: 50.39 sec.
	On aln 10,000 in seq BACT1. Time spent on BACT1 so far: 119.66 sec.
	On aln 15,000 in seq BACT1. Time spent on BACT1 so far: 204.80 sec.
	On aln 20,000 in seq BACT1. Time spent on BACT1 so far: 279.02 sec.
	On aln 25,000 in seq BACT1. Time spent on BACT1 so far: 376.95 sec.
	On aln 30,000 in seq BACT1. Time spent on BACT1 so far: 474.51 sec.
	On aln 35,000 in seq BACT1. Time spent on BACT1 so far: 559.32 sec.
	On aln 40,000 in seq BACT1. Time spent on BACT1 so far: 629.02 sec.
	On aln 45,000 in seq BACT1. Time spent on BACT1 so far: 724.07 sec.
	On aln 50,000 in seq BACT1. Time spent on BACT1 so far: 797.30 sec.
	On aln 55,000 in seq BACT1. Time spent on BACT1 so far: 871.21 sec.
	On aln 60,000 in seq BACT1. Time spent on BACT1 so far: 973.15 sec.
	On aln 65,000 in seq BACT1. Time spent on BACT1 so far: 1,073.75 sec.
	On aln 70,000 in seq BACT1. Time spent on BACT1 so far: 1,143.73 sec.
	On aln 75,000 in seq BACT1. Time spent on BACT1 so far: 1,245.70 sec.
	On aln 80,000 in seq BACT1. Time spent on BACT1 so far: 1,320.00 sec.
	On aln 85,000 in seq BACT1. Time spent on BACT1 so far: 1,391.82 sec.
	On aln 90,000 in seq BACT1. Time spent on BACT1 so far: 1,469.15 sec.
	On aln 95,000 in seq BACT1. Time spent on BACT1 so far: 1,552.18 sec.
	On aln 100,000 in seq BACT1. Time spent on BACT1 so far: 1,651.49 sec.
	On aln 105,000 in seq BACT1. Time spent on BACT1 so far: 1,732.47 sec.
	On aln 110,000 in seq BACT1. Time spent on BACT1 so far: 1,838.98 sec.
	On aln 115,000 in seq BACT1. Time spent on BACT1 so far: 1,919.40 sec.
	On aln 120,000 in seq BACT1. Time spent on BACT1 so far: 2,001.98 sec.
	On aln 125,000 in seq BACT1. Time spent on BACT1 so far: 2,110.28 sec.
	On aln 130,000 in seq BACT1. Time spent on BACT1 so far: 2,231.00 sec.
	On aln 135,000 in seq BACT1. Time spent on BACT1 so far: 2,311.37 sec.
	On aln 140,000 in seq BACT1. Time spent on BACT1 so far: 2,376.82 sec.
	On aln 145,000 in seq BACT1. Time spent on BACT1 so far: 2,445.30 sec.
	On aln 150,000 in seq BACT1. Time spent on BACT1 so far: 2,517.69 sec.
	On aln 155,000 in seq BACT1. Time spent on BACT1 so far: 2,614.99 sec.
	On aln 160,000 in seq BACT1. Time spent on BACT1 so far: 2,741.69 sec.
	On aln 165,000 in seq BACT1. Time spent on BACT1 so far: 2,831.87 sec.
	On aln 170,000 in seq BACT1. Time spent on BACT1 so far: 2,960.88 sec.
	On aln 175,000 in seq BACT1. Time spent on BACT1 so far: 3,063.76 sec.
	On aln 180,000 in seq BACT1. Time spent on BACT1 so far: 3,145.44 sec.
	On aln 185,000 in seq BACT1. Time spent on BACT1 so far: 3,237.23 sec.
	On aln 190,000 in seq BACT1. Time spent on BACT1 so far: 3,333.99 sec.
	On aln 195,000 in seq BACT1. Time spent on BACT1 so far: 3,433.18 sec.
	On aln 200,000 in seq BACT1. Time spent on BACT1 so far: 3,553.59 sec.
	On aln 205,000 in seq BACT1. Time spent on BACT1 so far: 3,633.70 sec.
	On aln 210,000 in seq BACT1. Time spent on BACT1 so far: 3,723.94 sec.
	On aln 215,000 in seq BACT1. Time spent on BACT1 so far: 3,854.84 sec.
	On aln 220,000 in seq BACT1. Time spent on BACT1 so far: 3,953.05 sec.
	On aln 225,000 in seq BACT1. Time spent on BACT1 so far: 4,056.97 sec.
	On aln 230,000 in seq BACT1. Time spent on BACT1 so far: 4,144.55 sec.
	On aln 235,000 in seq BACT1. Time spent on BACT1 so far: 4,220.56 sec.
	On aln 240,000 in seq BACT1. Time spent on BACT1 so far: 4,329.71 sec.
	On aln 245,000 in seq BACT1. Time spent on BACT1 so far: 4,449.42 sec.
	On aln 250,000 in seq BACT1. Time spent on BACT1 so far: 4,563.20 sec.
	On aln 255,000 in seq BACT1. Time spent on BACT1 so far: 4,647.77 sec.
	On aln 260,000 in seq BACT1. Time spent on BACT1 so far: 4,767.53 sec.
We ignored 30,472 linear alignments, fyi.
For reference, there are 1,765,231 low-coverage positions in BACT1.
And there are 543 "runs" of low-coverage positions.
[(0, 317), (320, 324), (710, 713), (731, 14345), (14357, 14514), (14581, 14616), (14640, 14644), (61817, 61834), (61840, 61851), (61856, 61871), (61874, 61876), (61880, 61888), (61904, 61909), (64792, 64817), (65220, 65221), (65223, 65243), (65471, 130012), (130031, 130034), (130037, 130058), (130071, 130075), (130124, 130204), (130405, 131666), (131735, 131742), (131754, 131754), (131787, 255298), (255314, 255651), (255657, 255692), (256070, 256148), (256158, 256232), (256244, 256256), (256259, 256314), (256324, 256328), (256331, 279251), (279262, 279263), (279281, 279282), (279302, 279324), (279335, 279348), (279782, 279787), (279799, 280053), (280219, 280220), (280225, 280245), (291302, 291313), (291334, 291334), (291344, 291412), (291717, 364617), (364648, 364663), (364666, 364674), (364677, 364680), (364684, 366596), (366600, 366608), (366630, 366635), (366724, 366745), (366777, 366781), (366795, 366873), (367049, 367051), (367056, 367180), (367203, 367226), (367251, 367291), (367293, 367299), (367302, 367304), (367313, 367314), (367322, 367322), (367339, 367414), (367437, 367439), (367460, 367470), (367478, 367493), (367499, 367553), (369718, 369860), (369874, 370157), (370171, 370172), (370223, 370294), (370369, 370369), (370375, 370403), (370407, 370474), (370480, 370481), (370484, 370488), (370900, 370989), (371013, 371065), (371068, 371073), (371075, 371111), (377457, 377479), (377712, 377716), (377719, 378390), (378396, 378398), (379091, 379103), (379116, 482255), (482271, 482440), (482442, 482445), (482453, 482480), (482504, 482515), (482527, 482529), (482533, 482533), (482536, 482539), (482600, 484877), (485490, 485493), (485495, 485524), (485628, 485776), (486891, 486893), (486896, 486901), (486906, 486958), (486973, 487336), (487369, 487369), (487381, 488396), (488421, 488421), (488449, 488468), (488542, 488562), (488565, 488600), (488602, 488626), (488634, 488637), (488645, 488647), (488650, 488653), (488668, 549065), (549140, 549150), (549162, 549175), (549180, 549272), (549278, 549284), (549450, 549451), (549470, 549508), (549510, 549514), (549540, 549541), (557642, 557808), (557814, 557816), (557856, 557859), (557899, 557913), (557915, 557978), (557980, 558088), (558104, 558104), (558214, 558216), (558226, 558235), (558237, 558248), (558258, 558262), (558285, 558288), (558293, 614898), (614907, 614916), (622642, 628743), (628754, 628831), (628847, 628873), (628878, 628891), (628984, 628992), (629011, 629011), (629157, 629157), (629196, 629359), (629367, 631490), (631513, 631523), (631582, 631584), (631600, 631607), (631609, 631823), (631849, 631856), (632192, 632202), (632208, 632337), (632341, 632346), (632350, 632419), (653388, 653465), (653470, 653473), (653488, 653545), (653549, 653556), (653565, 653568), (653576, 653596), (653599, 653599), (653604, 653606), (653608, 653608), (653614, 653617), (653635, 705857), (706174, 706174), (706205, 706853), (706855, 706882), (706968, 706968), (706970, 707063), (707067, 707085), (707156, 707157), (707187, 707235), (707247, 707298), (707303, 707323), (707337, 707342), (707355, 707360), (707799, 707848), (707859, 707890), (708022, 708026), (708030, 708032), (708041, 708071), (708082, 708090), (708100, 708111), (708126, 708134), (708148, 708153), (708436, 708445), (708452, 708454), (708460, 708541), (711062, 711078), (711084, 711100), (711119, 711119), (711122, 837237), (837359, 837375), (837405, 1078412), (1078415, 1080631), (1081786, 1081801), (1081830, 1081861), (1081872, 1081873), (1081876, 1081877), (1081892, 1081894), (1081925, 1081928), (1082705, 1082706), (1083610, 1083611), (1083630, 1083906), (1084209, 1084493), (1084539, 1084541), (1084543, 1084565), (1084646, 1084648), (1084670, 1084766), (1084768, 1084768), (1084799, 1108817), (1125935, 1125993), (1128757, 1128802), (1128807, 1128879), (1128931, 1128934), (1128936, 1128936), (1128940, 1129041), (1129052, 1129062), (1129116, 1129333), (1129341, 1129356), (1129457, 1129482), (1129766, 1129813), (1129837, 1129850), (1129860, 1129870), (1129877, 1129881), (1129886, 1129893), (1129922, 1129951), (1129955, 1129962), (1129977, 1129989), (1129994, 1132343), (1132347, 1132399), (1132411, 1132413), (1132537, 1132544), (1132569, 1132570), (1132578, 1132580), (1132582, 1132601), (1132623, 1132687), (1132729, 1133063), (1133232, 1133239), (1133242, 1133242), (1133250, 1133253), (1133262, 1133335), (1133475, 1133509), (1133531, 1133559), (1133561, 1133562), (1133572, 1133577), (1133586, 1133588), (1133603, 1140131), (1141273, 1141284), (1141286, 1141290), (1141292, 1141307), (1141311, 1141312), (1141322, 1141323), (1141350, 1141424), (1141440, 1141462), (1141548, 1141635), (1141644, 1141649), (1141799, 1168991), (1169017, 1169022), (1169115, 1169115), (1169160, 1169173), (1169181, 1169181), (1169187, 1169188), (1180153, 1180348), (1180475, 1180491), (1180621, 1180628), (1180631, 1180668), (1180683, 1180685), (1180689, 1180694), (1180702, 1228573), (1228597, 1228631), (1228646, 1228658), (1238214, 1238483), (1239360, 1239366), (1239369, 1239380), (1239385, 1239392), (1245860, 1246604), (1246700, 1344353), (1344860, 1344862), (1344874, 1344874), (1344881, 1344887), (1344899, 1344900), (1344913, 1344913), (1344915, 1344928), (1344957, 1344957), (1344964, 1344975), (1344998, 1345008), (1352445, 1439266), (1439270, 1439316), (1439337, 1439365), (1439400, 1439400), (1439426, 1439429), (1447341, 1447344), (1447815, 1447822), (1447852, 1465532), (1465585, 1465585), (1465592, 1465622), (1465645, 1466114), (1466147, 1466161), (1466166, 1466175), (1466187, 1466187), (1466195, 1466201), (1466205, 1469130), (1469132, 1469157), (1469522, 1469522), (1469524, 1469529), (1469750, 1469810), (1469813, 1469822), (1469834, 1469835), (1469841, 1469858), (1469877, 1469954), (1478558, 1478558), (1478567, 1478572), (1479080, 1479081), (1479122, 1479123), (1479128, 1479130), (1479145, 1479148), (1479154, 1479198), (1479209, 1479260), (1479307, 1479329), (1479334, 1479335), (1479338, 1479356), (1479361, 1494921), (1502224, 1502224), (1502442, 1502453), (1502456, 1502493), (1502613, 1502613), (1502618, 1502619), (1502639, 1502657), (1502707, 1502710), (1502717, 1503063), (1503576, 1504033), (1504035, 1504058), (1504066, 1504066), (1504078, 1504083), (1504096, 1504098), (1504104, 1504110), (1504127, 1504133), (1504140, 1504147), (1504224, 1504225), (1504237, 1504239), (1504249, 1504255), (1504272, 1504325), (1504459, 1504463), (1504465, 1546571), (1547775, 1547786), (1547801, 1547851), (1547855, 1580758), (1580762, 1580763), (1580787, 1580791), (1581012, 1581012), (1581014, 1581030), (1581060, 1594802), (1594821, 1594829), (1595547, 1616125), (1616341, 1616349), (1617549, 1617566), (1617581, 1617678), (1617685, 1617685), (1617693, 1617797), (1618456, 1620254), (1620281, 1620282), (1632841, 1649426), (1649467, 1649477), (1701555, 1701560), (1701563, 1701688), (1701721, 1701911), (1701919, 1702093), (1702311, 1702357), (1702593, 1702634), (1702736, 1702762), (1702765, 1702768), (1702770, 1702780), (1702783, 1702888), (1702897, 1702902), (1702905, 1702933), (1703191, 1703316), (1703984, 1705632), (1705663, 1705923), (1706067, 1706067), (1706351, 1706361), (1706365, 1706414), (1706416, 1706425), (1706542, 1706542), (1706547, 1707692), (1707694, 1745079), (1745084, 1745095), (1745603, 1745645), (1745667, 1745667), (1745677, 1745932), (1745970, 1745979), (1745988, 1747446), (1747537, 1747546), (1747550, 1747550), (1747594, 1747594), (1747599, 1747600), (1747608, 1747942), (1747959, 1747977), (1747986, 1748082), (1748568, 1748568), (1748653, 1803968), (1803972, 1886380), (1886382, 1886415), (1886461, 1886469), (1886471, 1886499), (1886663, 1887613), (1887622, 1887624), (1887634, 1887654), (1887659, 1887660), (1887975, 1887975), (1888039, 1888048), (1889870, 1889879), (1889892, 1889896), (1889955, 1889969), (1889976, 1889976), (1889995, 1890000), (1890003, 1895563), (1895579, 1895582), (1895585, 1895585), (1895591, 1895598), (1895603, 1895624), (1895639, 1895745), (1895919, 1895926), (1895945, 1895945), (1895994, 1895996), (1896000, 1896062), (1900742, 1900750), (1900756, 1900766), (1900807, 1900808), (1907839, 1907857), (1908434, 1908437), (1908834, 1908851), (1908853, 1908859), (1909110, 1909111), (1909119, 1909119), (1910320, 1910320), (1910478, 1910478), (1910480, 1910555), (1910558, 1910626), (1910631, 1911323), (1921112, 1921118), (1921149, 1921158), (1921162, 1921184), (1921189, 1921270), (1921280, 1921312), (1921314, 1921315), (1921322, 1921387), (1921404, 1921404), (1921409, 1921409), (1921611, 1921652), (1921656, 1921780), (1921787, 1921787), (1921820, 1921824), (1921830, 1921835), (1921856, 1921857), (1923575, 1923581), (1923644, 1923789), (1923803, 1923806), (1923808, 1923808), (1923810, 1923855), (1923888, 1923888), (1923894, 1934854), (1934928, 1934939), (1934948, 1935054), (1935059, 1935136), (1935138, 1935142), (1939630, 1998842), (1998931, 1998931), (1998940, 1998943), (1998954, 1998958), (1998968, 1998984), (1998995, 1999001), (1999018, 1999061), (2017984, 2018241), (2018471, 2018480), (2018483, 2018492), (2018495, 2018519), (2018521, 2018522), (2018540, 2018540), (2018595, 2018833), (2018846, 2018863), (2018919, 2018933), (2018942, 2018961), (2018967, 2018967), (2018979, 2019078), (2019087, 2019329), (2019648, 2019660), (2019678, 2039132), (2039887, 2039887), (2040115, 2040116), (2040126, 2040126), (2040132, 2040137), (2040142, 2040154), (2040177, 2040177), (2040181, 2040184), (2040186, 2040220), (2040267, 2040269), (2040279, 2040321), (2040329, 2040329), (2043498, 2043510), (2043555, 2043556), (2043974, 2043974), (2043976, 2044037), (2054676, 2054893), (2054911, 2055038), (2055046, 2055093), (2055648, 2055654), (2055759, 2055804), (2055822, 2055823), (2057451, 2061298), (2061361, 2061563), (2061566, 2061567), (2061623, 2064333), (2064345, 2064349), (2064363, 2064363), (2064394, 2064394), (2064519, 2064551), (2085564, 2085569), (2085573, 2085739), (2085748, 2117109), (2117356, 2117359), (2117560, 2117561), (2117566, 2117577), (2117590, 2117594), (2117614, 2117632), (2117667, 2117726), (2117733, 2117754), (2117877, 2117880), (2117896, 2117930), (2126058, 2126088), (2126129, 2126167), (2126253, 2126262), (2126289, 2126293), (2127820, 2127850), (2127856, 2127872), (2127882, 2127883), (2127888, 2128980), (2128984, 2128985), (2129000, 2129154), (2129157, 2129177), (2129451, 2149671), (2149674, 2149675), (2149684, 2149688), (2153389, 2153393)]
Adding "virtual reads" spanning each of these runs to account for this...
Wrote out 43,535 virtual reads.
Done with edge_1671! Took 4,802.41 sec.
======================================================================
Identifying mutated positions (p = 1%) in genome BACT2...
Found 372 mutated positions (p = 1%) in BACT2.
Note that this tally is higher than you'd see in e.g. the CP1/2/3 plots, because now we're including both 'rare' and non-rare mutations. Just so you don't waste five minutes sanity-checking this like I did.
Going through these positions...
	On aln 5,000 in seq BACT2. Time spent on BACT2 so far: 19.03 sec.
	On aln 10,000 in seq BACT2. Time spent on BACT2 so far: 41.51 sec.
	On aln 15,000 in seq BACT2. Time spent on BACT2 so far: 60.72 sec.
	On aln 20,000 in seq BACT2. Time spent on BACT2 so far: 80.70 sec.
	On aln 25,000 in seq BACT2. Time spent on BACT2 so far: 102.86 sec.
	On aln 30,000 in seq BACT2. Time spent on BACT2 so far: 126.18 sec.
	On aln 35,000 in seq BACT2. Time spent on BACT2 so far: 147.71 sec.
	On aln 40,000 in seq BACT2. Time spent on BACT2 so far: 172.68 sec.
	On aln 45,000 in seq BACT2. Time spent on BACT2 so far: 194.18 sec.
	On aln 50,000 in seq BACT2. Time spent on BACT2 so far: 212.54 sec.
	On aln 55,000 in seq BACT2. Time spent on BACT2 so far: 238.81 sec.
	On aln 60,000 in seq BACT2. Time spent on BACT2 so far: 261.74 sec.
	On aln 65,000 in seq BACT2. Time spent on BACT2 so far: 285.05 sec.
	On aln 70,000 in seq BACT2. Time spent on BACT2 so far: 311.66 sec.
	On aln 75,000 in seq BACT2. Time spent on BACT2 so far: 339.21 sec.
	On aln 80,000 in seq BACT2. Time spent on BACT2 so far: 365.79 sec.
	On aln 85,000 in seq BACT2. Time spent on BACT2 so far: 392.25 sec.
	On aln 90,000 in seq BACT2. Time spent on BACT2 so far: 420.20 sec.
	On aln 95,000 in seq BACT2. Time spent on BACT2 so far: 455.39 sec.
	On aln 100,000 in seq BACT2. Time spent on BACT2 so far: 477.24 sec.
	On aln 105,000 in seq BACT2. Time spent on BACT2 so far: 498.39 sec.
	On aln 110,000 in seq BACT2. Time spent on BACT2 so far: 522.81 sec.
	On aln 115,000 in seq BACT2. Time spent on BACT2 so far: 544.57 sec.
	On aln 120,000 in seq BACT2. Time spent on BACT2 so far: 568.42 sec.
	On aln 125,000 in seq BACT2. Time spent on BACT2 so far: 589.62 sec.
	On aln 130,000 in seq BACT2. Time spent on BACT2 so far: 623.22 sec.
	On aln 135,000 in seq BACT2. Time spent on BACT2 so far: 646.60 sec.
	On aln 140,000 in seq BACT2. Time spent on BACT2 so far: 664.93 sec.
	On aln 145,000 in seq BACT2. Time spent on BACT2 so far: 687.15 sec.
	On aln 150,000 in seq BACT2. Time spent on BACT2 so far: 709.46 sec.
	On aln 155,000 in seq BACT2. Time spent on BACT2 so far: 733.60 sec.
	On aln 160,000 in seq BACT2. Time spent on BACT2 so far: 760.52 sec.
	On aln 165,000 in seq BACT2. Time spent on BACT2 so far: 785.57 sec.
	On aln 170,000 in seq BACT2. Time spent on BACT2 so far: 811.43 sec.
	On aln 175,000 in seq BACT2. Time spent on BACT2 so far: 836.65 sec.
	On aln 180,000 in seq BACT2. Time spent on BACT2 so far: 863.76 sec.
	On aln 185,000 in seq BACT2. Time spent on BACT2 so far: 889.86 sec.
	On aln 190,000 in seq BACT2. Time spent on BACT2 so far: 916.06 sec.
	On aln 195,000 in seq BACT2. Time spent on BACT2 so far: 935.12 sec.
	On aln 200,000 in seq BACT2. Time spent on BACT2 so far: 954.47 sec.
	On aln 205,000 in seq BACT2. Time spent on BACT2 so far: 980.47 sec.
	On aln 210,000 in seq BACT2. Time spent on BACT2 so far: 1,005.46 sec.
	On aln 215,000 in seq BACT2. Time spent on BACT2 so far: 1,031.42 sec.
	On aln 220,000 in seq BACT2. Time spent on BACT2 so far: 1,057.18 sec.
	On aln 225,000 in seq BACT2. Time spent on BACT2 so far: 1,079.52 sec.
	On aln 230,000 in seq BACT2. Time spent on BACT2 so far: 1,104.89 sec.
	On aln 235,000 in seq BACT2. Time spent on BACT2 so far: 1,128.20 sec.
	On aln 240,000 in seq BACT2. Time spent on BACT2 so far: 1,153.16 sec.
	On aln 245,000 in seq BACT2. Time spent on BACT2 so far: 1,171.94 sec.
	On aln 250,000 in seq BACT2. Time spent on BACT2 so far: 1,187.58 sec.
	On aln 255,000 in seq BACT2. Time spent on BACT2 so far: 1,206.28 sec.
	On aln 260,000 in seq BACT2. Time spent on BACT2 so far: 1,224.97 sec.
	On aln 265,000 in seq BACT2. Time spent on BACT2 so far: 1,247.82 sec.
	On aln 270,000 in seq BACT2. Time spent on BACT2 so far: 1,272.54 sec.
	On aln 275,000 in seq BACT2. Time spent on BACT2 so far: 1,296.04 sec.
	On aln 280,000 in seq BACT2. Time spent on BACT2 so far: 1,321.18 sec.
	On aln 285,000 in seq BACT2. Time spent on BACT2 so far: 1,347.65 sec.
	On aln 290,000 in seq BACT2. Time spent on BACT2 so far: 1,374.93 sec.
	On aln 295,000 in seq BACT2. Time spent on BACT2 so far: 1,402.23 sec.
	On aln 300,000 in seq BACT2. Time spent on BACT2 so far: 1,428.34 sec.
	On aln 305,000 in seq BACT2. Time spent on BACT2 so far: 1,454.64 sec.
	On aln 310,000 in seq BACT2. Time spent on BACT2 so far: 1,478.90 sec.
	On aln 315,000 in seq BACT2. Time spent on BACT2 so far: 1,499.82 sec.
	On aln 320,000 in seq BACT2. Time spent on BACT2 so far: 1,521.66 sec.
	On aln 325,000 in seq BACT2. Time spent on BACT2 so far: 1,546.48 sec.
	On aln 330,000 in seq BACT2. Time spent on BACT2 so far: 1,565.56 sec.
	On aln 335,000 in seq BACT2. Time spent on BACT2 so far: 1,589.81 sec.
	On aln 340,000 in seq BACT2. Time spent on BACT2 so far: 1,614.47 sec.
	On aln 345,000 in seq BACT2. Time spent on BACT2 so far: 1,637.89 sec.
	On aln 350,000 in seq BACT2. Time spent on BACT2 so far: 1,662.88 sec.
	On aln 355,000 in seq BACT2. Time spent on BACT2 so far: 1,684.63 sec.
	On aln 360,000 in seq BACT2. Time spent on BACT2 so far: 1,704.91 sec.
	On aln 365,000 in seq BACT2. Time spent on BACT2 so far: 1,725.93 sec.
	On aln 370,000 in seq BACT2. Time spent on BACT2 so far: 1,749.61 sec.
	On aln 375,000 in seq BACT2. Time spent on BACT2 so far: 1,767.02 sec.
	On aln 380,000 in seq BACT2. Time spent on BACT2 so far: 1,793.10 sec.
	On aln 385,000 in seq BACT2. Time spent on BACT2 so far: 1,819.47 sec.
	On aln 390,000 in seq BACT2. Time spent on BACT2 so far: 1,843.99 sec.
	On aln 395,000 in seq BACT2. Time spent on BACT2 so far: 1,870.34 sec.
	On aln 400,000 in seq BACT2. Time spent on BACT2 so far: 1,892.02 sec.
	On aln 405,000 in seq BACT2. Time spent on BACT2 so far: 1,904.82 sec.
	On aln 410,000 in seq BACT2. Time spent on BACT2 so far: 1,924.23 sec.
	On aln 415,000 in seq BACT2. Time spent on BACT2 so far: 1,948.44 sec.
	On aln 420,000 in seq BACT2. Time spent on BACT2 so far: 1,973.58 sec.
	On aln 425,000 in seq BACT2. Time spent on BACT2 so far: 1,994.99 sec.
	On aln 430,000 in seq BACT2. Time spent on BACT2 so far: 2,020.74 sec.
	On aln 435,000 in seq BACT2. Time spent on BACT2 so far: 2,037.38 sec.
	On aln 440,000 in seq BACT2. Time spent on BACT2 so far: 2,057.68 sec.
	On aln 445,000 in seq BACT2. Time spent on BACT2 so far: 2,084.08 sec.
	On aln 450,000 in seq BACT2. Time spent on BACT2 so far: 2,112.56 sec.
	On aln 455,000 in seq BACT2. Time spent on BACT2 so far: 2,139.62 sec.
	On aln 460,000 in seq BACT2. Time spent on BACT2 so far: 2,165.14 sec.
	On aln 465,000 in seq BACT2. Time spent on BACT2 so far: 2,186.03 sec.
	On aln 470,000 in seq BACT2. Time spent on BACT2 so far: 2,210.04 sec.
	On aln 475,000 in seq BACT2. Time spent on BACT2 so far: 2,235.71 sec.
	On aln 480,000 in seq BACT2. Time spent on BACT2 so far: 2,259.01 sec.
	On aln 485,000 in seq BACT2. Time spent on BACT2 so far: 2,277.89 sec.
	On aln 490,000 in seq BACT2. Time spent on BACT2 so far: 2,303.72 sec.
	On aln 495,000 in seq BACT2. Time spent on BACT2 so far: 2,327.58 sec.
	On aln 500,000 in seq BACT2. Time spent on BACT2 so far: 2,351.08 sec.
	On aln 505,000 in seq BACT2. Time spent on BACT2 so far: 2,376.59 sec.
	On aln 510,000 in seq BACT2. Time spent on BACT2 so far: 2,398.92 sec.
	On aln 515,000 in seq BACT2. Time spent on BACT2 so far: 2,416.03 sec.
	On aln 520,000 in seq BACT2. Time spent on BACT2 so far: 2,442.41 sec.
	On aln 525,000 in seq BACT2. Time spent on BACT2 so far: 2,468.64 sec.
	On aln 530,000 in seq BACT2. Time spent on BACT2 so far: 2,490.18 sec.
	On aln 535,000 in seq BACT2. Time spent on BACT2 so far: 2,516.90 sec.
	On aln 540,000 in seq BACT2. Time spent on BACT2 so far: 2,543.05 sec.
	On aln 545,000 in seq BACT2. Time spent on BACT2 so far: 2,568.61 sec.
	On aln 550,000 in seq BACT2. Time spent on BACT2 so far: 2,592.92 sec.
	On aln 555,000 in seq BACT2. Time spent on BACT2 so far: 2,612.55 sec.
	On aln 560,000 in seq BACT2. Time spent on BACT2 so far: 2,629.31 sec.
	On aln 565,000 in seq BACT2. Time spent on BACT2 so far: 2,650.20 sec.
	On aln 570,000 in seq BACT2. Time spent on BACT2 so far: 2,675.65 sec.
	On aln 575,000 in seq BACT2. Time spent on BACT2 so far: 2,695.95 sec.
	On aln 580,000 in seq BACT2. Time spent on BACT2 so far: 2,711.79 sec.
	On aln 585,000 in seq BACT2. Time spent on BACT2 so far: 2,729.58 sec.
	On aln 590,000 in seq BACT2. Time spent on BACT2 so far: 2,753.45 sec.
	On aln 595,000 in seq BACT2. Time spent on BACT2 so far: 2,773.80 sec.
	On aln 600,000 in seq BACT2. Time spent on BACT2 so far: 2,792.17 sec.
	On aln 605,000 in seq BACT2. Time spent on BACT2 so far: 2,819.14 sec.
	On aln 610,000 in seq BACT2. Time spent on BACT2 so far: 2,845.69 sec.
	On aln 615,000 in seq BACT2. Time spent on BACT2 so far: 2,867.18 sec.
	On aln 620,000 in seq BACT2. Time spent on BACT2 so far: 2,894.40 sec.
	On aln 625,000 in seq BACT2. Time spent on BACT2 so far: 2,920.75 sec.
	On aln 630,000 in seq BACT2. Time spent on BACT2 so far: 2,944.25 sec.
	On aln 635,000 in seq BACT2. Time spent on BACT2 so far: 2,971.74 sec.
	On aln 640,000 in seq BACT2. Time spent on BACT2 so far: 2,997.99 sec.
	On aln 645,000 in seq BACT2. Time spent on BACT2 so far: 3,017.82 sec.
	On aln 650,000 in seq BACT2. Time spent on BACT2 so far: 3,042.19 sec.
	On aln 655,000 in seq BACT2. Time spent on BACT2 so far: 3,060.41 sec.
	On aln 660,000 in seq BACT2. Time spent on BACT2 so far: 3,085.96 sec.
	On aln 665,000 in seq BACT2. Time spent on BACT2 so far: 3,112.39 sec.
	On aln 670,000 in seq BACT2. Time spent on BACT2 so far: 3,136.47 sec.
	On aln 675,000 in seq BACT2. Time spent on BACT2 so far: 3,162.74 sec.
	On aln 680,000 in seq BACT2. Time spent on BACT2 so far: 3,185.41 sec.
	On aln 685,000 in seq BACT2. Time spent on BACT2 so far: 3,209.64 sec.
	On aln 690,000 in seq BACT2. Time spent on BACT2 so far: 3,234.41 sec.
	On aln 695,000 in seq BACT2. Time spent on BACT2 so far: 3,264.64 sec.
	On aln 700,000 in seq BACT2. Time spent on BACT2 so far: 3,290.03 sec.
	On aln 705,000 in seq BACT2. Time spent on BACT2 so far: 3,309.24 sec.
	On aln 710,000 in seq BACT2. Time spent on BACT2 so far: 3,328.16 sec.
	On aln 715,000 in seq BACT2. Time spent on BACT2 so far: 3,351.87 sec.
	On aln 720,000 in seq BACT2. Time spent on BACT2 so far: 3,374.29 sec.
	On aln 725,000 in seq BACT2. Time spent on BACT2 so far: 3,400.39 sec.
	On aln 730,000 in seq BACT2. Time spent on BACT2 so far: 3,427.45 sec.
	On aln 735,000 in seq BACT2. Time spent on BACT2 so far: 3,449.14 sec.
	On aln 740,000 in seq BACT2. Time spent on BACT2 so far: 3,462.67 sec.
We ignored 147,492 linear alignments, fyi.
For reference, there are 2,022,486 low-coverage positions in BACT2.
And there are 340 "runs" of low-coverage positions.
[(20691, 20693), (20746, 195256), (195267, 195267), (195467, 195468), (204388, 204388), (204390, 204435), (204444, 204451), (204454, 204528), (204535, 204563), (204565, 204570), (204608, 204609), (204662, 204662), (204678, 204678), (204682, 204697), (204702, 204721), (204723, 205894), (206195, 210441), (210449, 210451), (210482, 210484), (210492, 210494), (210496, 210504), (210506, 210512), (210518, 210518), (210527, 210527), (210529, 210530), (210535, 210537), (210539, 210543), (210552, 210561), (210564, 210565), (210587, 210593), (210607, 210608), (210616, 210625), (210630, 210632), (210636, 210636), (210659, 210663), (210694, 210694), (210697, 210700), (210754, 210784), (210786, 210789), (210792, 210814), (210829, 210834), (210838, 210838), (211443, 211449), (211827, 211827), (211831, 211908), (211913, 211964), (211966, 211967), (212093, 212385), (212405, 212421), (212426, 212427), (212441, 212589), (212594, 212611), (212616, 212652), (212675, 212675), (212678, 212812), (212826, 212870), (212875, 213165), (213167, 213206), (213219, 213221), (213227, 280451), (280453, 280455), (302518, 302518), (302592, 302592), (302596, 302599), (302601, 302605), (320509, 320519), (320523, 320528), (320531, 320531), (320533, 321050), (321172, 321172), (321176, 321234), (321237, 321237), (321239, 321245), (321259, 321259), (321264, 321264), (321266, 321268), (321282, 321294), (322430, 322450), (322470, 322472), (322475, 322475), (322482, 322541), (322566, 322572), (322582, 322586), (322704, 356591), (356594, 356656), (356658, 356659), (367533, 367538), (367566, 445573), (458660, 609848), (609854, 609863), (609910, 610021), (619243, 619246), (619290, 735367), (735373, 735374), (744579, 744579), (744581, 744581), (744585, 744586), (744590, 744590), (744642, 744642), (744649, 744649), (744736, 744736), (744738, 744740), (744857, 744859), (744866, 818159), (821435, 821435), (821438, 821438), (821440, 821480), (821501, 821509), (821583, 821593), (826606, 826610), (826620, 826650), (826658, 826671), (826680, 826686), (826708, 826708), (826714, 826886), (826895, 826895), (826905, 826910), (826920, 826930), (826955, 826958), (826961, 826962), (826990, 827007), (827009, 827016), (827018, 827019), (827033, 827603), (827609, 827631), (827635, 827645), (827647, 827649), (827651, 827652), (827662, 827675), (827677, 827677), (827685, 827693), (827698, 827699), (827716, 923210), (923257, 923277), (923280, 923286), (931044, 931046), (931058, 931060), (931064, 931071), (931080, 1165931), (1165933, 1165974), (1166016, 1166037), (1188572, 1188572), (1188602, 1188634), (1188655, 1188666), (1188669, 1188985), (1189040, 1197440), (1197502, 1197512), (1197526, 1197867), (1197903, 1197903), (1197907, 1197914), (1207467, 1207473), (1207475, 1207490), (1207510, 1207534), (1207675, 1309432), (1309434, 1309440), (1313492, 1313503), (1313527, 1313528), (1313531, 1313545), (1313549, 1372814), (1372816, 1372818), (1373847, 1373849), (1373853, 1373853), (1373858, 1373858), (1373925, 1373928), (1375563, 1375576), (1375653, 1375654), (1376040, 1376056), (1376058, 1376090), (1376103, 1376107), (1376114, 1397516), (1397518, 1397523), (1397528, 1397528), (1397532, 1397533), (1408127, 1408134), (1408140, 1482627), (1482631, 1482655), (1491348, 1491348), (1491351, 1491364), (1491379, 1533705), (1533758, 1533777), (1533963, 1533966), (1533968, 1533972), (1533975, 1533991), (1534027, 1534031), (1534040, 1534040), (1534049, 1534052), (1552510, 1552513), (1552537, 1552539), (1552581, 1552649), (1552656, 1552668), (1552682, 1552687), (1552699, 1577363), (1577369, 1577376), (1577380, 1577517), (1577519, 1577597), (1577666, 1577666), (1592169, 1592201), (1592204, 1592314), (1592329, 1592330), (1592367, 1592401), (1592408, 1592413), (1592417, 1592418), (1592420, 1592454), (1592506, 1592631), (1592645, 1592656), (1592667, 1719353), (1719355, 1719355), (1719390, 1719392), (1719438, 1719451), (1719615, 1719615), (1719619, 1719646), (1719648, 1719650), (1720705, 1724364), (1724366, 1763859), (1832516, 1868059), (1900786, 1927566), (1927569, 1927588), (1953916, 1953916), (1953920, 1970502), (1970556, 1970564), (1970566, 1970571), (1970577, 1970577), (1970588, 1970592), (1970607, 1970660), (1970679, 1970742), (2003976, 2003980), (2004012, 2036038), (2036068, 2036071), (2036097, 2036097), (2070659, 2087953), (2145746, 2197957), (2197962, 2197962), (2216488, 2216488), (2216490, 2275524), (2275819, 2276155), (2276162, 2276165), (2276770, 2276770), (2276783, 2276783), (2276789, 2327018), (2327029, 2327035), (2327040, 2327045), (2355919, 2375506), (2375509, 2375510), (2403062, 2403095), (2403120, 2403135), (2403137, 2422295), (2422297, 2422298), (2422301, 2422323), (2422341, 2422348), (2422350, 2422354), (2457009, 2457010), (2457104, 2480092), (2494839, 2507809), (2507822, 2507831), (2507833, 2507843), (2572921, 2572921), (2572923, 2572946), (2572949, 2572976), (2572980, 2575088), (2575114, 2575114), (2586802, 2603686), (2603697, 2603799), (2619176, 2619177), (2619632, 2619634), (2619638, 2619843), (2619848, 2629217), (2644661, 2644674), (2644681, 2696429), (2696466, 2696470), (2696525, 2696535), (2700092, 2724407), (2724437, 2724439), (2731472, 2731482), (2731559, 2731559), (2731562, 2731564), (2731736, 2731736), (2731764, 2731765), (2732705, 2735807), (2735851, 2743797), (2743802, 2743805), (2744427, 2744427), (2744599, 2744599), (2744825, 2745019), (2745021, 2745041), (2745056, 2745075), (2745093, 2745095), (2745099, 2745100), (2745154, 2745155), (2745201, 2745221), (2745535, 2746962), (2747233, 2747243), (2747247, 2747269), (2747352, 2747386), (2747391, 2747589), (2747595, 2747597), (2747603, 2747713), (2747718, 2747732), (2747754, 2747754), (2747764, 2747766), (2747819, 2747821), (2747918, 2747936), (2747946, 2747955), (2747977, 2748006), (2748010, 2748011), (2748017, 2748022), (2748029, 2748033), (2748037, 2748039), (2748062, 2748068), (2748074, 2748074), (2748079, 2748079), (2748082, 2748082), (2748085, 2748089), (2748093, 2748099), (2748114, 2748118), (2777733, 2777733), (2777911, 2777919), (2777999, 2778001), (2778003, 2778528), (2778533, 2778541), (2778579, 2778586), (2778591, 2778598), (2778601, 2778640), (2778646, 2778647), (2778649, 2778652), (2778664, 2778664), (2778666, 2778670), (2778705, 2778705), (2778720, 2778733), (2778735, 2778771), (2778773, 2778773), (2778824, 2778887), (2778891, 2778892), (2779947, 2779951), (2779957, 2779957), (2779961, 2781104), (2781112, 2781119), (2781147, 2781149), (2781161, 2781163), (2781168, 2781168), (2781171, 2781190)]
Adding "virtual reads" spanning each of these runs to account for this...
Wrote out 76,509 virtual reads.
Done with edge_2358! Took 3,470.42 sec.
Time taken: 10,598.250224113464 sec.

## 2. Assemble these smoothed reads_____no_output_____

%%bash

OUTDIR=phasing-data/smoothed-reads

# just a test -- diagnosing why the graph is disconnected. is it due to the --simpleec stuff?

/home/mfedarko/software/LJA-branch/bin/lja \
    --reads $OUTDIR/edge_1671_smoothed_reads_delignore_vrlow.fasta \
    --noec \
    --output-dir $OUTDIR/edge_1671_lja_noec_p1pct_delignore_vrlow00:00:00 2Mb  INFO: Hello! You are running La Jolla Assembler (LJA), a tool for genome assembly from PacBio HiFi reads
00:00:12 2Mb  INFO: ce30e586cf3360570805e35291bc1c5599c38b70
00:00:12 5Mb  INFO: LJA pipeline started
00:00:12 5Mb  INFO: Performing initial correction with k = 5001
00:00:12 0Mb  INFO: Reading reads
00:00:12 0Mb  INFO: Extracting minimizers
00:00:24 3.1Gb  INFO: Finished read processing
00:00:24 3.1Gb  INFO: 3716755 hashs collected. Starting sorting.
00:00:24 3.2Gb  INFO: Finished sorting. Total distinct minimizers: 25231
00:00:24 3.2Gb  INFO: Starting construction of sparse de Bruijn graph
00:00:24 3.2Gb  INFO: Vertex map constructed.
00:00:24 3.2Gb  INFO: Filling edge sequences.
00:00:38 3.2Gb  INFO: Finished sparse de Bruijn graph construction.
00:00:38 3.2Gb  INFO:  Collecting tips
00:00:38 3.2Gb  INFO: Added 1596 artificial minimizers from tips.
00:00:38 3.2Gb  INFO: Collected 49812 old edges.
00:00:38 3.2Gb  INFO: New minimizers added to sparse graph.
00:00:38 3.2Gb  INFO: Refilling graph with old edges.
00:00:39 3.2Gb  INFO: Filling graph with new edges.
00:00:39 3.2Gb  INFO: Finished fixing sparse de Bruijn graph.
00:00:39 3.2Gb  INFO: Starting to extract disjointigs.
00:00:39 3.2Gb  INFO: Finished extracting 2208 disjointigs of total size 17525953
00:00:40 0Mb  INFO: Loading disjointigs from file "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/k5001/disjointigs.fasta"
00:00:40 33Mb  INFO: Filling bloom filter with k+1-mers.
00:00:41 34Mb  INFO: Filled 30009072 bits out of 207479840
00:00:41 34Mb  INFO: Finished filling bloom filter. Selecting junctions.
00:00:41 34Mb  INFO: Collected 4950 junctions.
00:00:41 34Mb  INFO: Starting DBG construction.
00:00:41 34Mb  INFO: Vertices created.
00:00:41 34Mb  INFO: Filled dbg edges. Adding hanging vertices
00:00:41 34Mb  INFO: Added 0 hanging vertices
00:00:41 34Mb  INFO: Merging unbranching paths
00:00:41 34Mb  INFO: Ended merging edges. Resulting size 2542
00:00:42 34Mb  INFO: Cleaning edge coverages
00:00:42 34Mb  INFO: Collecting alignments of sequences to the graph
00:00:49 3.2Gb  INFO: Alignment collection finished. Total length of alignments is 574548
00:00:50 3.2Gb  INFO: Printing reads to fasta file "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:01:12 5Mb  INFO: Performing repeat resolution by transforming de Bruijn graph into Multiplex de Bruijn graph
00:01:12 0Mb  INFO: Loading graph from fasta
00:01:12 50Mb  INFO: Finished loading graph
00:01:13 140Mb  INFO: Looking for unique edges
00:01:13 140Mb  INFO: Marked 28 long edges as unique
00:01:13 140Mb  INFO: Marking extra edges as unique based on read paths
00:01:13 140Mb  INFO: Marked 29 edges as unique
00:01:13 140Mb  INFO: Splitting graph with unique edges
00:01:13 140Mb  INFO: Processing 380 components
00:01:14 140Mb  INFO: Finished unique edges search. Found 29 unique edges
00:01:14 140Mb  INFO: Analysing repeats of multiplicity 2 and looking for additional unique edges
00:01:14 140Mb  INFO: Finished processing of repeats of multiplicity 2. Found 0 erroneous edges.
00:01:14 140Mb  INFO: Resolving repeats
00:01:14 140Mb  INFO: Constructing paths
00:01:19 268Mb  INFO: Building graph
00:01:19 270Mb  INFO: Increasing k
00:02:29 270Mb  INFO: Finished increasing k
00:02:29 270Mb  INFO: Exporting remaining active transitions
00:02:29 270Mb  INFO: Export to Dot
00:02:29 270Mb  INFO: Export to GFA and compressed contigs
00:02:32 278Mb  INFO: Finished repeat resolution
00:02:33 5Mb  INFO: Performing polishing and homopolymer uncompression
00:02:33 18Mb  INFO: Aligning reads back to assembly
00:02:52 2.8Gb  INFO: Finished alignment.
00:02:52 2.8Gb  INFO: Printing alignments to "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/uncompressing/alignments.txt"
00:02:53 3Gb  INFO: Reading and processing initial reads from ["phasing-data/smoothed-reads/edge_1671_smoothed_reads_delignore_vrlow.fasta"]
00:07:20 8.9Gb  INFO: Uncompressing homopolymers in contigs
00:07:22 8.9Gb  INFO: Total zero covered nucleotides 1901
00:07:22 8.9Gb  INFO: Calculating overlaps between adjacent uncompressed edges
00:07:23 8.9Gb  INFO: Printing final gfa file to "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/mdbg.gfa"
00:07:23 8.9Gb  INFO: Printing final assembly to "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/assembly.fasta"
00:07:23 5Mb  INFO: Final homopolymer compressed and corrected reads can be found here: "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:07:23 5Mb  INFO: Final graph with homopolymer compressed edges can be found here: "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/mdbg/mdbg.hpc.gfa"
00:07:23 5Mb  INFO: Final graph can be found here: "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/mdbg.gfa"
00:07:23 5Mb  INFO: Final assembly can be found here: "phasing-data/smoothed-reads/edge_1671_lja_noec_p1pct_delignore_vrlow/assembly.fasta"
00:07:23 5Mb  INFO: LJA pipeline finished
%%bash

# LJA with no error correction, but with a filter for low-coverage edges

OUTDIR=phasing-data/smoothed-reads

/home/mfedarko/software/LJA-branch/bin/lja \
    --reads $OUTDIR/edge_6104_smoothed_reads_delignore_vrlow.fasta \
    --simpleec \
    --Cov-threshold 10 \
    --output-dir $OUTDIR/edge_6104_lja_cf_10x_p1pct_delignore_vrlow

/home/mfedarko/software/LJA-branch/bin/lja \
    --reads $OUTDIR/edge_1671_smoothed_reads_delignore_vrlow.fasta \
    --simpleec \
    --Cov-threshold 10 \
    --output-dir $OUTDIR/edge_1671_lja_cf_10x_p1pct_delignore_vrlow

/home/mfedarko/software/LJA-branch/bin/lja \
    --reads $OUTDIR/edge_2358_smoothed_reads_delignore_vrlow.fasta \
    --simpleec \
    --Cov-threshold 10 \
    --output-dir $OUTDIR/edge_2358_lja_cf_10x_p1pct_delignore_vrlow00:00:00 2Mb  INFO: Hello! You are running La Jolla Assembler (LJA), a tool for genome assembly from PacBio HiFi reads
00:00:10 2Mb  INFO: 2ec2b679d91f4230fdfa1949f196954333200ce4
00:00:10 5Mb  INFO: LJA pipeline started
00:00:10 5Mb  INFO: Performing initial correction with k = 5001
00:00:10 0Mb  INFO: Reading reads
00:00:10 0Mb  INFO: Extracting minimizers
00:00:29 4.5Gb  INFO: Finished read processing
00:00:29 4.5Gb  INFO: 5768518 hashs collected. Starting sorting.
00:00:29 4.5Gb  INFO: Finished sorting. Total distinct minimizers: 4185
00:00:29 4.5Gb  INFO: Starting construction of sparse de Bruijn graph
00:00:29 4.5Gb  INFO: Vertex map constructed.
00:00:29 4.5Gb  INFO: Filling edge sequences.
00:00:48 5.8Gb  INFO: Finished sparse de Bruijn graph construction.
00:00:48 5.8Gb  INFO:  Collecting tips
00:00:48 5.8Gb  INFO: Added 29 artificial minimizers from tips.
00:00:48 5.8Gb  INFO: Collected 8408 old edges.
00:00:48 5.8Gb  INFO: New minimizers added to sparse graph.
00:00:48 5.8Gb  INFO: Refilling graph with old edges.
00:00:48 5.8Gb  INFO: Filling graph with new edges.
00:00:48 5.8Gb  INFO: Finished fixing sparse de Bruijn graph.
00:00:48 5.8Gb  INFO: Starting to extract disjointigs.
00:00:48 5.8Gb  INFO: Finished extracting 100 disjointigs of total size 1558702
00:00:48 0Mb  INFO: Loading disjointigs from file "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/k5001/disjointigs.fasta"
00:00:48 8Mb  INFO: Filling bloom filter with k+1-mers.
00:00:48 8Mb  INFO: Filled 4900456 bits out of 33875264
00:00:48 8Mb  INFO: Finished filling bloom filter. Selecting junctions.
00:00:49 8Mb  INFO: Collected 522 junctions.
00:00:49 8Mb  INFO: Starting DBG construction.
00:00:49 8Mb  INFO: Vertices created.
00:00:49 8Mb  INFO: Filled dbg edges. Adding hanging vertices
00:00:49 8Mb  INFO: Added 0 hanging vertices
00:00:49 8Mb  INFO: Merging unbranching paths
00:00:49 8Mb  INFO: Ended merging edges. Resulting size 96
00:00:49 8Mb  INFO: Cleaning edge coverages
00:00:49 8Mb  INFO: Collecting alignments of sequences to the graph
00:01:03 5.9Gb  INFO: Alignment collection finished. Total length of alignments is 499118
00:01:03 5.9Gb  INFO: Could not correct 61 reads. They will be removed.
00:01:03 5.9Gb  INFO: Uncorrected reads were removed.
00:01:03 5.9Gb  INFO: Applying changes to the graph
00:01:07 6Gb  INFO: Printing reads to fasta file "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:01:39 5Mb  INFO: Performing repeat resolution by transforming de Bruijn graph into Multiplex de Bruijn graph
00:01:39 0Mb  INFO: Loading graph from fasta
00:01:39 7Mb  INFO: Finished loading graph
00:01:40 242Mb  INFO: Looking for unique edges
00:01:40 242Mb  INFO: Marked 18 long edges as unique
00:01:40 242Mb  INFO: Marking extra edges as unique based on read paths
00:01:40 242Mb  INFO: Marked 18 edges as unique
00:01:40 242Mb  INFO: Splitting graph with unique edges
00:01:40 242Mb  INFO: Processing 10 components
00:01:40 242Mb  INFO: Finished unique edges search. Found 74 unique edges
00:01:40 242Mb  INFO: Analysing repeats of multiplicity 2 and looking for additional unique edges
00:01:40 242Mb  INFO: Finished processing of repeats of multiplicity 2. Found 0 erroneous edges.
00:01:40 242Mb  INFO: Resolving repeats
00:01:40 242Mb  INFO: Constructing paths
00:01:44 337Mb  INFO: Building graph
00:01:44 337Mb  INFO: Increasing k
00:01:44 337Mb  INFO: Finished increasing k
00:01:44 337Mb  INFO: Exporting remaining active transitions
00:01:44 337Mb  INFO: Export to Dot
00:01:44 337Mb  INFO: Export to GFA and compressed contigs
00:01:44 342Mb  INFO: Finished repeat resolution
00:01:44 5Mb  INFO: Performing polishing and homopolymer uncompression
00:01:44 6Mb  INFO: Aligning reads back to assembly
00:02:03 4.2Gb  INFO: Finished alignment.
00:02:03 4.2Gb  INFO: Printing alignments to "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/uncompressing/alignments.txt"
00:02:04 4.2Gb  INFO: Reading and processing initial reads from ["phasing-data/smoothed-reads/edge_6104_smoothed_reads_delignore_vrlow.fasta"]
00:05:25 4.2Gb  INFO: Uncompressing homopolymers in contigs
00:05:25 4.2Gb  INFO: Total zero covered nucleotides 0
00:05:25 4.2Gb  INFO: Calculating overlaps between adjacent uncompressed edges
00:05:25 4.2Gb  INFO: Printing final gfa file to "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:05:25 4.2Gb  INFO: Printing final assembly to "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:05:26 5Mb  INFO: Final homopolymer compressed and corrected reads can be found here: "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:05:26 5Mb  INFO: Final graph with homopolymer compressed edges can be found here: "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg/mdbg.hpc.gfa"
00:05:26 5Mb  INFO: Final graph can be found here: "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:05:26 5Mb  INFO: Final assembly can be found here: "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:05:26 5Mb  INFO: LJA pipeline finished
00:00:00 2Mb  INFO: Hello! You are running La Jolla Assembler (LJA), a tool for genome assembly from PacBio HiFi reads
00:00:10 5Mb  INFO: 2ec2b679d91f4230fdfa1949f196954333200ce4
00:00:10 5Mb  INFO: LJA pipeline started
00:00:10 5Mb  INFO: Performing initial correction with k = 5001
00:00:10 0Mb  INFO: Reading reads
00:00:10 0Mb  INFO: Extracting minimizers
00:00:21 3.1Gb  INFO: Finished read processing
00:00:21 3.1Gb  INFO: 3716755 hashs collected. Starting sorting.
00:00:22 3.2Gb  INFO: Finished sorting. Total distinct minimizers: 25231
00:00:22 3.2Gb  INFO: Starting construction of sparse de Bruijn graph
00:00:22 3.2Gb  INFO: Vertex map constructed.
00:00:22 3.2Gb  INFO: Filling edge sequences.
00:00:34 3.2Gb  INFO: Finished sparse de Bruijn graph construction.
00:00:34 3.2Gb  INFO:  Collecting tips
00:00:34 3.2Gb  INFO: Added 1596 artificial minimizers from tips.
00:00:34 3.2Gb  INFO: Collected 49812 old edges.
00:00:34 3.2Gb  INFO: New minimizers added to sparse graph.
00:00:34 3.2Gb  INFO: Refilling graph with old edges.
00:00:35 3.2Gb  INFO: Filling graph with new edges.
00:00:35 3.2Gb  INFO: Finished fixing sparse de Bruijn graph.
00:00:35 3.2Gb  INFO: Starting to extract disjointigs.
00:00:35 3.2Gb  INFO: Finished extracting 2208 disjointigs of total size 17525953
00:00:35 0Mb  INFO: Loading disjointigs from file "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/k5001/disjointigs.fasta"
00:00:36 33Mb  INFO: Filling bloom filter with k+1-mers.
00:00:38 34Mb  INFO: Filled 30009072 bits out of 207479840
00:00:38 34Mb  INFO: Finished filling bloom filter. Selecting junctions.
00:00:38 34Mb  INFO: Collected 4950 junctions.
00:00:38 34Mb  INFO: Starting DBG construction.
00:00:38 34Mb  INFO: Vertices created.
00:00:38 34Mb  INFO: Filled dbg edges. Adding hanging vertices
00:00:38 34Mb  INFO: Added 0 hanging vertices
00:00:38 34Mb  INFO: Merging unbranching paths
00:00:38 34Mb  INFO: Ended merging edges. Resulting size 2542
00:00:39 34Mb  INFO: Cleaning edge coverages
00:00:39 34Mb  INFO: Collecting alignments of sequences to the graph
00:00:44 2.3Gb  INFO: Alignment collection finished. Total length of alignments is 574548
00:00:45 2.3Gb  INFO: Could not correct 4712 reads. They will be removed.
00:00:45 2.3Gb  INFO: Uncorrected reads were removed.
00:00:45 2.3Gb  INFO: Applying changes to the graph
00:00:48 2.4Gb  INFO: Printing reads to fasta file "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:01:07 5Mb  INFO: Performing repeat resolution by transforming de Bruijn graph into Multiplex de Bruijn graph
00:01:07 0Mb  INFO: Loading graph from fasta
00:01:08 12Mb  INFO: Finished loading graph
00:01:08 130Mb  INFO: Looking for unique edges
00:01:08 130Mb  INFO: Marked 79 long edges as unique
00:01:08 130Mb  INFO: Marking extra edges as unique based on read paths
00:01:08 130Mb  INFO: Marked 83 edges as unique
00:01:08 130Mb  INFO: Splitting graph with unique edges
00:01:08 130Mb  INFO: Processing 102 components
00:01:08 130Mb  INFO: Finished unique edges search. Found 91 unique edges
00:01:08 130Mb  INFO: Analysing repeats of multiplicity 2 and looking for additional unique edges
00:01:08 130Mb  INFO: Finished processing of repeats of multiplicity 2. Found 0 erroneous edges.
00:01:08 130Mb  INFO: Resolving repeats
00:01:08 130Mb  INFO: Constructing paths
00:01:10 175Mb  INFO: Building graph
00:01:10 175Mb  INFO: Increasing k
00:01:10 177Mb  INFO: Finished increasing k
00:01:10 177Mb  INFO: Exporting remaining active transitions
00:01:10 177Mb  INFO: Export to Dot
00:01:10 177Mb  INFO: Export to GFA and compressed contigs
00:01:10 184Mb  INFO: Finished repeat resolution
00:01:11 5Mb  INFO: Performing polishing and homopolymer uncompression
00:01:11 6Mb  INFO: Aligning reads back to assembly
00:01:20 2.2Gb  INFO: Finished alignment.
00:01:20 2.2Gb  INFO: Printing alignments to "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/uncompressing/alignments.txt"
00:01:20 2.2Gb  INFO: Reading and processing initial reads from ["phasing-data/smoothed-reads/edge_1671_smoothed_reads_delignore_vrlow.fasta"]
00:02:23 3.4Gb  INFO: Uncompressing homopolymers in contigs
00:02:24 3.4Gb  INFO: Total zero covered nucleotides 0
00:02:24 3.4Gb  INFO: Calculating overlaps between adjacent uncompressed edges
00:02:24 3.4Gb  INFO: Printing final gfa file to "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:02:24 3.4Gb  INFO: Printing final assembly to "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:02:24 5Mb  INFO: Final homopolymer compressed and corrected reads can be found here: "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:02:24 5Mb  INFO: Final graph with homopolymer compressed edges can be found here: "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg/mdbg.hpc.gfa"
00:02:24 5Mb  INFO: Final graph can be found here: "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:02:24 5Mb  INFO: Final assembly can be found here: "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:02:24 5Mb  INFO: LJA pipeline finished
00:00:00 2Mb  INFO: Hello! You are running La Jolla Assembler (LJA), a tool for genome assembly from PacBio HiFi reads
00:00:10 2Mb  INFO: 2ec2b679d91f4230fdfa1949f196954333200ce4
00:00:10 5Mb  INFO: LJA pipeline started
00:00:10 5Mb  INFO: Performing initial correction with k = 5001
00:00:10 0Mb  INFO: Reading reads
00:00:10 0Mb  INFO: Extracting minimizers
00:00:46 5.8Gb  INFO: Finished read processing
00:00:46 5.8Gb  INFO: 12260029 hashs collected. Starting sorting.
00:00:46 5.8Gb  INFO: Finished sorting. Total distinct minimizers: 10087
00:00:46 5.8Gb  INFO: Starting construction of sparse de Bruijn graph
00:00:46 5.8Gb  INFO: Vertex map constructed.
00:00:46 5.8Gb  INFO: Filling edge sequences.
00:01:21 5.8Gb  INFO: Finished sparse de Bruijn graph construction.
00:01:21 5.8Gb  INFO:  Collecting tips
00:01:21 5.8Gb  INFO: Added 29 artificial minimizers from tips.
00:01:21 5.8Gb  INFO: Collected 20348 old edges.
00:01:21 5.8Gb  INFO: New minimizers added to sparse graph.
00:01:21 5.8Gb  INFO: Refilling graph with old edges.
00:01:22 5.8Gb  INFO: Filling graph with new edges.
00:01:22 5.8Gb  INFO: Finished fixing sparse de Bruijn graph.
00:01:22 5.8Gb  INFO: Starting to extract disjointigs.
00:01:22 5.8Gb  INFO: Finished extracting 313 disjointigs of total size 4093868
00:01:22 0Mb  INFO: Loading disjointigs from file "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/k5001/disjointigs.fasta"
00:01:22 14Mb  INFO: Filling bloom filter with k+1-mers.
00:01:23 15Mb  INFO: Filled 11703639 bits out of 80913760
00:01:23 15Mb  INFO: Finished filling bloom filter. Selecting junctions.
00:01:23 15Mb  INFO: Collected 1238 junctions.
00:01:23 15Mb  INFO: Starting DBG construction.
00:01:23 15Mb  INFO: Vertices created.
00:01:24 15Mb  INFO: Filled dbg edges. Adding hanging vertices
00:01:24 15Mb  INFO: Added 0 hanging vertices
00:01:24 15Mb  INFO: Merging unbranching paths
00:01:24 15Mb  INFO: Ended merging edges. Resulting size 232
00:01:24 15Mb  INFO: Cleaning edge coverages
00:01:24 15Mb  INFO: Collecting alignments of sequences to the graph
00:01:45 7.9Gb  INFO: Alignment collection finished. Total length of alignments is 832018
00:01:46 7.9Gb  INFO: Could not correct 469 reads. They will be removed.
00:01:46 7.9Gb  INFO: Uncorrected reads were removed.
00:01:46 7.9Gb  INFO: Applying changes to the graph
00:01:51 8.2Gb  INFO: Printing reads to fasta file "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:02:50 5Mb  INFO: Performing repeat resolution by transforming de Bruijn graph into Multiplex de Bruijn graph
00:02:50 0Mb  INFO: Loading graph from fasta
00:02:50 11Mb  INFO: Finished loading graph
00:02:51 245Mb  INFO: Looking for unique edges
00:02:51 245Mb  INFO: Marked 29 long edges as unique
00:02:51 245Mb  INFO: Marking extra edges as unique based on read paths
00:02:51 245Mb  INFO: Marked 29 edges as unique
00:02:51 245Mb  INFO: Splitting graph with unique edges
00:02:51 245Mb  INFO: Processing 16 components
00:02:51 245Mb  INFO: Finished unique edges search. Found 177 unique edges
00:02:51 245Mb  INFO: Analysing repeats of multiplicity 2 and looking for additional unique edges
00:02:51 245Mb  INFO: Finished processing of repeats of multiplicity 2. Found 0 erroneous edges.
00:02:51 245Mb  INFO: Resolving repeats
00:02:51 245Mb  INFO: Constructing paths
00:02:57 449Mb  INFO: Building graph
00:02:57 449Mb  INFO: Increasing k
00:02:58 449Mb  INFO: Finished increasing k
00:02:58 449Mb  INFO: Exporting remaining active transitions
00:02:58 449Mb  INFO: Export to Dot
00:02:58 449Mb  INFO: Export to GFA and compressed contigs
00:02:59 456Mb  INFO: Finished repeat resolution
00:02:59 5Mb  INFO: Performing polishing and homopolymer uncompression
00:02:59 10Mb  INFO: Aligning reads back to assembly
00:03:32 4.1Gb  INFO: Finished alignment.
00:03:32 4.1Gb  INFO: Printing alignments to "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/uncompressing/alignments.txt"
00:03:33 4.1Gb  INFO: Reading and processing initial reads from ["phasing-data/smoothed-reads/edge_2358_smoothed_reads_delignore_vrlow.fasta"]
00:09:18 11.6Gb  INFO: Uncompressing homopolymers in contigs
00:09:19 11.6Gb  INFO: Total zero covered nucleotides 0
00:09:19 11.6Gb  INFO: Calculating overlaps between adjacent uncompressed edges
00:09:19 11.6Gb  INFO: Printing final gfa file to "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:09:20 11.6Gb  INFO: Printing final assembly to "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:09:20 5Mb  INFO: Final homopolymer compressed and corrected reads can be found here: "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/k5001/corrected_reads.fasta"
00:09:20 5Mb  INFO: Final graph with homopolymer compressed edges can be found here: "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg/mdbg.hpc.gfa"
00:09:20 5Mb  INFO: Final graph can be found here: "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
00:09:20 5Mb  INFO: Final assembly can be found here: "phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/assembly.fasta"
00:09:20 5Mb  INFO: LJA pipeline finished

## 3. Double-check edge locations in original MAG

In LJA's output, the assembly.fasta file doesn't always exactly match up with the segments in the mdbg.gfa file; we are interested here in associating parts of the graph with the original MAG, so we align these segments (which may contain e.g. overlapping or redundant sequences) rather than the actual final contigs._____no_output_____

for seq in SEQS:
    # this code is yoinked and modified slightly from
    # https://gist.github.com/fedarko/9fe32014f1e55d80511be0d22dc36830 (... which I wrote)

    gfa_fn   = f"phasing-data/smoothed-reads/{seq}_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa"
    fasta_fn = f"phasing-data/smoothed-reads/{seq}_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta"

    num_seqs = 0

    # NOTE this string will eventually contain the entire output FASTA file in
    # memory; it'd be more efficient to split this into chunks to reduce space requirements
    fasta_out = ""

    print(f"Converting GFA file to FASTA...\n  Input:  {gfa_fn}\n  Output: {fasta_fn}")

    with open(gfa_fn, "r") as gfa_file:
        for line in gfa_file:
            if line.startswith("S\t"):
                split = line.strip().split("\t")
                seq = split[2]
                fasta_out += ">{}\n".format(split[1])
                fasta_out += split[2] + "\n"
                num_seqs += 1

    with open(fasta_fn, "w") as fasta_file:
        fasta_file.write(fasta_out)

    print(f"FASTA of {num_seqs} sequences created.\n----")Converting GFA file to FASTA...
  Input:  phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa
  Output: phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
FASTA of 53 sequences created.
----
Converting GFA file to FASTA...
  Input:  phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa
  Output: phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
FASTA of 53 sequences created.
----
Converting GFA file to FASTA...
  Input:  phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg.gfa
  Output: phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
FASTA of 153 sequences created.
----
%%bash

OUTDIR=phasing-data/smoothed-reads

minimap2 -ax asm20 --secondary=no --MD \
    /Poppy/mfedarko/sheepgut/seqs/edge_6104.fasta $OUTDIR/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta > \
    $OUTDIR/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/seq2mag.sam

minimap2 -ax asm20 --secondary=no --MD \
    /Poppy/mfedarko/sheepgut/seqs/edge_1671.fasta $OUTDIR/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta > \
    $OUTDIR/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/seq2mag.sam

minimap2 -ax asm20 --secondary=no --MD \
    /Poppy/mfedarko/sheepgut/seqs/edge_2358.fasta $OUTDIR/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta > \
    $OUTDIR/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/seq2mag.sam[M::mm_idx_gen::0.053*0.99] collected minimizers
[M::mm_idx_gen::0.072*1.50] sorted minimizers
[M::main::0.072*1.50] loaded/built the index for 1 target sequence(s)
[M::mm_mapopt_update::0.081*1.43] mid_occ = 100
[M::mm_idx_stat] kmer size: 19; skip: 10; is_hpc: 0; #seq: 1
[M::mm_idx_stat::0.086*1.44] distinct minimizers: 230439 (98.64% are singletons); average occurrences: 1.017; average spacing: 5.499
[M::worker_pipeline::0.515*2.53] mapped 53 sequences
[M::main] Version: 2.17-r941
[M::main] CMD: minimap2 -ax asm20 --secondary=no --MD /Poppy/mfedarko/sheepgut/seqs/edge_6104.fasta phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
[M::main] Real time: 0.528 sec; CPU: 1.316 sec; Peak RSS: 0.030 GB
[M::mm_idx_gen::0.072*1.00] collected minimizers
[M::mm_idx_gen::0.098*1.47] sorted minimizers
[M::main::0.098*1.47] loaded/built the index for 1 target sequence(s)
[M::mm_mapopt_update::0.110*1.42] mid_occ = 100
[M::mm_idx_stat] kmer size: 19; skip: 10; is_hpc: 0; #seq: 1
[M::mm_idx_stat::0.116*1.38] distinct minimizers: 384668 (98.91% are singletons); average occurrences: 1.017; average spacing: 5.506
[M::worker_pipeline::0.568*2.46] mapped 53 sequences
[M::main] Version: 2.17-r941
[M::main] CMD: minimap2 -ax asm20 --secondary=no --MD /Poppy/mfedarko/sheepgut/seqs/edge_1671.fasta phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
[M::main] Real time: 0.581 sec; CPU: 1.412 sec; Peak RSS: 0.053 GB
[M::mm_idx_gen::0.094*0.98] collected minimizers
[M::mm_idx_gen::0.122*1.41] sorted minimizers
[M::main::0.122*1.41] loaded/built the index for 1 target sequence(s)
[M::mm_mapopt_update::0.137*1.35] mid_occ = 100
[M::mm_idx_stat] kmer size: 19; skip: 10; is_hpc: 0; #seq: 1
[M::mm_idx_stat::0.144*1.33] distinct minimizers: 478571 (97.87% are singletons); average occurrences: 1.067; average spacing: 5.497
[M::worker_pipeline::1.292*2.64] mapped 153 sequences
[M::main] Version: 2.17-r941
[M::main] CMD: minimap2 -ax asm20 --secondary=no --MD /Poppy/mfedarko/sheepgut/seqs/edge_2358.fasta phasing-data/smoothed-reads/edge_2358_lja_cf_10x_p1pct_delignore_vrlow/mdbg-seqs.fasta
[M::main] Real time: 1.307 sec; CPU: 3.428 sec; Peak RSS: 0.066 GB

### 3.1. Check edge locations in CAMP

- Figure out which edge(s) in the graph intersect with gene 1217
- Extract gene 1217 haplotypes from these edges

To clarify, this is the gene with lots of ~16% mutations. It's analyzed in more detail in `Phasing-LJA-CAMP-Gene.ipynb`.

Previously, I had some code here which checked where the edges in a small "disconnected" component in the graph were aligned in the CAMP MAG; this illustrated that these edges mapped to a region in the start of the MAG, right before a coverage drop. This was the motivation for some modifications to the virtual read generation process, which successfully re-connected the graph._____no_output_____

# Copied from Phasing-LJA-CAMP-Gene.ipynb... sorry for the duplication!

mps = [1209000, 1209009, 1209021, 1209057, 1209103, 1209114, 1209120, 1209125,
       1209132, 1209135, 1209141, 1209144, 1209147, 1209153, 1209204, 1209240,
       1209264, 1209265, 1209296, 1209321, 1209324, 1209336, 1209399, 1209402,
       1209417, 1209420, 1209423, 1209522, 1209576, 1209609, 1209696, 1209699,
       1209756, 1209795]
assert len(mps) == 34_____no_output_____afp = "phasing-data/smoothed-reads/edge_6104_lja_cf_10x_p1pct_delignore_vrlow/seq2mag.sam"
g1217_contigs = []

e2mp2hap = {}
f = pysam.AlignmentFile(afp)
for aln in f.fetch():
    ap = aln.get_aligned_pairs(matches_only=True)
    aln_seq = aln.query_sequence
    contig_name = aln.query_name
    mp2hap = {}
    edge_intersects_g1217 = False
    # we can't assign to strings, so we use a list of characters for the haplotype
    hap = [" "] * len(mps)
    for pair in ap:
        ref_pos = pair[1]
        if ref_pos >= 1208926 and ref_pos <= 1210074:
            edge_intersects_g1217 = True
            if ref_pos in mps:
                if ref_pos in mp2hap:
                    raise ValueError("How is this edge aligned to this same mutated position twice???")
                mp2hap[ref_pos] = aln_seq[pair[0]]
                hap[mps.index(ref_pos)] = aln_seq[pair[0]]

    if edge_intersects_g1217:
        e2mp2hap[contig_name] = (mp2hap, "".join(hap))
        g1217_contigs.append((contig_name, aln.get_blocks()))

print(f"The following {len(g1217_contigs):,} contigs intersect with gene 1217 in CAMP.")
print(", ".join([t[0] for t in g1217_contigs]))
print("The positions in CAMP to which these contigs are aligned are as follows:\n")
for t in g1217_contigs:
    print(
        f"{t[0]}:\n  Position range(s): {t[1]}\n  "
        f"mutpos to haplotype: {e2mp2hap[t[0]][1]} (covers {len(e2mp2hap[t[0]][0])} mutpos)"
    )

print("Unique haplotypes:\n ", "\n  ".join(set([e2mp2hap[e][1] for e in e2mp2hap.keys()])))The following 6 contigs intersect with gene 1217 in CAMP.
78, 67, 24, 25, 26, 28
The positions in CAMP to which these contigs are aligned are as follows:

78:
  Position range(s): [(1144992, 1209001)]
  mutpos to haplotype: A                                  (covers 1 mutpos)
67:
  Position range(s): [(1209756, 1289244)]
  mutpos to haplotype:                                 AA (covers 2 mutpos)
24:
  Position range(s): [(1202436, 1266671)]
  mutpos to haplotype: AAACCCGAGTGCATGGTCTCCTTAACTAACTTAA (covers 34 mutpos)
25:
  Position range(s): [(1151940, 1259331)]
  mutpos to haplotype: AAACCCGAGTGCATGGTCTCCTTAACTAACTTAA (covers 34 mutpos)
26:
  Position range(s): [(1144992, 1259331)]
  mutpos to haplotype: AAACCCGAGTGCATGGTCTCCTTAACTAACTTAA (covers 34 mutpos)
28:
  Position range(s): [(1151940, 1266671)]
  mutpos to haplotype: GCGTTAAGACATTAAACGCTTCCGGTCGGTACGG (covers 34 mutpos)
Unique haplotypes:
  GCGTTAAGACATTAAACGCTTCCGGTCGGTACGG
  AAACCCGAGTGCATGGTCTCCTTAACTAACTTAA
  A
                                  AA

Corresponds to the highlighted segments in this bubble, right at the end of the CAMP multiplex de Bruijn graph:

![image-2.png](attachment:image-2.png)_____no_output_____

f = pysam.AlignmentFile(afp)
c2s = {}
for aln in f.fetch():
    contig_name = aln.query_name
    if contig_name == "25" or contig_name == "26":
        c2s[contig_name] = aln.query_sequence_____no_output_____s1 = c2s["25"]
s2 = c2s["26"][6948:]
assert len(s1) == len(s2)_____no_output_____for pi, p in enumerate(s1):
    if s1[pi] != s2[pi]:
        print(pi, s1[pi], s2[pi])50495 T A
50497 A G
50495 + 1151940_____no_output_____

### 3.2. Double-check edge locations in BACT1

Like with CAMP, figure out what's up with the disconnected sections of the graph._____no_output_____

# Copied from MetagenomeScope
dc_node_tbl = """78	46,364 bp	+	37.16%
79	46,364 bp	+	37.16%
-179	46,521 bp	-	36.76%
-178	33,558 bp	-	36.93%
-78	46,364 bp	-	37.16%
-79	46,364 bp	-	37.16%
179	46,521 bp	+	36.76%
178	33,558 bp	+	36.93%
127	105,027 bp	+	36.74%
-168	65,017 bp	-	36.83%
128	105,027 bp	+	36.74%
-127	105,027 bp	-	36.74%
168	65,017 bp	+	36.83%
-128	105,027 bp	-	36.74%
216	76,608 bp	+	34.75%
-216	76,608 bp	-	34.75%
223	72,604 bp	+	37.79%
-223	72,604 bp	-	37.79%
163	85,567 bp	+	36.74%
-163	85,567 bp	-	36.74%
217	76,608 bp	+	34.74%
-217	76,608 bp	-	34.74%
186	63,836 bp	+	37.42%
-186	63,836 bp	-	37.42%
64	61,374 bp	+	37.25%
-64	61,374 bp	-	37.25%"""

dc_contigs = set()
for row in dc_node_tbl.splitlines():
    nodename = row.strip().split()[0]
    if nodename[0] == "-":
        dc_contigs.add(nodename[1:])
    else:
        dc_contigs.add(nodename)
dc_contigs_____no_output_____afp = "phasing-data/smoothed-reads/edge_1671_lja_cf_10x_p1pct_delignore_vrlow/seq2mag.sam"
f = pysam.AlignmentFile(afp)
for aln in f.fetch():
    contig_name = aln.query_name
    if contig_name in dc_contigs:
        print(contig_name)
        print(aln.get_blocks())
#     else:
#         if set(range(aln.get_blocks()[0][0], aln.get_blocks()[0][1])) & set(range(0, 101488)):
#             print(contig_name, aln.get_blocks(), "overlaps with beginning")216
[(1281887, 1281927), (1281929, 1358497)]
127
[(190582, 295609)]
223
[(352798, 425402)]
168
[(238928, 303945)]
163
[(97145, 182533), (182536, 182715)]
217
[(1281887, 1281927), (1281929, 1358497)]
186
[(11241, 75077)]
78
[(1443454, 1489818)]
79
[(1443454, 1489818)]
128
[(190582, 295609)]
64
[(13703, 75077)]
179
[(1413410, 1414357), (1414358, 1459932)]
178
[(1426374, 1459932)]