/// Create a new BAM file.
///
/// # Arguments
///
/// * `path` - the path. Use "-" for stdin.
/// * `header` - header definition to use
Create a new BAM file.
Create a new BAM file .
fn new(path: &[u8], header: &header::Header) -> Result<Self, BGZFError> {
        let f = try!(bgzf_open(&ffi::CString::new(path).unwrap(), b"w"));
        // sam_hdr_parse does not populate the text and l_text fields of the header_record.
        // This causes non-SQ headers to be dropped in the output BAM file.
        // To avoid this, we copy the full header to a new C-string that is allocated with malloc,
        // and set this into header_record manually.
        let header_record = unsafe {
            let mut header_string = header.to_bytes();
            if !header_string.is_empty() && header_string[header_string.len() - 1] != b'\n' {
                header_string.push(b'\n');
            }
            let l_text = header_string.len();
            let text = ::libc::malloc(l_text + 1);
            libc::memset(text, 0, l_text + 1);
            libc::memcpy(
                text,
                header_string.as_ptr() as *const ::libc::c_void,
                header_string.len(),
            );
            //println!("{}", str::from_utf8(&header_string).unwrap());
            let rec = htslib::sam_hdr_parse((l_text + 1) as i32, text as *const i8);
            (*rec).text = text as *mut i8;
            (*rec).l_text = l_text as u32;
            rec
        };
        unsafe {
            htslib::bam_hdr_write(f, header_record);
        }
        Ok(Writer {
            f: f,
            header: HeaderView::new(header_record),
        })
    }
fn new ( path : & [ u8 ] , header : & header :: Header ) -> Result < Self , BGZFError > { let f = try ! ( bgzf_open ( ffi CString new ( path ) unwrap ( ) b" " ) ) ; // sam_hdr_parse does not populate the text and l_text fields of the header_record. // This causes non-SQ headers to be dropped in the output BAM file. // To avoid this, we copy the full header to a new C-string that is allocated with malloc, // and set this into header_record manually. let header_record = unsafe { let mut header_string = header . to_bytes ( ) ; if ! header_string . is_empty ( ) && header_string [ header_string . len ( ) - 1 ] != b'\n' { header_string . push ( b'\n' ) ; } let l_text = header_string . len ( ) ; let text = :: libc :: malloc ( l_text + 1 ) ; libc :: memset ( text , 0 , l_text + 1 ) ; libc :: memcpy ( text , header_string . as_ptr ( ) as * const :: libc :: c_void , header_string . len ( ) , ) ; //println!("{}", str::from_utf8(&header_string).unwrap()); let rec = htslib :: sam_hdr_parse ( ( l_text + 1 ) as i32 , text as * const i8 ) ; ( * rec ) . text = text as * mut i8 ; ( * rec ) . l_text = l_text as u32 ; rec } ; unsafe { htslib :: bam_hdr_write ( f , header_record ) ; } Ok ( Writer { f : f , header : HeaderView :: new ( header_record ) , } ) }
Create a new BAM file.
Create a new BAM file .
path
&[u8]
header
&header::Header