annotate PsiCLASS-1.0.2/samtools-0.1.19/bamtk.c @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #include <stdio.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #include <unistd.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 #include <assert.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include <fcntl.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5 #include "bam.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 #ifdef _USE_KNETFILE
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 #include "knetfile.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 int bam_taf2baf(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 int bam_mpileup(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 int bam_merge(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 int bam_index(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 int bam_sort(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 int bam_tview_main(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 int bam_mating(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 int bam_rmdup(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 int bam_flagstat(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 int bam_fillmd(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 int bam_idxstats(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 int main_samview(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 int main_import(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 int main_reheader(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 int main_cut_target(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 int main_phase(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 int main_cat(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 int main_depth(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 int main_bam2fq(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 int main_pad2unpad(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 int main_bedcov(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 int main_bamshuf(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 int faidx_main(int argc, char *argv[]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 static int usage()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 fprintf(stderr, "\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 fprintf(stderr, "Program: samtools (Tools for alignments in the SAM format)\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 fprintf(stderr, "Version: %s\n\n", BAM_VERSION);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 fprintf(stderr, "Usage: samtools <command> [options]\n\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 fprintf(stderr, "Command: view SAM<->BAM conversion\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 fprintf(stderr, " sort sort alignment file\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 fprintf(stderr, " mpileup multi-way pileup\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 fprintf(stderr, " depth compute the depth\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 fprintf(stderr, " faidx index/extract FASTA\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 #if _CURSES_LIB != 0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 fprintf(stderr, " tview text alignment viewer\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 fprintf(stderr, " index index alignment\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 fprintf(stderr, " idxstats BAM index stats (r595 or later)\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 fprintf(stderr, " fixmate fix mate information\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 fprintf(stderr, " flagstat simple stats\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 fprintf(stderr, " calmd recalculate MD/NM tags and '=' bases\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 fprintf(stderr, " merge merge sorted alignments\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 fprintf(stderr, " rmdup remove PCR duplicates\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 fprintf(stderr, " reheader replace BAM header\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 fprintf(stderr, " cat concatenate BAMs\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 fprintf(stderr, " bedcov read depth per BED region\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 fprintf(stderr, " targetcut cut fosmid regions (for fosmid pool only)\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 fprintf(stderr, " phase phase heterozygotes\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 fprintf(stderr, " bamshuf shuffle and group alignments by name\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 // fprintf(stderr, " depad convert padded BAM to unpadded BAM\n"); // not stable
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 fprintf(stderr, "\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 #ifdef _WIN32
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 fprintf(stderr, "\
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 Note: The Windows version of SAMtools is mainly designed for read-only\n\
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 operations, such as viewing the alignments and generating the pileup.\n\
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 Binary files generated by the Windows version may be buggy.\n\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 return 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74 int main(int argc, char *argv[])
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 #ifdef _WIN32
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77 setmode(fileno(stdout), O_BINARY);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78 setmode(fileno(stdin), O_BINARY);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79 #ifdef _USE_KNETFILE
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80 knet_win32_init();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 if (argc < 2) return usage();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
84 if (strcmp(argv[1], "view") == 0) return main_samview(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
85 else if (strcmp(argv[1], "import") == 0) return main_import(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
86 else if (strcmp(argv[1], "mpileup") == 0) return bam_mpileup(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
87 else if (strcmp(argv[1], "merge") == 0) return bam_merge(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
88 else if (strcmp(argv[1], "sort") == 0) return bam_sort(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
89 else if (strcmp(argv[1], "index") == 0) return bam_index(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
90 else if (strcmp(argv[1], "idxstats") == 0) return bam_idxstats(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
91 else if (strcmp(argv[1], "faidx") == 0) return faidx_main(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
92 else if (strcmp(argv[1], "fixmate") == 0) return bam_mating(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
93 else if (strcmp(argv[1], "rmdup") == 0) return bam_rmdup(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
94 else if (strcmp(argv[1], "flagstat") == 0) return bam_flagstat(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
95 else if (strcmp(argv[1], "calmd") == 0) return bam_fillmd(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
96 else if (strcmp(argv[1], "fillmd") == 0) return bam_fillmd(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
97 else if (strcmp(argv[1], "reheader") == 0) return main_reheader(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
98 else if (strcmp(argv[1], "cat") == 0) return main_cat(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
99 else if (strcmp(argv[1], "targetcut") == 0) return main_cut_target(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
100 else if (strcmp(argv[1], "phase") == 0) return main_phase(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
101 else if (strcmp(argv[1], "depth") == 0) return main_depth(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
102 else if (strcmp(argv[1], "bam2fq") == 0) return main_bam2fq(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
103 else if (strcmp(argv[1], "pad2unpad") == 0) return main_pad2unpad(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
104 else if (strcmp(argv[1], "depad") == 0) return main_pad2unpad(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
105 else if (strcmp(argv[1], "bedcov") == 0) return main_bedcov(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
106 else if (strcmp(argv[1], "bamshuf") == 0) return main_bamshuf(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
107 else if (strcmp(argv[1], "pileup") == 0) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
108 fprintf(stderr, "[main] The `pileup' command has been removed. Please use `mpileup' instead.\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
109 return 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
110 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
111 #if _CURSES_LIB != 0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
112 else if (strcmp(argv[1], "tview") == 0) return bam_tview_main(argc-1, argv+1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
113 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
114 else {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
115 fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
116 return 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
117 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
118 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
119 }