-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.R
executable file
·58 lines (43 loc) · 1.25 KB
/
example.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
library(rslow5)
##################################################################
# open a S/BLOW5 file
file <- rslow5_open("inst/extdata/example.slow5")
# print the header
hdr <- rslow5_header(file)
print(hdr)
###### sequential access ######
while (TRUE) {
slow5 <- rslow5_get_next(file)
if (length(slow5$read_id) == 0) {
break
}
print(head(slow5,n=7)) #primary fields except raw signal
}
###### random access ######
#load the index
rslow5_idx_load(file)
# get readIDs r1,r3, r5
rid <- c("r1", "r3", "r5")
slow5 <- rslow5_get(file, rid)
print(head(slow5,n=7))
# now get read IDs r2 and r1
rid <- c("r2", "r1")
slow5 <- rslow5_get(file, rid)
print(head(slow5,n=7))
# unload the index at the end
rslow5_idx_unload(file)
##################################################################
# Open a different S/BLOW5 file
file <- rslow5_open("inst/extdata/example2.slow5")
# get the header
hdr <- rslow5_header(file)
print(hdr)
# sequentially read, this time with two threads and a batch size of 2
while (TRUE) {
slow5 <- rslow5_get_next(file, num_thread = 2, batch_size = 2)
if (length(slow5$read_id) == 0) {
break
}
print(tail(slow5,n=5)) #aux fields
}
##################################################################