annotate ezBAMQC/src/htslib/test/fieldarith.c @ 20:9de3bbec2479 draft default tip

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