2 *****************************************************************************
7 *CREATE DATE : 2010-7-29
8 *FUNCTION : definition of class SamCtrl
9 *FILE NAME : SamCtrl.cpp
10 *UPDATE DATE : 2010-8-1
11 *UPDATE BY : Bill Tang
12 *******************************************************************************
26 m_b
= bam_init1(); // initialize m_b
31 SamCtrl::~SamCtrl(void)
39 * FUNCTION: open sam/bam file in pattern mode.
40 * PARAMETER: path: the file's path. mode: the pattern.
41 * RETURN: successful: true. failed: flase.
43 bool SamCtrl::open(const char *path
, const char *mode
)
46 // judge if opened a file before
55 if ((m_in
= samopen(m_in_path
.c_str(), m_in_mode
.c_str(), m_fn_list
)) == 0)
60 if (m_in
->header
== 0)
65 if ((m_out
= samopen(m_out_path
.c_str(), m_out_mode
.c_str(), m_in
->header
)) == 0)
76 * FUNCTION: read a line from sam/bam file.
77 * PARAMETER: line: the read data will stored in this varible.
78 * RETURN: the line size when read successful. -1 when read failed
80 int SamCtrl::readline(std::string
&line
)
89 while ((ret
= samread(m_in
, m_b
)) >= 0)
91 // when read failed continue
92 if (__g_skip_aln(m_in
->header
, m_b
))
97 m_s
= bam_format1_core(m_out
->header
, m_b
, m_out
->type
>>2&3); // read the buffer
98 line
= m_s
; // store into the line
107 * FUNCTION: close the sam/bam file
111 void SamCtrl::close()
126 * FUNCTION: judge if the file is opened successful
128 * RETURN: true if successful else false if failed
130 bool SamCtrl::isOpened()