| 1 | /**************************************************************************** |
| 2 | * Header file for Kmer similarity computation functions * |
| 3 | ****************************************************************************/ |
| 4 | |
| 5 | /** |
| 6 | * @file kmer_similarity.h |
| 7 | * @author Celine Mercier ([email protected]) |
| 8 | * @date January 7th 2019 |
| 9 | * @brief Header file for Kmer similarity computation functions. |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #ifndef KMER_SIMILARITY_H_ |
| 14 | #define KMER_SIMILARITY_H_ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | |
| 18 | #include "obitypes.h" |
| 19 | #include "obidmscolumn.h" |
| 20 | #include "obiview.h" |
| 21 | |
| 22 | |
| 23 | #define ARRAY_LENGTH (256) |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * @brief Alignment structure, with informations about the similarity and to rebuild the alignment. |
| 28 | */ |
| 29 | typedef struct Obi_ali { |
| 30 | int score; /**< Alignment score, corresponding to an approximation of the number of |
| 31 | * nucleotides matching in the overlap of the alignment. |
| 32 | * It's an approximation because one mismatch produces kmer_size kmer mismatches if in the middle of the overlap, |
| 33 | * and less for mismatches located towards the ends of the overlap. The case where there are the most mismatches is assumed, |
| 34 | * meaning that the score will be often underestimated and never overestimated. |
| 35 | */ |
| 36 | int consensus_length; /**< Length of the final consensus sequence. |
| 37 | */ |
| 38 | int overlap_length; /**< Length of the overlap between the aligned sequences. |
| 39 | */ |
| 40 | char* consensus_seq; /**< Consensus sequence built as to reconstruct a pairedend read. |
| 41 | */ |
| 42 | uint8_t* consensus_qual; /**< Consensus quality built as to reconstruct a pairedend read. |
| 43 | */ |
| 44 | int shift; /**< Shift chosen to align the sequences. |
| 45 | */ |
| 46 | char direction[6]; /**< Alignment direction (positive/right or negative/left shift). |
| 47 | */ |
| 48 | } Obi_ali_t, *Obi_ali_p; |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * @brief Frees an Obi_ali_p structure and all its elements. |
| 53 | * |
| 54 | * @warning The pointer sent becomes unusable. |
| 55 | * |
| 56 | * @param ali The pointer on the Obi_ali_p structure to free. |
| 57 | * |
| 58 | * @since January 2019 |
| 59 | * @author Celine Mercier ([email protected]) |
| 60 | */ |
| 61 | void obi_free_shifted_ali(Obi_ali_p ali); |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Function computing the kmer similarity of two sequences stored in views. |
| 66 | * |
| 67 | * The similarity is computing this way: the positions of identical kmers in both sequences are |
| 68 | * compared, and the most represented shift is chosen. The similarity is then calculated as: |
| 69 | * kmer_similarity = number_of_common_kmers_with_the_chosen_shift + kmer_size - 1 |
| 70 | * |
| 71 | * @warning Several pointers and structures passed to or returned by the function have to be freed by the caller: |
| 72 | * - kmer_pos_array |
| 73 | * - shift_array |
| 74 | * - shift_count_array |
| 75 | * - the Obi_ali_p structure returned |
| 76 | * |
| 77 | * @param view1 A pointer on the view containing the first sequence. |
| 78 | * @param column1 A pointer on the column containing the first sequence. |
| 79 | * @param idx1 The index of the first sequence in view1. |
| 80 | * @param elt_idx1 The element index of the first sequence in column1. |
| 81 | * @param view2 A pointer on the view containing the second sequence. |
| 82 | * @param column2 A pointer on the column containing the second sequence. |
| 83 | * @param idx2 The index of the second sequence in view2. |
| 84 | * @param elt_idx2 The element index of the second sequence in column2. |
| 85 | * @param qual_col1 A pointer on the column containing the quality associated with the first sequence (in view1). |
| 86 | * @param qual_col2 A pointer on the column containing the quality associated with the second sequence (in view2). |
| 87 | * @param reversed_column A pointer on the column containing a boolean indicating whether the sequences correspond |
| 88 | * to paired-end reads that might have been reversed before aligning them |
| 89 | * (e.g. when the ngsfilter tool is used before alignpairedend). |
| 90 | * @param kmer_size The kmer length to use. Must be >= 1 <= 4. |
| 91 | * @param kmer_pos_array The array used to store kmer positions. If NULL, allocated by the function. |
| 92 | * If needed, reallocated to a bigger size. |
| 93 | * @param kmer_pos_array_height_p A pointer on an integer corresponding to the size (number of elements) |
| 94 | * allocated for kmer_pos_array. Updated by the function as needed. |
| 95 | * @param shift_array The array used to store kmer shifts. If NULL, allocated by the function. |
| 96 | * If needed, reallocated to a bigger size. |
| 97 | * @param shift_array_height_p A pointer on an integer corresponding to the size (number of elements) |
| 98 | * allocated for shift_array. Updated by the function as needed. |
| 99 | * @param shift_count_array The array used to store shift counts. If NULL, allocated by the function. |
| 100 | * If needed, reallocated to a bigger size. |
| 101 | * @param shift_count_array_height_p A pointer on an integer corresponding to the size (number of elements) |
| 102 | * allocated for shift_count_array. Updated by the function as needed. |
| 103 | * @param build_consensus A boolean indicating whether the function should build the consensus sequence and quality as to reconstruct a pairedend read. // TODO option to build consensus without quality? |
| 104 | * |
| 105 | * @returns A pointer on an Obi_ali_p structure containing the results. |
| 106 | * @retval NULL if an error occurred. |
| 107 | * |
| 108 | * @since January 2019 |
| 109 | * @author Celine Mercier ([email protected]) |
| 110 | */ |
| 111 | Obi_ali_p kmer_similarity(Obiview_p view1, |
| 112 | OBIDMS_column_p column1, |
| 113 | index_t idx1, |
| 114 | index_t elt_idx1, |
| 115 | Obiview_p view2, |
| 116 | OBIDMS_column_p column2, |
| 117 | index_t idx2, |
| 118 | index_t elt_idx2, |
| 119 | OBIDMS_column_p qual_col1, |
| 120 | OBIDMS_column_p qual_col2, |
| 121 | OBIDMS_column_p reversed_column, |
| 122 | uint8_t kmer_size, |
| 123 | int32_t** kmer_pos_array_p, |
| 124 | int32_t* kmer_pos_array_height_p, |
| 125 | int32_t** shift_array_p, |
| 126 | int32_t* shift_array_height_p, |
| 127 | int32_t** shift_count_array_p, |
| 128 | int32_t* shift_count_array_height_p, |
| 129 | bool build_consensus); |
| 130 | |
| 131 | |
| 132 | #endif /* KMER_SIMILARITY_H_ */ |