forked from samtools/bcftools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ploidy.h
129 lines (103 loc) · 4.31 KB
/
ploidy.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
127
128
/*
Copyright (C) 2014 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Lookup from region and sex to ploidy.
Example of usage:
int default_ploidy = 2;
ploidy_t *pld = ploidy_init(fname, default_ploidy);
int nsex = ploidy_nsex(pld);
int *sex2ploidy = malloc(sizeof(int)*nsex);
ploidy_query(pld, "X",60000, sex2ploidy, NULL, NULL);
for (i=0; i<nsex; i++)
printf("ploidy of %s is %d\n", ploidy_id2sex(pld,i), sex2ploidy[i]);
ploidy_destroy(pld);
An example of ploidy file format follows. The coordinates are 1-based and
inclusive. The "*" records define the default ploidy for each sex. If not
present, the default_ploidy passed to ploidy_init is used instead:
X 1 60000 M 1
X 2699521 154931043 M 1
Y 1 59373566 M 1
Y 1 59373566 F 0
MT 1 16569 M 1
MT 1 16569 F 1
* * * M 2
* * * F 2
*/
#ifndef __PLOIDY_H__
#define __PLOIDY_H__
#include <htslib/regidx.h>
typedef struct _ploidy_t ploidy_t;
/*
* ploidy_init()
* @param fname: input file name or NULL if default ploidy from example above should be used
* @param dflt: default ploidy to use for unlisted regions (the '* * *' records have precedence).
*
* Returns new structure on success or NULL on error.
*/
ploidy_t *ploidy_init(const char *fname, int dflt);
/* Same as ploidy_init() but the whole file is passed as a single string */
ploidy_t *ploidy_init_string(const char *str, int dflt);
/*
* ploidy_destroy() - free memory allocated by ploidy_init
*/
void ploidy_destroy(ploidy_t *ploidy);
/*
* ploidy_query() - query ploidy at a position for all genders at once
* @param seq: chromosome name
* @param pos: 0-based position
* @param sex2ploidy: if not NULL, array will be filled with mapping from sex id to ploidy
* @param min: if not NULL, minimum encountered encountered will be set
* @param max: if not NULL, maximum encountered encountered will be set
*
* Returns 1 if the position is listed in the regions or 0 otherwise.
*/
int ploidy_query(ploidy_t *ploidy, char *seq, int pos, int *sex2ploidy, int *min, int *max);
/*
* ploidy_nsex() - return number of recognised genders
*/
int ploidy_nsex(ploidy_t *ploidy);
/*
* ploidy_id2sex() - mapping between numeric gender id and name
*
* Returns gender name (e.g. "M" or "F" in the example above)
* or NULL if there is no such id.
*/
char *ploidy_id2sex(ploidy_t *ploidy, int id);
/*
* ploidy_sex2id() - mapping between gender name and its numeric id
*
* Returns numeric id or -1 if not present.
*/
int ploidy_sex2id(ploidy_t *ploidy, char *sex);
/*
* ploidy_add_sex() - register new gender name. This function is
* useful when gender has the default ploidy for all regions
* and is not listed in the file passed to ploidy_init()
*
* Returns numeric id of the added sex, regardless of whether the string was
* newly added or was already present in the dictionary.
*/
int ploidy_add_sex(ploidy_t *ploidy, const char *sex);
/** Returns region index for raw access */
regidx_t *ploidy_regions(ploidy_t *ploidy);
/** Return the minimum / maximum recognised ploidy */
int ploidy_max(ploidy_t *ploidy);
int ploidy_min(ploidy_t *ploidy);
#endif