1 /* $Id: iit-read.h 222139 2020-03-13 00:15:01Z twu $ */
2 #ifndef IIT_READ_INCLUDED
3 #define IIT_READ_INCLUDED
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>		/* For HAVE_64_BIT */
6 #endif
7 
8 #include <stdio.h>
9 #include "bool.h"
10 #include "uintlist.h"
11 #include "intlist.h"
12 #include "list.h"
13 #include "interval.h"
14 #include "types.h"
15 #include "iitdef.h"
16 #include "filestring.h"
17 
18 
19 typedef enum {READ_ALL, READ_ONE, READ_NONE} Divread_T;
20 /* READ_NONE is useful if we want to obtain an interval by name,
21    rather than by coordinate */
22 
23 typedef enum {NO_KNOWN_GENE, KNOWN_GENE, KNOWN_GENE_MULTIEXON} Overlap_T;
24 
25 
26 #define T IIT_T
27 
28 extern bool
29 IIT_universalp (char *filename, bool add_iit_p);
30 extern bool
31 IIT_valuep (T this);
32 extern char *
33 IIT_name (T this);
34 extern int
35 IIT_version (T this);
36 extern int
37 IIT_total_nintervals (T this);
38 extern int
39 IIT_nintervals (T this, int divno);
40 extern int
41 IIT_ntypes (T this);
42 extern int
43 IIT_nfields (T this);
44 
45 extern Chrpos_T
46 IIT_length (T this, int index);
47 extern Chrpos_T
48 IIT_divlength (T this, char *divstring);
49 extern Chrpos_T
50 IIT_totallength (T this);
51 extern Interval_T
52 IIT_interval (T this, int index);
53 extern Interval_T
54 IIT_interval_for_divno (T this, int divno, int index);
55 extern Chrpos_T
56 IIT_interval_low (T this, int index);
57 extern Chrpos_T
58 IIT_interval_high (T this, int index);
59 extern Chrpos_T
60 IIT_interval_length (T this, int index);
61 extern int
62 IIT_interval_type (T this, int index);
63 extern int
64 IIT_interval_sign (T this, int index);
65 extern void
66 IIT_interval_bounds (Chrpos_T *low, Chrpos_T *high, Chrpos_T *length, T this,
67 		     int index, int circular_typeint);
68 extern int
69 IIT_index (T this, int divno, int i);
70 
71 extern int
72 IIT_ndivs (T this);
73 extern char *
74 IIT_divstring (T this, int divno);
75 extern int
76 IIT_divint (T this, char *divstring);
77 extern char *
78 IIT_divstring_from_index (T this, int index);
79 extern char *
80 IIT_typestring (T this, int type);
81 extern int
82 IIT_typeint (T this, char *typestring);
83 extern char *
84 IIT_fieldstring (T this, int fieldint);
85 extern char *
86 IIT_label (T this, int index, bool *allocp);
87 extern char *
88 IIT_annotation (char **restofheader, T this, int index, bool *alloc_header_p);
89 extern char
90 IIT_annotation_firstchar (T this, int index);
91 extern
92 #ifdef HAVE_64_BIT
93 UINT8
94 #else
95 UINT4
96 #endif
97 IIT_annotation_strlen (T this, int index);
98 extern char *
99 IIT_fieldvalue (T this, int index, int fieldint);
100 extern int
101 IIT_fieldint (T this, char *fieldstring);
102 
103 extern void
104 IIT_debug (char *filename);
105 extern void
106 IIT_dump_divstrings (FILE *fp, T this);
107 extern void
108 IIT_dump_typestrings (FILE *fp, T this);
109 extern void
110 IIT_dump_fieldstrings (FILE *fp, T this);
111 extern void
112 IIT_dump_labels (FILE *fp, T this);
113 extern void
114 IIT_dump (T this, bool sortp);
115 extern void
116 IIT_dump_simple (T this);
117 extern void
118 IIT_dump_formatted (T this, bool directionalp);
119 extern Chrpos_T *
120 IIT_transitions (int **signs, int *nedges, T this);
121 extern Chrpos_T *
122 IIT_transitions_subset (int **signs, int *nedges, T this, int *indices, int nindices);
123 extern void
124 IIT_dump_counts (T this, bool alphabetizep);
125 
126 extern void
127 IIT_free (T *old);
128 extern int
129 IIT_read_divint (char *filename, char *divstring, bool add_iit_p);
130 
131 /* Same as IIT_read, but can handle a region of memory, instead of a file */
132 extern T
133 IIT_load (char *memory, char *name);
134 
135 extern T
136 /* add_iit_p means to add the ".iit" suffix to the filename */
137 IIT_read (char *filename, char *name, bool readonlyp, Divread_T divread, char *divstring,
138 	  bool add_iit_p);
139 
140 extern int *
141 IIT_find (int *nmatches, T this, char *label);
142 extern int
143 IIT_find_linear (T this, char *label);
144 extern int
145 IIT_find_one (T this, char *label);
146 
147 extern Chrpos_T *
148 IIT_get_highs_for_low (int *nuniq, T this, int divno, Chrpos_T x);
149 extern Chrpos_T *
150 IIT_get_lows_for_high (int *nuniq, T this, int divno, Chrpos_T x);
151 extern bool
152 IIT_low_exists_signed_p (T this, int divno, Chrpos_T x, int sign);
153 extern bool
154 IIT_high_exists_signed_p (T this, int divno, Chrpos_T x, int sign);
155 extern int *
156 IIT_get_lows_signed (int *nmatches, T this, int divno, Chrpos_T x, Chrpos_T y, int sign);
157 extern int *
158 IIT_get_highs_signed (int *nmatches, T this, int divno, Chrpos_T x, Chrpos_T y, int sign);
159 
160 extern int *
161 IIT_get (int *nmatches, T this, char *divstring, Chrpos_T x, Chrpos_T y, bool sortp);
162 extern int *
163 IIT_get_signed (int *nmatches, T this, char *divstring, Chrpos_T x, Chrpos_T y, int sign, bool sortp);
164 extern bool
165 IIT_exists_with_divno (T this, int divno, Chrpos_T x, Chrpos_T y);
166 extern bool
167 IIT_exists_with_divno_signed (T this, int divno, Chrpos_T x, Chrpos_T y, int sign);
168 extern bool
169 IIT_exists_with_divno_typed_signed (T this, int divno, Chrpos_T x, Chrpos_T y, int type, int sign);
170 extern int *
171 IIT_get_with_divno (int *nmatches, T this, int divno, Chrpos_T x, Chrpos_T y, bool sortp);
172 extern int *
173 IIT_get_signed_with_divno (int *nmatches, T this, int divno, Chrpos_T x, Chrpos_T y, bool sortp,
174 			   int sign);
175 extern int
176 IIT_get_next (T this, int divno, Chrpos_T y);
177 extern void
178 IIT_get_flanking (int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks,
179 		  T this, char *divstring, Chrpos_T x, Chrpos_T y, int nflanking, int sign);
180 extern void
181 IIT_get_flanking_with_divno (int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks,
182 			     T this, int divno, Chrpos_T x, Chrpos_T y, int nflanking, int sign);
183 extern void
184 IIT_get_flanking_typed (int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks,
185 			T this, char *divstring, Chrpos_T x, Chrpos_T y, int nflanking, int type,
186 			int sign);
187 extern void
188 IIT_get_flanking_multiple_typed (int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks,
189 				 T this, char *divstring, Chrpos_T x, Chrpos_T y, int nflanking, int *types, int ntypes);
190 extern int
191 IIT_get_one (T this, char *divstring, Chrpos_T x, Chrpos_T y);
192 extern int *
193 IIT_get_typed (int *ntypematches, T this, char *divstring, Chrpos_T x, Chrpos_T y, int type, bool sortp);
194 extern int *
195 IIT_get_typed_with_divno (int *ntypematches, T this, int divno, Chrpos_T x, Chrpos_T y, int type, bool sortp);
196 extern int *
197 IIT_get_typed_signed (int *ntypematches, T this, char *divstring, Chrpos_T x, Chrpos_T y,
198 		      int type, int sign, bool sortp);
199 extern int *
200 IIT_get_typed_signed_with_divno (int *ntypematches, T this, int divno, Chrpos_T x, Chrpos_T y,
201 				 int type, int sign, bool sortp);
202 extern int *
203 IIT_get_multiple_typed (int *ntypematches, T this, char *divstring, Chrpos_T x, Chrpos_T y,
204 			int *types, int ntypes, bool sortp);
205 extern int
206 IIT_get_exact (T this, char *divstring, Chrpos_T x, Chrpos_T y, int type);
207 extern bool
208 IIT_exact_p (T this, char *divstring, Chrpos_T x, Chrpos_T y, int type);
209 extern int *
210 IIT_get_exact_multiple (int *nmatches, T this, char *divstring, Chrpos_T x, Chrpos_T y, int type);
211 
212 extern int *
213 IIT_get_values_between (int *nmatches, T this, double lowval, double highval);
214 extern int *
215 IIT_get_values_below (int *nmatches, T this, double highval);
216 extern int *
217 IIT_get_values_above (int *nmatches, T this, double lowval);
218 
219 extern List_T
220 IIT_intervallist_typed (List_T *labellist, Uintlist_T *seglength_list, T this);
221 extern List_T
222 IIT_typelist (T this);
223 
224 extern void
225 IIT_print_header (Filestring_T fp, T this, int *matches, int nmatches,
226 		  char *chr, bool reversep, bool relativep, Chrpos_T left, bool print_comment_p);
227 
228 extern Intlist_T
229 IIT_gene_exons_plus (int *chrnum, Uintlist_T *exonstarts, T genes_iit,
230 		     int *genes_chrnum_crosstable, int index);
231 extern Intlist_T
232 IIT_gene_exons_minus (int *chrnum, Uintlist_T *exonstarts, T genes_iit,
233 		      int *genes_chrnum_crosstable, int index);
234 extern int
235 IIT_gene_exons_array (int *transcript_genestrand, int **exonbounds, unsigned int **exonstarts,
236 		      T alignment_iit, int alignment_index);
237 
238 extern Overlap_T
239 IIT_gene_overlap (T map_iit, int divno, Chrpos_T x, Chrpos_T y, bool favor_multiexon_p);
240 extern bool
241 IIT_gene_overlapp (T map_iit, int index, Chrpos_T x, Chrpos_T y);
242 
243 extern Chrpos_T
244 IIT_genestruct_chrpos (char *strand, char **divstring, char **gene,
245 		       T map_iit, char *transcript, int querypos);
246 
247 extern Intlist_T
248 IIT_unique_positions (T map_iit, int index0, int divno);
249 extern Intlist_T
250 IIT_unique_positions_given_others (T map_iit, int index0, int *matches, int nmatches);
251 extern Intlist_T
252 IIT_unique_splicep (T map_iit, int index0, int divno);
253 extern Intlist_T
254 IIT_unique_splicep_given_others (T map_iit, int index0, int *matches, int nmatches);
255 
256 
257 #undef T
258 #endif
259