Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

thread 'main' panicked: "Traceback cigar end position must be in bounds!" #34

Open
d-cameron opened this issue Oct 1, 2024 · 0 comments

Comments

@d-cameron
Copy link

Crash when running on certain input data with free query gap:

use std::cmp::max;

use block_aligner::{cigar::*, scan_block::*, scores::*};

fn aln<const XDROP: bool, const FREE_QUERY_START_GAPS: bool, const FREE_QUERY_END_GAPS: bool>(
    qstr: &[u8],
    rstr: &[u8],
    xdrop: i32,
) -> String {
    let mut min_block_size = 32;
    let mut max_block_size = 256;
    // A gap of length n will cost: open + extend * (n - 1)
    let gaps = Gaps {
        open: -18,
        extend: -2,
    };
    let mat = NucMatrix::new_simple(2, -8);
    let r = PaddedBytes::from_bytes::<NucMatrix>(rstr, max_block_size);
    let q = PaddedBytes::from_bytes::<NucMatrix>(qstr, max_block_size);
    while FREE_QUERY_END_GAPS && min_block_size <= qstr.len() {
        min_block_size *= 2;
        max_block_size = max(min_block_size, max_block_size);
    }
    let mut ba = Block::<true, XDROP, false, FREE_QUERY_START_GAPS, FREE_QUERY_END_GAPS>::new(
        q.len(),
        r.len(),
        max_block_size,
    );
    ba.align(&q, &r, &mat, gaps, min_block_size..=max_block_size, xdrop);
    let res = ba.res();
    let mut cigar = Cigar::new(res.query_idx, res.reference_idx);
    ba.trace()
        .cigar_eq(&q, &r, res.query_idx, res.reference_idx, &mut cigar);
    let qi = res.query_idx;
    let ri = res.reference_idx;
    format!("{cigar} q={qi} r={ri}")
}
fn print_aln(qstr: &[u8], rstr: &[u8]) {
    println!(
        "For sequences q={}, r={}:\nFree start is: {}\nFree end is: {}\nBoth free is: {}\nX-drop is: {}",
        String::from_utf8(qstr.to_vec()).unwrap(),
        String::from_utf8(rstr.to_vec()).unwrap(),
        aln::<false, true, false>(qstr, rstr, 0),
        aln::<false, false, true>(qstr, rstr, 0),
        aln::<false, true, true>(qstr, rstr, 0),
        aln::<true, false, false>(qstr, rstr, 50),
    );
}
fn main() {
    print_aln(
        b"CAAAACAAAGTTTTTGACTTAGGCTTCGGGTGTGTAATAATACGACACGATCAATTTTATTCAATACTCTACCCTTTATCCCGTTGGGGTATATATATATTTTAATGTATGTTATATTATATATATTGTATATATTGTGTATATATTAAAGGAAAATGTAGGACTTACGAATATAATATATATTATATAATATATATTATTTATTATTATATATTAATATACATTATATATATTACTATATCTATATTAATAATATTTATTATATATTTTAATATATACATTAATATATTAATATATATTAACATATATTAATATATATATATTAATGTATACATTAATATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAATATATATTATATTCTATATATAATATATATTATATGCCATATATAATATATATTACATTATATGATATATATAATATATATTACATTATATGCTATATATAATATATACTATAGATTATAGATTATATATTATATATAATGTATATAGTATTATATTATGTATAATATTATACATATTGTATGTAATATAATATATATTATATAATTTTATATATTGTATAATATATATTATATATATTATATGTATAATATATATAATATATAATTAATAAATTATATATNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCAAAACAAAGTTTTTGACTTAGGCTTCGGGTGTGTAATAATACGACACGATCAATTTTATTCAATACTCTACCCTTTATCCCGTTGGGGTATATATATATTTTAATGTATGTTATATTATATATATTGTATATATTGTGTATATATTAAAGGAAAATGTAGGACTTACGAATATAATATATATTATATAATATATATTATTTATTATTATATATTAATATACATTATATATATTACTATATCTATATTAATAATATTTATTATATATTTTAATATATACATTAATATATTAATATATATTAACATATATTAATATATATATTAATGTATATTAACATATATTAATATATATATTAATGTATACATTAATATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAAGATATATTATATGCTATATATAATATATATTATATTCTATATATAATATATATTATATGCCATATATAATATATATTACATTATATGATATATATAATATATATTACATTATATGCTATATATAATATATACTATAGATTATAGATTATATATTATATATAATGTATATAGTATTATATTATGTATAATATTATACATATTGTATGTAATATAATATATATTATATAATTTTATATATTGTATAATATATATTATATTATATATATTATATGTAATATATATAATATATAATTAATAAATTATATATTATATTATAGTATATACAATATATAATAAATTATATAATATATATAATATATTGTAATATATAATATAATATATAATATATTAATATATAAAATATTAATATATTATATATATTAATATATTAACATATTAATATTAATATATATAATATATAATATAATACATAACACATATTAATATATATAATATTCTATATAACATTATATAATATATTATATATAAAAATATAATAAATATTATATATAGTATATAATAAATATTATATAAATATAATATATAATATATAATATATGTATAATATATTAATATGTATATATAATATACAATATATATTATATGCATAATATATTATATATTAATATATTAATATTAATATATTAATTAGATATATTAATACATTATATAATATATTATATATAATATATTATATACATTATATAATATATTATATATATTATATTATAATATAATATATATTATTATATTATATTATATAATATATATTAT",
    b"CTTTTTATTTTTAGTTCCTTTTACTTTGGTGTTTCCAAGTTAAACGAGACTGTAAACTTTTTGAGTCGTGTCTGTCACCGTGAATCCTGGTTCCCGTCCTCTAGGGATTAGGGTAGTGGAACCGCTATCCCGTATTTGTAAGGTCCCACTTCCGTGTTATGTGTAACACTCCAGGTTGACGATGGTCCGTCTGTCCTCACGAAAATGTACATGTCCTTCCAGTAACTTCCGAGTCACAAAACAAAGTTTTTGACTTAGGCTTCGGGTGTGTAATAATACGACACGATCAATTTTATTCAATACTCTACCCTTTATCCCGTTGGGGTATATATATATTTTAATGTATGTTATATTATATATATTGTATATATTGTGTATATATTAAAGGAAAATGTAGGACTTACGAATATAATA");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant