Debian Codegraph @

inc/core/AgnLocus.h

raw
1 /**
2
3 Copyright (c) 2010-2014, Daniel S. Standage and CONTRIBUTORS
4
5 The AEGeAn Toolkit is distributed under the ISC License. See
6 the 'LICENSE' file in the AEGeAn source code distribution or
7 online at https://github.com/standage/AEGeAn/blob/master/LICENSE.
8
9 **/
10 #ifndef AEGEAN_LOCUS
11 #define AEGEAN_LOCUS
12
13 #include "annotationsketch/block_api.h"
14 #include "core/array_api.h"
15 #include "extended/feature_node_api.h"
16 #include "AgnCliquePair.h"
17
18 /**
19 * @class AgnLocus
20 *
21 * The AgnLocus class represents gene loci and interval loci in memory and can
22 * be used to facilitate comparison of two different sources of annotation.
23 * Under the hood, each ``AgnLocus`` object is a feature node with one or more
24 * gene features as direct children.
25 */
26 typedef GtGenomeNode AgnLocus;
27
28 /**
29 * @type When tracking the source of an annotation for comparison purposes, use
30 * this enumerated type to refer to reference (``REFERENCESOURCE``) vs
31 * prediction (``PREDICTIONSOURCE``) annotations. ``DEFAULTSOURCE`` is for when
32 * the source is not a concern.
33 */
34 enum AgnComparisonSource
35 {
36 REFERENCESOURCE,
37 PREDICTIONSOURCE,
38 DEFAULTSOURCE
39 };
40 typedef enum AgnComparisonSource AgnComparisonSource;
41
42 /**
43 * @type This data structure provides a convenient container for metadata needed
44 * to produce a PNG graphic for pairwise comparison
45 * loci.
46 */
47 struct AgnLocusPngMetadata
48 {
49 char filename_template[512];
50 char stylefile[512];
51 const char *refrfile;
52 const char *predfile;
53 const char *refrlabel;
54 const char *predlabel;
55 };
56 typedef struct AgnLocusPngMetadata AgnLocusPngMetadata;
57
58 /**
59 * @type Comparison operators to use when filtering loci.
60 */
61 enum AgnLocusFilterOp
62 {
63 AGN_LOCUS_FILTER_EQ,
64 AGN_LOCUS_FILTER_NE,
65 AGN_LOCUS_FILTER_GT,
66 AGN_LOCUS_FILTER_GE,
67 AGN_LOCUS_FILTER_LT,
68 AGN_LOCUS_FILTER_LE,
69 AGN_LOCUS_FILTER_NO, // no-op
70 };
71 typedef enum AgnLocusFilterOp AgnLocusFilterOp;
72
73 /**
74 * @type Data by which to filter a locus. If the value returned by ``function``
75 * satisfies the criterion specified by ``testvalue`` and ``operator``, then
76 * the locus is to be kept.
77 */
78 struct AgnLocusFilter
79 {
80 GtUword (*function) (AgnLocus *, AgnComparisonSource);
81 GtUword testvalue;
82 AgnLocusFilterOp operator;
83 AgnComparisonSource src;
84 };
85 typedef struct AgnLocusFilter AgnLocusFilter;
86
87 /**
88 * @function Associate the given annotation with this locus. Rather
89 * than calling this function directly, users are recommended to use one of the
90 * following macros: ``agn_locus_add_pred_feature(locus, gene)`` and
91 * ``agn_locus_add_refr_feature(locus, gene)``, to be used when keeping
92 * track of an annotation's source is important (i.e. for pairwise comparison);
93 * and ``agn_locus_add_feature(locus, gene)`` otherwise.
94 */
95 void agn_locus_add(AgnLocus *locus, GtFeatureNode *feature,
96 AgnComparisonSource source);
97 #define agn_locus_add_pred_feature(LC, GN)\
98 agn_locus_add(LC, GN, PREDICTIONSOURCE)
99 #define agn_locus_add_refr_feature(LC, GN)\
100 agn_locus_add(LC, GN, REFERENCESOURCE)
101 #define agn_locus_add_feature(LC, GN)\
102 agn_locus_add(LC, GN, DEFAULTSOURCE)
103
104 /**
105 * @function Do a semi-shallow copy of this data structure--for members whose
106 * data types support reference counting, the same pointer is used and the
107 * reference is incremented. For the other members a new object is created and
108 * populated with the same content.
109 */
110 AgnLocus *agn_locus_clone(AgnLocus *locus);
111
112 /**
113 * @function The combined length of all coding sequences associated with this
114 * locus. Rather than calling this function directly, users are encouraged to
115 * use one of the following macros: ``agn_locus_refr_cds_length(locus)``
116 * for the combined length of all reference CDSs,
117 * ``agn_locus_pred_cds_length(locus)`` for the combined length of all
118 * prediction CDSs, and ``agn_locus_get_cds_length(locus)`` for the
119 * combined length of all CDSs.
120 */
121 GtUword agn_locus_cds_length(AgnLocus *locus, AgnComparisonSource src);
122 #define agn_locus_pred_cds_length(LC)\
123 agn_locus_cds_length(LC, PREDICTIONSOURCE)
124 #define agn_locus_refr_cds_length(LC)\
125 agn_locus_cds_length(LC, REFERENCESOURCE)
126 #define agn_locus_get_cds_length(LC)\
127 agn_locus_cds_length(LC, DEFAULTSOURCE)
128
129 /**
130 * @function Compare every reference transcript clique with every prediction
131 * transcript clique. For gene loci with multiple transcript cliques, each
132 * comparison is not necessarily reported. Instead, we report the set of clique
133 * pairs that provides the optimal pairing of reference and prediction
134 * transcripts. If there are more reference transcript cliques than prediction
135 * cliques (or vice versa), these unmatched cliques are reported separately.
136 */
137 void agn_locus_comparative_analysis(AgnLocus *locus, GtLogger *logger);
138
139 /**
140 * @function Analog of ``strcmp`` for sorting AgnLocus objects. Loci are first
141 * sorted lexicographically by sequence ID, and then spatially by genomic
142 * coordinates.
143 */
144 int agn_locus_array_compare(const void *p1, const void *p2);
145
146 /**
147 * @function Add this locus' internal comparison stats to a larger set of
148 * aggregate stats.
149 */
150 void agn_locus_comparison_aggregate(AgnLocus *locus, AgnComparison *comp);
151
152 /**
153 * @function Add this locus' internal comparison stats to a larger set of
154 * aggregate stats.
155 */
156 void agn_locus_data_aggregate(AgnLocus *locus, AgnComparisonData *data);
157
158 /**
159 * @function Class destructor.
160 */
161 void agn_locus_delete(AgnLocus *locus);
162
163 /**
164 * @function Get the number of exons for the locus. Rather than calling this
165 * function directly, users are encouraged to use one of the following macros:
166 * ``agn_locus_num_pred_exons(locus)`` for the number of prediction exons,
167 * ``agn_locus_num_refr_exons(locus)`` for the number of reference exons,
168 * or ``agn_locus_num_exons(locus)`` if the source of annotation is
169 * undesignated or irrelevant.
170 */
171 GtUword agn_locus_exon_num(AgnLocus *locus, AgnComparisonSource src);
172 #define agn_locus_num_pred_exons(LC)\
173 agn_locus_exon_num(LC, PREDICTIONSOURCE)
174 #define agn_locus_num_refr_exons(LC)\
175 agn_locus_exon_num(LC, REFERENCESOURCE)
176 #define agn_locus_num_exons(LC)\
177 agn_locus_exon_num(LC, DEFAULTSOURCE)
178
179 /**
180 * @function Parse filters from ``filterfile`` and place ``AgnLocusFilter``
181 * objects in ``filters``.
182 */
183 void agn_locus_filter_parse(FILE *filterfile, GtArray *filters);
184
185 /**
186 * @function Return true if ``locus`` satisfies the given filtering
187 * criterion.
188 */
189 bool agn_locus_filter_test(AgnLocus *locus, AgnLocusFilter *filter);
190
191
192 /**
193 * @function Return an array of the locus' top-level children, regardless of
194 * their type.
195 */
196 GtArray *agn_locus_get(AgnLocus *locus);
197
198 /**
199 * @function Get a list of all the prediction transcript cliques that have no
200 * corresponding reference transcript clique.
201 */
202 GtArray *agn_locus_get_unique_pred_cliques(AgnLocus *locus);
203
204 /**
205 * @function Get a list of all the reference transcript cliques that have no
206 * corresponding prediction transcript clique.
207 */
208 GtArray *agn_locus_get_unique_refr_cliques(AgnLocus *locus);
209
210 /**
211 * @function Get the genes associated with this locus. Rather than calling
212 * this function directly, users are encouraged to use one of the following
213 * macros: ``agn_locus_pred_genes(locus)`` to retrieve prediction genes,
214 * ``agn_locus_refr_genes(locus)`` to retrieve reference genes, or
215 * ``agn_locus_get_genes(locus)`` if the source of annotation is undesignated or
216 * irrelevant.
217 */
218 GtArray *agn_locus_genes(AgnLocus *locus, AgnComparisonSource src);
219 #define agn_locus_pred_genes(LC)\
220 agn_locus_genes(LC, PREDICTIONSOURCE)
221 #define agn_locus_refr_genes(LC)\
222 agn_locus_genes(LC, REFERENCESOURCE)
223 #define agn_locus_get_genes(LC)\
224 agn_locus_genes(LC, DEFAULTSOURCE)
225
226 /**
227 * @function Get the gene IDs associated with this locus. Rather than
228 * calling this function directly, users are encouraged to use one of the
229 * following macros: ``agn_locus_pred_gene_ids(locus)`` to retrieve
230 * prediction IDs, ``agn_locus_refr_gene_ids(locus)`` to retrieve
231 * reference IDs, or ``agn_locus_get_gene_ids(locus)`` if the source of
232 * annotation is undesignated or irrelevant.
233 */
234
235 GtArray *agn_locus_gene_ids(AgnLocus *locus, AgnComparisonSource src);
236 #define agn_locus_pred_gene_ids(LC)\
237 agn_locus_gene_ids(LC, PREDICTIONSOURCE)
238 #define agn_locus_refr_gene_ids(LC)\
239 agn_locus_gene_ids(LC, REFERENCESOURCE)
240 #define agn_locus_get_gene_ids(LC)\
241 agn_locus_gene_ids(LC, DEFAULTSOURCE)
242
243 /**
244 * @function Get the number of genes for the locus. Rather than calling
245 * this function directly, users are encouraged to use one of the following
246 * macros: ``agn_locus_num_pred_genes(locus)`` for the number of prediction
247 * genes, ``agn_locus_num_refr_genes(locus)`` for the number of reference
248 * genes, or ``agn_locus_num_genes(locus)`` if the source of annotation is
249 * undesignated or irrelevant.
250 */
251 GtUword agn_locus_gene_num(AgnLocus *locus, AgnComparisonSource src);
252 #define agn_locus_num_pred_genes(LC)\
253 agn_locus_gene_num(LC, PREDICTIONSOURCE)
254 #define agn_locus_num_refr_genes(LC)\
255 agn_locus_gene_num(LC, REFERENCESOURCE)
256 #define agn_locus_num_genes(LC)\
257 agn_locus_gene_num(LC, DEFAULTSOURCE)
258
259 /**
260 * @function Given two adjacent gene-containing iLoci, determine their
261 * orientation: 0 for both forward ('>>'), 1 for inner ('><'), 2 for outer
262 * ('<>'), and 3 for reverse ('<<').
263 */
264 int agn_locus_inner_orientation(AgnLocus *left, AgnLocus *right);
265
266 /**
267 * @function Get the mRNAs associated with this locus. Rather than calling
268 * this function directly, users are encouraged to use one of the following
269 * macros: ``agn_locus_pred_mrnas(locus)`` to retrieve prediction mRNAs,
270 * ``agn_locus_refr_mrnas(locus)`` to retrieve reference mRNAs, or
271 * ``agn_locus_get_mrnas(locus)`` if the source of annotation is undesignated or
272 * irrelevant.
273 */
274 GtArray *agn_locus_mrnas(AgnLocus *locus, AgnComparisonSource src);
275 #define agn_locus_pred_mrnas(LC)\
276 agn_locus_mrnas(LC, PREDICTIONSOURCE)
277 #define agn_locus_refr_mrnas(LC)\
278 agn_locus_mrnas(LC, REFERENCESOURCE)
279 #define agn_locus_get_mrnas(LC)\
280 agn_locus_mrnas(LC, DEFAULTSOURCE)
281
282 /**
283 * @function Get the mRNA IDs associated with this locus. Rather than
284 * calling this function directly, users are encouraged to use one of the
285 * following macros: ``agn_locus_pred_mrna_ids(locus)`` to retrieve
286 * prediction IDs, ``agn_locus_refr_mrna_ids(locus)`` to retrieve
287 * reference IDs, or ``agn_locus_get_mrna_ids(locus)`` if the source of
288 * annotation is undesignated or irrelevant.
289 */
290 GtArray *agn_locus_mrna_ids(AgnLocus *locus, AgnComparisonSource src);
291 #define agn_locus_pred_mrna_ids(LC)\
292 agn_locus_mrna_ids(LC, PREDICTIONSOURCE)
293 #define agn_locus_refr_mrna_ids(LC)\
294 agn_locus_mrna_ids(LC, REFERENCESOURCE)
295 #define agn_locus_get_mrna_ids(LC)\
296 agn_locus_mrna_ids(LC, DEFAULTSOURCE)
297
298 /**
299 * @function Get the number of mRNAs for the locus. Rather than calling
300 * this function directly, users are encouraged to use one of the following
301 * macros: ``agn_locus_num_pred_mrnas(locus)`` for the number of prediction
302 * mRNAs, ``agn_locus_num_refr_mrnas(locus)`` for the number of reference
303 * mRNAs, or ``agn_locus_num_mrnas(locus)`` if the source of annotation is
304 * undesignated or irrelevant.
305 */
306 GtUword agn_locus_mrna_num(AgnLocus *locus, AgnComparisonSource src);
307 #define agn_locus_num_pred_mrnas(LC)\
308 agn_locus_mrna_num(LC, PREDICTIONSOURCE)
309 #define agn_locus_num_refr_mrnas(LC)\
310 agn_locus_mrna_num(LC, REFERENCESOURCE)
311 #define agn_locus_num_mrnas(LC)\
312 agn_locus_mrna_num(LC, DEFAULTSOURCE)
313
314 /**
315 * @function Class constructor.
316 */
317 AgnLocus* agn_locus_new(GtStr *seqid);
318
319 /**
320 * @function Return the clique pairs to be reported for this locus.
321 */
322 GtArray *agn_locus_pairs_to_report(AgnLocus *locus);
323
324 #ifndef WITHOUT_CAIRO
325 /**
326 * @function Track selector function for generating PNG graphics of pairwise
327 * comparison loci. The track name to will be written to ``track``.
328 */
329 void agn_locus_png_track_selector(GtBlock *block, GtStr *track,void *data);
330 #endif
331
332 #ifndef WITHOUT_CAIRO
333 /**
334 * @function Print a PNG graphic for this locus.
335 */
336 void agn_locus_print_png(AgnLocus *locus, AgnLocusPngMetadata *metadata);
337 #endif
338
339 /**
340 * @function Print a mapping of the transcript(s) associated with this locus in
341 * a two-column tab-delimited format: ``transcriptId<tab>locusId``.
342 */
343 void agn_locus_print_transcript_mapping(AgnLocus *locus, FILE *outstream);
344
345 /**
346 * @function Set the start and end coordinates for this locus.
347 */
348 void agn_locus_set_range(AgnLocus *locus, GtUword start, GtUword end);
349
350 /**
351 * @function Calculate the splice complexity of this gene locus. Rather than
352 * calling this method directly, users are recommended to use one of the
353 * following macros: ``agn_locus_prep_splice_complexity(locus)`` to
354 * calculate the splice complexity of just the prediction transcripts,
355 * ``agn_locus_refr_splice_complexity(locus)`` to calculate the splice
356 * complexity of just the reference transcripts, and
357 * ``agn_locus_calc_splice_complexity(locus)`` to calculate the splice
358 * complexity taking into account all transcripts.
359 */
360 double agn_locus_splice_complexity(AgnLocus *locus, AgnComparisonSource src);
361 #define agn_locus_pred_splice_complexity(LC)\
362 agn_locus_splice_complexity(LC, PREDICTIONSOURCE)
363 #define agn_locus_refr_splice_complexity(LC)\
364 agn_locus_splice_complexity(LC, REFERENCESOURCE)
365 #define agn_locus_calc_splice_complexity(LC)\
366 agn_locus_splice_complexity(LC, DEFAULTSOURCE)
367
368 /**
369 * @function Run unit tests for this class. Returns true if all tests passed.
370 */
371 bool agn_locus_unit_test(AgnUnitTest *test);
372
373 #endif