| 1 |
/** |
| 2 |
|
| 3 |
Copyright (c) 2010-2015, 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 AGN_UTILS |
| 11 |
#define AGN_UTILS |
| 12 |
|
| 13 |
#include "core/array_api.h" |
| 14 |
#include "core/str_api.h" |
| 15 |
#include "extended/feature_index_api.h" |
| 16 |
#include "extended/genome_node_api.h" |
| 17 |
|
| 18 |
#define AGN_MAX_FILENAME_SIZE 4096 |
| 19 |
|
| 20 |
/** |
| 21 |
* @module AgnUtils |
| 22 |
* |
| 23 |
* Collection of assorted functions that are otherwise unrelated. |
| 24 |
*/ //; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* @type This data structure combines sequence coordinates with a sequence ID to |
| 29 |
* facilitate their usage together. |
| 30 |
*/ |
| 31 |
struct AgnSequenceRegion |
| 32 |
{ |
| 33 |
GtStr *seqid; |
| 34 |
GtRange range; |
| 35 |
}; |
| 36 |
typedef struct AgnSequenceRegion AgnSequenceRegion; |
| 37 |
|
| 38 |
#ifndef NDEBUG |
| 39 |
/* Stolen shamelessley from gt_assert() */ |
| 40 |
#define agn_assert(expression) \ |
| 41 |
do { \ |
| 42 |
if (!(expression)) { \ |
| 43 |
fprintf(stderr, "Assertion failed: (%s), function %s, file %s, " \ |
| 44 |
"line %d.\nThis is a bug, please report it at " \ |
| 45 |
"https://github.com/standage/AEGeAn/issues.\n", \ |
| 46 |
#expression, __func__, __FILE__, __LINE__); \ |
| 47 |
/*@ignore@*/ \ |
| 48 |
exit(1); \ |
| 49 |
/*@end@*/ \ |
| 50 |
} \ |
| 51 |
} while (false) |
| 52 |
#else |
| 53 |
#define agn_assert(expression) ((void) 0) |
| 54 |
#endif |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* @function Similar to ``gt_array_copy``, except that array elements are |
| 59 |
* treated as pointers and dereferenced before being added to the new array. |
| 60 |
*/ |
| 61 |
GtArray* agn_array_copy(GtArray *source, size_t size); |
| 62 |
|
| 63 |
/** |
| 64 |
* @function Determine the splice complexity of the given set of transcripts. |
| 65 |
*/ |
| 66 |
double agn_calc_splice_complexity(GtArray *transcripts); |
| 67 |
|
| 68 |
/** |
| 69 |
* @function Copy the sequence regions from ``src`` to ``dest``. If ``use_orig`` |
| 70 |
* is true, regions specified by input region nodes (such as those parsed from |
| 71 |
* ``##sequence-region`` pragmas in GFF3) are used. Otherwise, regions inferred |
| 72 |
* directly from the feature nodes are used. |
| 73 |
*/ |
| 74 |
GtUword |
| 75 |
agn_feature_index_copy_regions(GtFeatureIndex *dest, GtFeatureIndex *src, |
| 76 |
bool use_orig, GtError *error); |
| 77 |
|
| 78 |
/** |
| 79 |
* @function Copy the sequence regions from ``refrsrc`` and ``predsrc`` to |
| 80 |
* ``dest``. If ``use_orig`` is true, regions specified by input region nodes |
| 81 |
* (such as those parsed from ``##sequence-region`` pragmas in GFF3) are used. |
| 82 |
* Otherwise, regions inferred directly from the feature nodes are used. |
| 83 |
*/ |
| 84 |
GtUword |
| 85 |
agn_feature_index_copy_regions_pairwise(GtFeatureIndex *dest, |
| 86 |
GtFeatureIndex *refrsrc, |
| 87 |
GtFeatureIndex *predsrc, |
| 88 |
bool use_orig, GtError *error); |
| 89 |
|
| 90 |
/** |
| 91 |
* @function Traverse the given feature and its subfeatures and find the |
| 92 |
* range occupied by coding sequence, or {0,0} if there is no coding sequence. |
| 93 |
*/ |
| 94 |
GtRange agn_feature_node_get_cds_range(GtFeatureNode *fn); |
| 95 |
|
| 96 |
/** |
| 97 |
* @function Return an array of the given feature node's direct children. |
| 98 |
*/ |
| 99 |
GtArray *agn_feature_node_get_children(GtFeatureNode *fn); |
| 100 |
|
| 101 |
/** |
| 102 |
* @function ID attribute is required to be unique within a single GFF3 file, |
| 103 |
* but is not guaranteed to be unique among all GFF3 files (that is, it is not |
| 104 |
* a stable identifier). This function searches other common attributes for |
| 105 |
* labels or identifiers (`accession` and then `Name`) that are likely to be |
| 106 |
* more stable. If these cannot be found, the `ID` attribute is retrieved. |
| 107 |
* Finally, if `ID` is unavailable, the location of the feature will be |
| 108 |
* returned in the format `${featuretype}:${seqid}_${start}-${end}`. |
| 109 |
*/ |
| 110 |
const char *agn_feature_node_get_label(GtFeatureNode *fn); |
| 111 |
|
| 112 |
/** |
| 113 |
* @function Remove feature ``fn`` and all its subfeatures from ``root``. |
| 114 |
* Analogous to ``gt_feature_node_remove_leaf`` with the difference that ``fn`` |
| 115 |
* need not be a leaf feature. |
| 116 |
*/ |
| 117 |
void agn_feature_node_remove_tree(GtFeatureNode *root, GtFeatureNode *fn); |
| 118 |
|
| 119 |
/** |
| 120 |
* @function Returns true if any of the features in ``feats`` overlaps, false |
| 121 |
* otherwise. |
| 122 |
*/ |
| 123 |
bool agn_feature_overlap_check(GtArray *feats); |
| 124 |
|
| 125 |
/** |
| 126 |
* @function Compare function for data type ``GtGenomeNode **``, needed for |
| 127 |
* sorting ``GtGenomeNode *`` stored in ``GtArray`` objects. |
| 128 |
*/ |
| 129 |
int agn_genome_node_compare(GtGenomeNode **gn_a, GtGenomeNode **gn_b); |
| 130 |
|
| 131 |
/** |
| 132 |
* @function Determine the length of an mRNA's 3' UTR. |
| 133 |
*/ |
| 134 |
GtUword agn_mrna_3putr_length(GtFeatureNode *mrna); |
| 135 |
|
| 136 |
/** |
| 137 |
* @function Determine the length of an mRNA's 5'UTR. |
| 138 |
*/ |
| 139 |
GtUword agn_mrna_5putr_length(GtFeatureNode *mrna); |
| 140 |
|
| 141 |
/** |
| 142 |
* @function Determine the length of an mRNA's coding sequence. |
| 143 |
*/ |
| 144 |
GtUword agn_mrna_cds_length(GtFeatureNode *mrna); |
| 145 |
|
| 146 |
/** |
| 147 |
* @function If a top-level feature ``top`` contains a multifeature child (with |
| 148 |
* multi representative ``rep``), use this function to get the complete range of |
| 149 |
* the multifeature. |
| 150 |
*/ |
| 151 |
GtRange agn_multi_child_range(GtFeatureNode *top, GtFeatureNode *rep); |
| 152 |
|
| 153 |
/** |
| 154 |
* @function Determine if two features overlap such that they should be |
| 155 |
* assigned to the same iLocus. Specify the minimum overlap (in bp) required |
| 156 |
* and whether the location of the feature's coding sequence (CDS) should be |
| 157 |
* used or not. |
| 158 |
*/ |
| 159 |
bool agn_overlap_ilocus(GtGenomeNode *f1, GtGenomeNode *f2, |
| 160 |
GtUword minoverlap, bool by_cds); |
| 161 |
|
| 162 |
/** |
| 163 |
* @function CLI function: provide the name of the program, and this function |
| 164 |
* prints out the AEGeAn version number to the specified outstream. |
| 165 |
*/ |
| 166 |
void agn_print_version(const char *progname, FILE *outstream); |
| 167 |
|
| 168 |
/** |
| 169 |
* @function Format the given non-negative number with commas as the thousands |
| 170 |
* separator. The resulting string will be written to ``buffer``. |
| 171 |
*/ |
| 172 |
int agn_sprintf_comma(GtUword n, char *buffer); |
| 173 |
|
| 174 |
/** |
| 175 |
* @function Dereference the given pointers and compare the resulting strings |
| 176 |
* (*a la* ``strcmp``). |
| 177 |
*/ |
| 178 |
int agn_string_compare(const void *p1, const void *p2); |
| 179 |
|
| 180 |
/** |
| 181 |
* @function Find the strings that are present in either (or both) of the string |
| 182 |
* arrays. |
| 183 |
*/ |
| 184 |
GtStrArray* agn_str_array_union(GtStrArray *a1, GtStrArray *a2); |
| 185 |
|
| 186 |
#endif |