// create a TE alignment from a string (skip if it doesn't meet criteria)
// we have 3 criteria:
// 1. SAM flag does not "&" with 4 (4 means unmapped)
// 2. The chromosome is an actual chromosome (like 2L and 2R)
// 3. read is a split-read from the genome side (we already know it is from the transposon side)
create a TE alignment from a string (skip if it doesn't meet criteria)
we have 3 criteria:
1. SAM flag does not "&" with 4 (4 means unmapped)
2. The chromosome is an actual chromosome (like 2L and 2R)
3. read is a split-read from the genome side (we already know it is from the transposon side)
create a TE alignment from a string ( skip if it doesn ' t meet criteria ) we have 3 criteria : 1 . SAM flag does not " & " with 4 ( 4 means unmapped ) 2 . The chromosome is an actual chromosome ( like 2L and 2R ) 3 . read is a split - read from the genome side ( we already know it is from the transposon side )
pub fn create(
        genome_alignment_data: Data,
        te_alignment_data: Data,
        chroms: &Vec<String>,
    ) -> Result<(String, GenomeAlignment)> {
        if !GenomeAlignment::is_mapped(genome_alignment_data.get("FLAG")?) {
            bail!("unmapped read");
        }
        let te_name = te_alignment_data.get("TE_NAME")?;
        let old_m: u64 = te_alignment_data.get("OLD_M")?.parse()?;
        let old_s: u64 = te_alignment_data.get("OLD_S")?.parse()?;
        let is_sm_te = te_alignment_data.get("OLD_SM")? == "SM";
        let is_start = te_alignment_data.get("START_OF_TE")? == "start";
        if is_sm_te != is_start {
            let sm_str = {
                if is_sm_te {
                    "SM"
                } else {
                    "MS"
                }
            };
            let start_str = {
                if is_start {
                    "start"
                } else {
                    "end"
                }
            };
            panic!(format!(
                "TE mapper error: TE alignment was {} and aligned to the {} of the transposon",
                sm_str, start_str
            ));
        }
        let flag = genome_alignment_data.get("FLAG")?;
        let chrom = genome_alignment_data.get("RNAME")?;
        let pos: u64 = genome_alignment_data.get("POS")?.parse()?;
        let cigar_str = genome_alignment_data.get("CIGAR")?;
        if !GenomeAlignment::validate_chrom(&chrom, chroms) {
            bail!("invalid chromosome");
        }
        let is_plus = GenomeAlignment::is_plus(flag);
        let split_read = SplitReadGenome::parse(cigar_str, old_m, old_s, is_start, is_plus, pos)?;
        Ok((
            chrom.clone(),
            GenomeAlignment {
                te_name: te_name,
                old_m: old_m,
                old_s: old_s,
                is_sm_te: is_sm_te,
                is_start: is_start,
                new_plus: is_plus,
                chrom: chrom,
                split_read_genome: split_read,
            },
        ))
    }
pub fn create ( genome_alignment_data : Data , te_alignment_data : Data , chroms : & Vec < String > , ) -> Result < ( String , GenomeAlignment ) > { if ! GenomeAlignment :: is_mapped ( genome_alignment_data . get ( " " ) ? ) { bail ! ( " " ) ; } let te_name = te_alignment_data . get ( " " ) ? ; let old_m : u64 = te_alignment_data . get ( " " ) ? . parse ( ) ? ; let old_s : u64 = te_alignment_data . get ( " " ) ? . parse ( ) ? ; let is_sm_te = te_alignment_data . get ( " " ) ? == " " ; let is_start = te_alignment_data . get ( " " ) ? == " " ; if is_sm_te != is_start { let sm_str = { if is_sm_te { " " } else { " " } } ; let start_str = { if is_start { " " } else { " " } } ; panic ! ( format ( " " sm_str start_str ) ) ; } let flag = genome_alignment_data . get ( " " ) ? ; let chrom = genome_alignment_data . get ( " " ) ? ; let pos : u64 = genome_alignment_data . get ( " " ) ? . parse ( ) ? ; let cigar_str = genome_alignment_data . get ( " " ) ? ; if ! GenomeAlignment :: validate_chrom ( & chrom , chroms ) { bail ! ( " " ) ; } let is_plus = GenomeAlignment :: is_plus ( flag ) ; let split_read = SplitReadGenome :: parse ( cigar_str , old_m , old_s , is_start , is_plus , pos ) ? ; Ok ( ( chrom . clone ( ) , GenomeAlignment { te_name : te_name , old_m : old_m , old_s : old_s , is_sm_te : is_sm_te , is_start : is_start , new_plus : is_plus , chrom : chrom , split_read_genome : split_read , } , ) ) }
create a TE alignment from a string (skip if it doesn't meet criteria)
we have 3 criteria:
1.
create a TE alignment from a string ( skip if it doesn ' t meet criteria ) we have 3 criteria : 1 .
genome_alignment_data
Data
te_alignment_data
Data
chroms
&Vec<String>