comparison ezBAMQC/src/htslib/test/fieldarith.c @ 0:dfa3745e5fd8

Uploaded
author youngkim
date Thu, 24 Mar 2016 17:12:52 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfa3745e5fd8
1 /* test/fieldarith.c -- CIGAR field arithmetic test suite.
2
3 Copyright (C) 2013 Genome Research Ltd.
4
5 Author: John Marshall <jm18@sanger.ac.uk>
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE. */
24
25 #include <stdio.h>
26
27 #include "htslib/sam.h"
28
29 int ntests = 0;
30 int nfailures = 0;
31
32 void check(const bam1_t *aln, const char *testname, const char *tag, int value)
33 {
34 int32_t refvalue;
35 uint8_t *aux = bam_aux_get(aln, tag);
36 if (!aux) return;
37 ntests++;
38 refvalue = bam_aux2i(aux);
39 if (value != refvalue) {
40 fprintf(stderr, "%s FAIL for %s: computed %d != %d expected\n",
41 testname, bam_get_qname(aln), value, refvalue);
42 nfailures++;
43 }
44 }
45
46 int main(int argc, char **argv)
47 {
48 bam_hdr_t *header;
49 bam1_t *aln = bam_init1();
50 int i;
51
52 for (i = 1; i < argc; i++) {
53 samFile *in = sam_open(argv[i], "r");
54 if (in == NULL) { perror(argv[1]); return 1; }
55
56 header = sam_hdr_read(in);
57 while (sam_read1(in, header, aln) >= 0) {
58 check(aln, "cigar2qlen", "XQ",
59 bam_cigar2qlen(aln->core.n_cigar, bam_get_cigar(aln)));
60 check(aln, "cigar2rlen", "XR",
61 bam_cigar2rlen(aln->core.n_cigar, bam_get_cigar(aln)));
62 check(aln, "endpos", "XE", bam_endpos(aln));
63 }
64
65 bam_hdr_destroy(header);
66 sam_close(in);
67 }
68
69 bam_destroy1(aln);
70
71 return (nfailures > 0);
72 }