-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfile.h
126 lines (111 loc) · 4.32 KB
/
cfile.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef _CFILE_H
#define _CFILE_H
#include "cdata.h"
#include "snames.h"
#include "index.h"
/* cfile for reading, see cdata_write for writing */
typedef struct cfile_t {
BGZF *fh;
int n; /* number of samples read */
} cfile_t;
/**
* Opens a file and returns a cfile_t instance.
* If the filename is "-", it will open stdin for reading. Otherwise, it opens the named file.
* On any error opening the file, the program will exit.
*
* @param fname The name of the file to open.
* @return A cfile_t instance that represents the opened file.
*/
cfile_t open_cfile(char *fname);
/**
* Reads cdata from a cfile_t instance.
*
* @param cf The cfile_t instance to read from.
* @return A cdata_t instance with the data read from the file.
*/
cdata_t read_cdata1(cfile_t *cf);
/**
* Reads a cdata_t instance from a cfile_t instance.
* This function is a lower-level utility for reading compressed data from a file.
* c memory will be reallocated.
*
* @param cf The cfile_t instance to read from.
* @param c The cdata_t instance to store the read data into.
* @return 1 if the read operation was successful and there was data to read, 0 if there was no data to read.
*/
int read_cdata2(cfile_t *cf, cdata_t *c);
DEFINE_VECTOR(cdata_v, cdata_t)
/**
* Reads cdata from a specified range in a cfile_t instance.
* If "end" is smaller than "beg", the program will exit with an error.
*
* @param cf The cfile_t instance to read from.
* @param beg The beginning of the range to read from.
* @param end The end of the range to read from.
* @return A cdata_v instance with the data read from the file.
*/
cdata_v* read_cdata(cfile_t *cf, int64_t beg, int64_t end);
/**
* Reads all cdata from a cfile_t instance. This function can be memory intensive if there are many samples.
*
* @param cf The cfile_t instance to read from.
* @return A cdata_v instance with all the data read from the file.
*/
cdata_v* read_cdata_all(cfile_t *cf);
/**
* Reads the first n cdata from a cfile_t instance.
*
* @param cf The cfile_t instance to read from.
* @param n The number of cdata to read from the head of the file.
* @return A cdata_v instance with the data read from the file.
*/
cdata_v* read_cdata_from_head(cfile_t *cf, int64_t n);
/**
* Reads the last n cdata from a cfile_t instance.
*
* @param cf The cfile_t instance to read from.
* @param idx The index of the data to read.
* @param n The number of cdata to read from the tail of the file.
* @return A cdata_v instance with the data read from the file.
*/
cdata_v* read_cdata_from_tail(cfile_t *cf, index_t *idx, int64_t n);
/**
* Reads cdata from a cfile_t instance at specified indices.
*
* @param cf The cfile_t instance to read from.
* @param indices The indices of the data to read.
* @param n The number of cdata to read.
* @return A cdata_v instance with the data read from the file.
*/
cdata_v* read_cdata_with_indices(cfile_t *cf, const int64_t* indices, int n);
/**
* Reads cdata from a cfile_t instance with specified sample names.
* If any sample name is not found in the index, the program will exit with an error.
*
* @param cf The cfile_t instance to read from.
* @param idx The index of the data to read.
* @param snames The sample names to read.
* @return A cdata_v instance with the data read from the file.
*/
cdata_v* read_cdata_with_snames(cfile_t *cf, index_t *idx, snames_t *snames);
/**
* Writes a cdata_t instance to a BGZF file stream.
*
* This function takes a pointer to a BGZF file stream and a cdata_t instance,
* and writes the data from the cdata_t instance to the BGZF file stream.
* The data is expected to be in a specific format, matching the structure of the cdata_t type.
*
* @param fp A pointer to the BGZF file stream to write to.
* @param c A pointer to the cdata_t instance to be written.
*/
void cdata_write1(BGZF *fp, cdata_t *c);
/**
* Writes the cdata to the specified file.
*
* @param fname_out The name of the output file. If NULL, output to stdout.
* @param c The cdata_t instance to write to the file.
* @param mode The mode to open the file. This should be either "w" for write mode or "a" for append mode.
* @param verbose A flag to control verbosity. If non-zero, additional information will be printed during the write process.
*/
void cdata_write(char *fname_out, cdata_t *c, const char *mode, int verbose);
#endif