Skip to content

Commit f8016c0

Browse files
vasudeva8jkbonfield
authored andcommitted
Added qtask_ordered, qtask_unordered and index_fasta examples.
The qtask programs demonstrate of use ordered and unordered result processing from a thread pool. The index_fasta and read_fast_index tools demonstrate the fasta indexing capabilities. Improved the Makefile and tidied up the indentation and code example layout / structure in DEMO.md Also several minor wording and spelling fixes.
1 parent a135bc0 commit f8016c0

37 files changed

+1704
-342
lines changed

Diff for: samples/DEMO.md

+510-207
Large diffs are not rendered by default.

Diff for: samples/Makefile

+42-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ HTS_DIR = ../
22
include $(HTS_DIR)/htslib_static.mk
33

44
CC = gcc
5-
CFLAGS = -Wall -g -O0
5+
CFLAGS = -Wall -O2
66

77
#to statically link to libhts
88
LDFLAGS = $(HTS_DIR)/libhts.a -L$(HTS_DIR) $(HTSLIB_static_LDFLAGS) $(HTSLIB_static_LIBS)
@@ -13,91 +13,104 @@ LDFLAGS = $(HTS_DIR)/libhts.a -L$(HTS_DIR) $(HTSLIB_static_LDFLAGS) $(HTSLIB_sta
1313
PRGS = flags split split2 cram read_fast read_header read_ref read_bam \
1414
read_aux dump_aux add_header rem_header update_header mod_bam mod_aux \
1515
mod_aux_ba write_fast idx_on_write read_reg read_multireg pileup \
16-
mpileup modstate pileup_mod flags_field split_t1 split_t2
16+
mpileup modstate pileup_mod flags_field split_t1 split_t2 \
17+
read_fast_i qtask_ordered qtask_unordered index_fasta
1718

1819
all: $(PRGS)
1920

20-
flags:
21+
flags: flags_demo.c
2122
$(CC) $(CFLAGS) -I $(HTS_DIR) flags_demo.c -o $@ $(LDFLAGS)
2223

23-
split:
24+
split: split.c
2425
$(CC) $(CFLAGS) -I $(HTS_DIR) split.c -o $@ $(LDFLAGS)
2526

26-
split2:
27+
split2: split2.c
2728
$(CC) $(CFLAGS) -I $(HTS_DIR) split2.c -o $@ $(LDFLAGS)
2829

29-
cram:
30+
cram: cram.c
3031
$(CC) $(CFLAGS) -I $(HTS_DIR) cram.c -o $@ $(LDFLAGS)
3132

32-
read_fast:
33+
read_fast: read_fast.c
3334
$(CC) $(CFLAGS) -I $(HTS_DIR) read_fast.c -o $@ $(LDFLAGS)
3435

35-
read_header:
36+
read_header: read_header.c
3637
$(CC) $(CFLAGS) -I $(HTS_DIR) read_header.c -o $@ $(LDFLAGS)
3738

38-
read_ref:
39+
read_ref: read_refname.c
3940
$(CC) $(CFLAGS) -I $(HTS_DIR) read_refname.c -o $@ $(LDFLAGS)
4041

41-
read_bam:
42+
read_bam: read_bam.c
4243
$(CC) $(CFLAGS) -I $(HTS_DIR) read_bam.c -o $@ $(LDFLAGS)
4344

44-
read_aux:
45+
read_aux: read_aux.c
4546
$(CC) $(CFLAGS) -I $(HTS_DIR) read_aux.c -o $@ $(LDFLAGS)
4647

47-
dump_aux:
48+
dump_aux: dump_aux.c
4849
$(CC) $(CFLAGS) -I $(HTS_DIR) dump_aux.c -o $@ $(LDFLAGS)
4950

50-
add_header:
51+
add_header: add_header.c
5152
$(CC) $(CFLAGS) -I $(HTS_DIR) add_header.c -o $@ $(LDFLAGS)
5253

53-
rem_header:
54+
rem_header: rem_header.c
5455
$(CC) $(CFLAGS) -I $(HTS_DIR) rem_header.c -o $@ $(LDFLAGS)
5556

56-
update_header:
57+
update_header: update_header.c
5758
$(CC) $(CFLAGS) -I $(HTS_DIR) update_header.c -o $@ $(LDFLAGS)
5859

59-
mod_bam:
60+
mod_bam: mod_bam.c
6061
$(CC) $(CFLAGS) -I $(HTS_DIR) mod_bam.c -o $@ $(LDFLAGS)
6162

62-
mod_aux:
63+
mod_aux: mod_aux.c
6364
$(CC) $(CFLAGS) -I $(HTS_DIR) mod_aux.c -o $@ $(LDFLAGS)
6465

65-
mod_aux_ba:
66+
mod_aux_ba: mod_aux_ba.c
6667
$(CC) $(CFLAGS) -I $(HTS_DIR) mod_aux_ba.c -o $@ $(LDFLAGS)
6768

68-
write_fast:
69+
write_fast: write_fast.c
6970
$(CC) $(CFLAGS) -I $(HTS_DIR) write_fast.c -o $@ $(LDFLAGS)
7071

71-
idx_on_write:
72+
idx_on_write: index_write.c
7273
$(CC) $(CFLAGS) -I $(HTS_DIR) index_write.c -o $@ $(LDFLAGS)
7374

74-
read_reg:
75+
read_reg: index_reg_read.c
7576
$(CC) $(CFLAGS) -I $(HTS_DIR) index_reg_read.c -o $@ $(LDFLAGS)
7677

77-
read_multireg:
78+
read_multireg: index_multireg_read.c
7879
$(CC) $(CFLAGS) -I $(HTS_DIR) index_multireg_read.c -o $@ $(LDFLAGS)
7980

80-
pileup:
81+
read_fast_i: read_fast_index.c
82+
$(CC) $(CFLAGS) -I $(HTS_DIR) read_fast_index.c -o $@ $(LDFLAGS)
83+
84+
pileup: pileup.c
8185
$(CC) $(CFLAGS) -I $(HTS_DIR) pileup.c -o $@ $(LDFLAGS)
8286

83-
mpileup:
87+
mpileup: mpileup.c
8488
$(CC) $(CFLAGS) -I $(HTS_DIR) mpileup.c -o $@ $(LDFLAGS)
8589

86-
modstate:
90+
modstate: modstate.c
8791
$(CC) $(CFLAGS) -I $(HTS_DIR) modstate.c -o $@ $(LDFLAGS)
8892

89-
pileup_mod:
93+
pileup_mod: pileup_mod.c
9094
$(CC) $(CFLAGS) -I $(HTS_DIR) pileup_mod.c -o $@ $(LDFLAGS)
9195

92-
flags_field:
96+
flags_field: flags_htsopt_field.c
9397
$(CC) $(CFLAGS) -I $(HTS_DIR) flags_htsopt_field.c -o $@ $(LDFLAGS)
9498

95-
split_t1:
99+
split_t1: split_thread1.c
96100
$(CC) $(CFLAGS) -I $(HTS_DIR) split_thread1.c -o $@ $(LDFLAGS)
97101

98-
split_t2:
102+
split_t2: split_thread2.c
99103
$(CC) $(CFLAGS) -I $(HTS_DIR) split_thread2.c -o $@ $(LDFLAGS)
100104

105+
index_fasta: index_fasta.c
106+
$(CC) $(CFLAGS) -I $(HTS_DIR) index_fasta.c -o $@ $(LDFLAGS)
107+
108+
qtask_ordered: qtask_ordered.c
109+
$(CC) $(CFLAGS) -I $(HTS_DIR) qtask_ordered.c -o $@ $(LDFLAGS)
110+
111+
qtask_unordered: qtask_unordered.c
112+
$(CC) $(CFLAGS) -I $(HTS_DIR) qtask_unordered.c -o $@ $(LDFLAGS)
113+
101114
clean:
102115
find . -name "*.o" | xargs rm -rf
103116
find . -name "*.dSYM" | xargs rm -rf

Diff for: samples/README.md

+33-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ data, and is the core library used by [samtools][2] and [bcftools][3].
44

55
A set of sample programs are available which showcases the usage of APIs in HTSlib.
66
They are based on version 1.17 of HTSLib and are mainly for demonstration of API usage.
7-
Further optimization and error handling might be required for actual usage.
7+
Further optimisation and error handling might be required for actual usage.
88

99

1010
[1]: http://samtools.github.io/hts-specs/
@@ -61,7 +61,7 @@ indexed.
6161

6262
[Read_fast][Read_fast]
6363

64-
This application showcases the fasta/fastq data read.
64+
This application showcases fasta/fastq data read without using index.
6565

6666
[Read_header][Read_header]
6767

@@ -72,7 +72,7 @@ indexed.
7272
[Read_ref][Read_ref]
7373

7474
This application showcases the read and access of header data. It shows
75-
all reference names which has length equal or greather to given input.
75+
all reference names which has length equal or greater to given input.
7676

7777
[Read_bam][Read_bam]
7878

@@ -129,24 +129,33 @@ indexed.
129129

130130
[Write_fast][Write_fast]
131131

132-
This application showcases the fasta/fastq data write. It appends a dummy
133-
data to given file.
132+
This application showcases the fasta/fastq data write. It appends data on
133+
given file.
134134

135135
[Index_write][Index_write]
136136

137137
This application showcases the creation of index along with output
138138
creation. Based on file type and shift, it creates bai, csi or crai files.
139139

140+
[Index_fast][Index_fast]
141+
142+
This application showcases index creation on fasta/fastq reference data.
143+
140144
[Read_reg][Read_reg]:
141145

142146
This application showcases the usage of region specification in alignment
143147
read.
144148

145149
[Read_multireg][Read_multireg]:
146150

147-
This application showcases the usage of mulitple region specification in
151+
This application showcases the usage of multiple region specification in
148152
alignment read.
149153

154+
[Read_fast_index][Read_fast_index]
155+
156+
This application showcases the fasta/fastq data read using index. It takes a
157+
region (reference name[:start-end]) and gets data from that region.
158+
150159
[Pileup][Pileup]:
151160

152161
This application showcases the pileup api, where all alignments covering a
@@ -181,8 +190,7 @@ indexed.
181190

182191
This application showcases the use of threads in file handling. It saves
183192
the read1 and read2 as separate files in given directory, one as sam and
184-
other as bam. 2 threads are used for read and 1 each dedicated for each
185-
output file.
193+
other as bam. 1 thread is used for read, 1 for sam write and 2 for bam write.
186194

187195
[Split_thread2][Split_thread2]
188196

@@ -191,6 +199,19 @@ indexed.
191199
and other as bam. A pool of 4 threads is created and shared for both read
192200
and write.
193201

202+
[Qtask_ordered][Qtask_ordered]
203+
204+
This application showcases the use of queues and threads for custom
205+
processing. Alignments in input file are updated with their GC ratio on a
206+
custom aux tag. The processing may occur in any order but the results are
207+
retrieved in same order as it was queued and saved to disk.
208+
209+
[Qtask_unordered][Qtask_unordered]
210+
211+
This application showcases the use of queues and threads for custom
212+
processing. The count of bases and GC ratio are calculated and displayed.
213+
The order of counting is irrelevant and hence ordered retrieval is not used.
214+
194215
### More Information
195216

196217
More detailed documentation is available in the [DEMO.md][DEMO] with worked
@@ -215,13 +236,17 @@ examples per demonstration tool.
215236
[Mod_aux_ba]: mod_aux_ba.c
216237
[Write_fast]: write_fast.c
217238
[Index_write]: index_write.c
239+
[Index_fasta]: index_fasta.c
218240
[Read_reg]: index_reg_read.c
219241
[Read_multireg]: index_multireg_read.c
242+
[Read_fast_index]: read_fast_index.c
220243
[Pileup]: pileup.c
221244
[Mpileup]: mpileup.c
222245
[Modstate]: modstate.c
223246
[Pileup_mod]: pileup_mod.c
224247
[Flags_field]: flags_htsopt_field.c
225248
[Split_thread1]: split_thread1.c
226249
[Split_thread2]: split_thread2.c
250+
[Qtask_ordered]: qtask_ordered.c
251+
[Qtask_unordered]: qtask_unordered.c
227252
[DEMO]: DEMO.md

Diff for: samples/add_header.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ DEALINGS IN THE SOFTWARE
2424
2525
*/
2626

27-
/* The pupose of this code is to demonstrate the library apis and need proper error handling and optimization */
27+
/* The purpose of this code is to demonstrate the library apis and need proper error handling and optimisation */
2828

2929
#include <getopt.h>
3030
#include <unistd.h>
3131
#include <htslib/sam.h>
3232

33-
/// print_usage - print the demo_usage
34-
/** @param fp pointer to the file / terminal to which demo_usage to be dumped
33+
/// print_usage - print the usage
34+
/** @param fp pointer to the file / terminal to which usage to be dumped
3535
returns nothing
3636
*/
3737
static void print_usage(FILE *fp)
3838
{
3939
fprintf(fp, "Usage: add_header infile\n\
40-
Adds new header lines of SQ, RG, PG and CO typs\n");
40+
Adds new header lines of SQ, RG, PG and CO types\n");
4141
return;
4242
}
4343

Diff for: samples/cram.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ DEALINGS IN THE SOFTWARE
2424
2525
*/
2626

27-
/* The pupose of this code is to demonstrate the library apis and need proper error handling and optimization */
27+
/* The purpose of this code is to demonstrate the library apis and need proper error handling and optimisation */
2828

2929
#include <getopt.h>
3030
#include <unistd.h>
3131
#include <htslib/sam.h>
3232

33-
/// print_usage - print the demo_usage
34-
/** @param fp pointer to the file / terminal to which demo_usage to be dumped
33+
/// print_usage - print the usage
34+
/** @param fp pointer to the file / terminal to which usage to be dumped
3535
returns nothing
3636
*/
3737
static void print_usage(FILE *fp)

Diff for: samples/dump_aux.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ DEALINGS IN THE SOFTWARE
2424
2525
*/
2626

27-
/* The pupose of this code is to demonstrate the library apis and need proper error handling and optimization */
27+
/* The purpose of this code is to demonstrate the library apis and need proper error handling and optimisation */
2828

2929
#include <getopt.h>
3030
#include <unistd.h>
3131
#include <htslib/sam.h>
3232

33-
/// print_usage - print the demo_usage
34-
/** @param fp pointer to the file / terminal to which demo_usage to be dumped
33+
/// print_usage - print the usage
34+
/** @param fp pointer to the file / terminal to which usage to be dumped
3535
returns nothing
3636
*/
3737
static void print_usage(FILE *fp)
@@ -92,7 +92,7 @@ int printauxdata(FILE *fp, char type, int32_t idx, const uint8_t *data)
9292
fprintf(fp, "%c", auxBType);
9393
for (i = 0; i < auxBcnt; ++i) { //iterate the array
9494
fprintf(fp, ",");
95-
//calling recurssively with index to reuse a few lines
95+
//calling recursively with index to reuse a few lines
9696
if (printauxdata(fp, auxBType, i, data) == EXIT_FAILURE) {
9797
return EXIT_FAILURE;
9898
}

Diff for: samples/flags_demo.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ DEALINGS IN THE SOFTWARE
2424
2525
*/
2626

27-
/* The pupose of this code is to demonstrate the library apis and need proper error handling and optimization */
27+
/* The purpose of this code is to demonstrate the library apis and need proper error handling and optimisation */
2828

2929
#include <getopt.h>
3030
#include <unistd.h>
3131
#include <htslib/sam.h>
3232

33-
/// print_usage - show flags_demo usage
34-
/** @param fp pointer to the file / terminal to which demo_usage to be dumped
33+
/// print_usage - show usage
34+
/** @param fp pointer to the file / terminal to which usage to be dumped
3535
returns nothing
3636
*/
3737
static void print_usage(FILE *fp)

Diff for: samples/flags_htsopt_field.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ DEALINGS IN THE SOFTWARE
2424
2525
*/
2626

27-
/* The pupose of this code is to demonstrate the library apis and need proper error handling and optimization */
27+
/* The purpose of this code is to demonstrate the library apis and need proper error handling and optimisation */
2828

2929
#include <getopt.h>
3030
#include <unistd.h>
3131
#include <htslib/sam.h>
3232

33-
/// print_usage - show flags_demo usage
34-
/** @param fp pointer to the file / terminal to which demo_usage to be dumped
33+
/// print_usage - show usage
34+
/** @param fp pointer to the file / terminal to which usage to be dumped
3535
returns nothing
3636
*/
3737
static void print_usage(FILE *fp)

0 commit comments

Comments
 (0)