int main() { samfile_t *in = 0, *out = 0; int slx2sngr = 0; char in_mode[5], out_mode[5], *fn_out = 0, *fn_list = 0, *fn_ref = 0; strcpy(in_mode, "r"); strcpy(out_mode, "w"); strcat(in_mode, "b"); printf("start******************************************************\n"); char *filename = "/ifs1/RD/shaohaojing/DAI/1000306/1000306_HUMgqbRLJDIAAPE_091015_I58_FC42UC6AAXX_L2_HUMgqbRLJDIAAPE_1.fq.bam.sort.bam"; if ((in = samopen(filename, in_mode, fn_list)) == 0) { fprintf(stderr, "[main_samview] fail to open file for reading.\n"); exit(0); } if (in->header == 0) { fprintf(stderr, "[main_samview] fail to read the header.\n"); exit(0); } if ((out = samopen(fn_out? fn_out : "-", out_mode, in->header)) == 0) { fprintf(stderr, "[main_samview] fail to open file for writing.\n"); exit(0); } bam1_t *b = bam_init1(); int r; char *s; while((r = samread(in, b)) >= 0) { if (!__g_skip_aln(in->header, b)) { s = bam_format1_core(out->header, b, out->type>>2&3); } printf("%s\n", s); free(s); // printf("%s", b->data); // printf("\n++++++++++%d+++++++++++", r); // printf("********************\n"); }
/** * DATE: 2010-7-29 * FUNCTION: read a line from sam/bam file. * PARAMETER: line: the read data will stored in this varible. * RETURN: the line size when read successful. -1 when read failed */ int SamCtrl::readline(std::string &line) { if (m_in == 0) { return -1; } int ret = 0; // begin to read while ((ret = samread(m_in, m_b)) >= 0) { // when read failed continue if (__g_skip_aln(m_in->header, m_b)) { continue; } m_s = bam_format1_core(m_out->header, m_b, m_out->type>>2&3); // read the buffer line = m_s; // store into the line free(m_s); return line.size(); } return -1; }