| 1 | #ifndef SCYTHE_H |
| 2 | #define SCYTHE_H |
| 3 | |
| 4 | #include <zlib.h> |
| 5 | #include "kseq.h" |
| 6 | |
| 7 | /* KSEQ_INIT() cannot be called here, because we only need the types |
| 8 | defined. Calling KSEQ_INIT() would also define functions, leading |
| 9 | to an unused function warning with GCC. So, the basic typedefs |
| 10 | kseq.h has are included here, and each file that reads needs: |
| 11 | |
| 12 | This was a fix also used in Nik Joshi's Sickle (which I also helped |
| 13 | with) and is the only way I know of dealing with this. |
| 14 | |
| 15 | __KS_GETC(gzread, BUFFER_SIZE) |
| 16 | __KS_GETUNTIL(gzread, BUFFER_SIZE) |
| 17 | __KSEQ_READ |
| 18 | */ |
| 19 | |
| 20 | #define BUFFER_SIZE 4096 |
| 21 | __KS_TYPE(gzFile) |
| 22 | __KS_BASIC(gzFile, BUFFER_SIZE) |
| 23 | __KSEQ_TYPE(gzFile) |
| 24 | |
| 25 | #define MAX_ADAPTERS 1000 |
| 26 | #define MATCH_SCORE 1 |
| 27 | #define MISMATCH_SCORE -1 |
| 28 | |
| 29 | #define IS_FASTQ(quality_type) INTEGER(quality_type)[0] >= 0 |
| 30 | #define min(a,b) ((a)>(b)?(b):(a)) |
| 31 | |
| 32 | typedef enum { |
| 33 | PHRED, |
| 34 | SANGER, |
| 35 | SOLEXA, |
| 36 | ILLUMINA |
| 37 | } quality_type; |
| 38 | |
| 39 | #define Q_OFFSET 0 |
| 40 | #define Q_MIN 1 |
| 41 | #define Q_MAX 2 |
| 42 | |
| 43 | /* The quality constants come from: |
| 44 | http://www.biopython.org/DIST/docs/api/Bio.SeqIO.QualityIO-module.html*/ |
| 45 | |
| 46 | static const int quality_contants[4][3] = { |
| 47 | /* offset, min, max */ |
| 48 | {0, 4, 60}, /* PHRED */ |
| 49 | {33, 0, 93}, /* SANGER */ |
| 50 | {64, -5, 62}, /* SOLEXA, early Illumina (pre-pipeline 1.3) */ |
| 51 | {64, 0, 62} /* ILLUMINA (post-pipeline 1.3) */ |
| 52 | }; |
| 53 | |
| 54 | typedef struct adapter { |
| 55 | char *name; |
| 56 | char *seq; |
| 57 | int length; |
| 58 | unsigned int *occurrences; |
| 59 | } adapter; |
| 60 | |
| 61 | typedef struct adapter_array { |
| 62 | adapter *adapters; |
| 63 | int n; |
| 64 | } adapter_array; |
| 65 | |
| 66 | typedef struct likelihood_set { |
| 67 | double random; |
| 68 | double contam; |
| 69 | } likelihood_set; |
| 70 | |
| 71 | typedef struct posterior_set { |
| 72 | int is_contam; |
| 73 | double random; |
| 74 | double contam; |
| 75 | } posterior_set; |
| 76 | |
| 77 | typedef struct match { |
| 78 | int *match, *match_pos; // match positions; TODO simplify |
| 79 | int shift; // position adapter found, -1 if is_contam is 0 |
| 80 | int length; // length of adapter contamination, -1 if is_contam is 0 |
| 81 | int score; // match score |
| 82 | int adapter_index; // index of which adapter was found |
| 83 | float *p_quals; // array of qualities convered to probs |
| 84 | posterior_set *ps; // posterior set |
| 85 | } match; |
| 86 | |
| 87 | /* prob.c prototypes */ |
| 88 | float *qual_to_probs(const char *, quality_type); |
| 89 | double p_data(const int *, float *, float, float, int); |
| 90 | posterior_set *posterior(const int *, float *, float, float, int); |
| 91 | likelihood_set *likelihood(const int *, float *, float, int); |
| 92 | |
| 93 | /* util.c prototypes */ |
| 94 | void *xmalloc(size_t); |
| 95 | adapter_array *load_adapters(gzFile); |
| 96 | void destroy_adapters(adapter_array *, int); |
| 97 | char *fmt_matches(const char *, const char *, const int *, const int); |
| 98 | void print_float_array(const float *, int); |
| 99 | void fprint_float_array(FILE *, const float *, int); |
| 100 | void print_int_array(const int *, int); |
| 101 | void print_uint_array(const unsigned int *, int); |
| 102 | void fprint_uint_array(FILE *, const unsigned int *, int); |
| 103 | extern int sum(const int *, size_t); |
| 104 | void write_fastq(FILE *, kseq_t *, int, int, int); |
| 105 | void print_summary(adapter_array *, float, int, int, int); |
| 106 | |
| 107 | /* match.c prototypes */ |
| 108 | int *score_sequence(int *, const char *, const char *, size_t); |
| 109 | match *find_best_match(const adapter_array *, const char *, float *, float, float, int); |
| 110 | void print_match(kseq_t *, match *, FILE *, const adapter_array *, quality_type); |
| 111 | void destroy_match(match *); |
| 112 | |
| 113 | |
| 114 | #endif /* SCYTHE_H */ |