11 #ifndef PACKAGE_VERSION
12 #define PACKAGE_VERSION "0.1.7-6 (r530)"
15 int bam_taf2baf(int argc, char *argv[]);
16 int bam_pileup(int argc, char *argv[]);
17 int bam_merge(int argc, char *argv[]);
18 int bam_index(int argc, char *argv[]);
19 int bam_sort(int argc, char *argv[]);
20 int bam_tview_main(int argc, char *argv[]);
21 int bam_mating(int argc, char *argv[]);
22 int bam_rmdup(int argc, char *argv[]);
23 int bam_flagstat(int argc, char *argv[]);
24 int bam_fillmd(int argc, char *argv[]);
26 int main_samview(int argc, char *argv[]);
27 int main_import(int argc, char *argv[]);
29 int faidx_main(int argc, char *argv[]);
30 int glf3_view_main(int argc, char *argv[]);
32 int bam_tagview(int argc, char *argv[])
40 fprintf(stderr, "Usage: samtools tagview <in.bam> <tag>\n");
43 fp = strcmp(argv[1], "-")? bam_open(argv[1], "r") : bam_dopen(fileno(stdin), "r");
45 header = bam_header_read(fp);
47 fprintf(stderr, "[bam_view] fail to read the BAM header. Abort!\n");
50 tag[0] = argv[2][0]; tag[1] = argv[2][1];
51 b = (bam1_t*)calloc(1, sizeof(bam1_t));
52 while ((ret = bam_read1(fp, b)) >= 0) {
53 uint8_t *d = bam_aux_get(b, tag);
55 printf("%s\t%d\t", bam1_qname(b), b->core.flag);
56 if (d[0] == 'Z' || d[0] == 'H') printf("%s\n", bam_aux2Z(d));
57 else if (d[0] == 'f') printf("%f\n", bam_aux2f(d));
58 else if (d[0] == 'd') printf("%lf\n", bam_aux2d(d));
59 else if (d[0] == 'A') printf("%c\n", bam_aux2A(d));
60 else if (d[0] == 'c' || d[0] == 's' || d[0] == 'i') printf("%d\n", bam_aux2i(d));
61 else if (d[0] == 'C' || d[0] == 'S' || d[0] == 'I') printf("%u\n", bam_aux2i(d));
65 if (ret < -1) fprintf(stderr, "[bam_view] truncated file? Continue anyway. (%d)\n", ret);
66 free(b->data); free(b);
67 bam_header_destroy(header);
74 fprintf(stderr, "\n");
75 fprintf(stderr, "Program: samtools (Tools for alignments in the SAM format)\n");
76 fprintf(stderr, "Version: %s\n\n", PACKAGE_VERSION);
77 fprintf(stderr, "Usage: samtools <command> [options]\n\n");
78 fprintf(stderr, "Command: view SAM<->BAM conversion\n");
79 fprintf(stderr, " sort sort alignment file\n");
80 fprintf(stderr, " pileup generate pileup output\n");
81 fprintf(stderr, " faidx index/extract FASTA\n");
83 fprintf(stderr, " tview text alignment viewer\n");
85 fprintf(stderr, " index index alignment\n");
86 fprintf(stderr, " fixmate fix mate information\n");
87 fprintf(stderr, " glfview print GLFv3 file\n");
88 fprintf(stderr, " flagstat simple stats\n");
89 fprintf(stderr, " calmd recalculate MD/NM tags and '=' bases\n");
90 fprintf(stderr, " merge merge sorted alignments\n");
91 fprintf(stderr, " rmdup remove PCR duplicates\n");
92 fprintf(stderr, "\n");
96 int main(int argc, char *argv[])
99 setmode(fileno(stdout), O_BINARY);
100 setmode(fileno(stdin), O_BINARY);
105 if (argc < 2) return usage();
106 if (strcmp(argv[1], "view") == 0) return main_samview(argc-1, argv+1);
107 else if (strcmp(argv[1], "import") == 0) return main_import(argc-1, argv+1);
108 else if (strcmp(argv[1], "pileup") == 0) return bam_pileup(argc-1, argv+1);
109 else if (strcmp(argv[1], "merge") == 0) return bam_merge(argc-1, argv+1);
110 else if (strcmp(argv[1], "sort") == 0) return bam_sort(argc-1, argv+1);
111 else if (strcmp(argv[1], "index") == 0) return bam_index(argc-1, argv+1);
112 else if (strcmp(argv[1], "faidx") == 0) return faidx_main(argc-1, argv+1);
113 else if (strcmp(argv[1], "fixmate") == 0) return bam_mating(argc-1, argv+1);
114 else if (strcmp(argv[1], "rmdup") == 0) return bam_rmdup(argc-1, argv+1);
115 else if (strcmp(argv[1], "glfview") == 0) return glf3_view_main(argc-1, argv+1);
116 else if (strcmp(argv[1], "flagstat") == 0) return bam_flagstat(argc-1, argv+1);
117 else if (strcmp(argv[1], "tagview") == 0) return bam_tagview(argc-1, argv+1);
118 else if (strcmp(argv[1], "calmd") == 0) return bam_fillmd(argc-1, argv+1);
119 else if (strcmp(argv[1], "fillmd") == 0) return bam_fillmd(argc-1, argv+1);
121 else if (strcmp(argv[1], "tview") == 0) return bam_tview_main(argc-1, argv+1);
124 fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]);