/* * Writes an annotation list to disk. If reading is a negative number then * it is assumed to be a contig number instead. * * Comp, start, end and length refer to the parameters for the reading that * this tag is from. * * Offset should contain the offset of this reading in the contig when writing * consensus tags. */ static void write_anno_list(GapIO *io, anno_info *ap, int len, int reading, int offset, int comp, int start, int end, int length) { int i, start2, end2; for (i = 0; i < len; i++) { /* * Clip to used length of sequence when translating tags to the * consensus. */ if (reading < 0) { if (comp) { start2 = length - ap[i].end + 1; end2 = length - ap[i].start + 1; } else { start2 = ap[i].start; end2 = ap[i].end; } if (start2 + offset < 0) start2 = 0 - offset; /* Can't check yet as we don't know the contig length */ #if 0 if (end2 >= end) end2 = end-1; if (end2 < start2) continue; #endif } else { start2 = ap[i].start; end2 = ap[i].end; if (start2 + offset < 1 || end2 + offset > length) { verror(ERR_WARN, "enter_reading", "Tag on reading %s overlaps gel reading ends - not " "entered", get_read_name(io, reading)); continue; } else if (end2 < start2) { verror(ERR_WARN, "enter_reading", "Tag on reading %s has negative length - not entered", get_read_name(io, reading)); continue; } } insert_NEW_tag(io, (tag_id)reading, start2 + offset, end2 - start2 + 1, ap[i].type, ap[i].comment, ap[i].strand); } return; }
void bam_parser(opt_t *opt) { samFile *in = sam_open(opt->in_name, "r"); if(in == NULL) die("bam_parser: fail to open file '%s'", opt->in_name); // if output file exists but not force to overwrite if(access(opt->out_name, F_OK)!=-1 && opt->f==false) die("bam_parser: %s exists, use opetion -f to overwrite", opt->out_name); bam_hdr_t *header = sam_hdr_read(in); bam1_t *aln = bam_init1(); int8_t *p; int32_t n; int ret; while((ret=sam_read1(in, header, aln)) >= 0) printf("name=%s\nflag=%d\nseq=%s\nqual=%s\nlane_id=%d\n", get_read_name(aln), aln->core.flag, get_sequence(aln), get_qualities(aln), get_lane_id(aln)); bam_destroy1(aln); sam_close(in); }