const char *gt_condenseq_extract_decoded_range(GtCondenseq *condenseq, GtRange range, char separator) { GtUword length = range.end - range.start + 1, idx; const GtUchar *ubuf; char *buf; gt_assert(range.start <= range.end); ubuf = gt_condenseq_extract_encoded_range(condenseq, range); if (condenseq->buffer == NULL || condenseq->buffsize < length) { condenseq->buffer = gt_realloc(condenseq->buffer, sizeof (*condenseq->buffer) * length); condenseq->buffsize = length; } buf = condenseq->buffer; for (idx = 0; idx < length; ++idx) { if (ubuf[idx] == SEPARATOR) { buf[idx] = separator; } else { buf[idx] = gt_alphabet_decode(condenseq->alphabet, ubuf[idx]); } } return buf; }
void gt_score_matrix_show(const GtScoreMatrix *sm, FILE *fp) { unsigned i, j; gt_assert(sm && fp); /* show alphabet line */ gt_xfputc(' ', fp); for (i = 0; i < gt_alphabet_size(sm->alphabet); i++) fprintf(fp, " %c", gt_alphabet_decode(sm->alphabet, i)); gt_xfputc('\n', fp); /* show score lines */ for (i = 0; i < gt_alphabet_size(sm->alphabet); i++) { gt_xfputc(gt_alphabet_decode(sm->alphabet, i), fp); for (j = 0; j < gt_alphabet_size(sm->alphabet); j++) fprintf(fp, " %2d", gt_score_matrix_get_score(sm, i, j)); gt_xfputc('\n', fp); } }
char gt_wtree_encseq_unmap_decoded(GtWtree *wtree, GtWtreeSymbol symbol) { GtWtreeEncseq *wtree_encseq; GtUchar encseq_sym = (GtUchar) symbol; gt_assert((symbol & ((GtUchar) 0)) == 0); gt_assert(wtree != NULL); wtree_encseq = gt_wtree_encseq_cast(wtree); switch (wtree_encseq->alpha_size - encseq_sym) { case 1: return (char) SEPARATOR; case 2: return gt_alphabet_decode(wtree_encseq->alpha, (GtUchar) WILDCARD); case 3: return (char) UNDEFCHAR; default: return gt_alphabet_decode(wtree_encseq->alpha, encseq_sym); } }
static int alphabet_lua_decode(lua_State *L) { GtAlphabet **alpha; unsigned int code; char character; alpha = check_alphabet(L, 1); code = luaL_checkinteger(L, 2); /* XXX: too restrictive, does not consider wildcards */ luaL_argcheck(L, code < gt_alphabet_size(*alpha), 2, "invalid code"); character = gt_alphabet_decode(*alpha, code); lua_pushlstring(L, &character, 1); return 1; }
static int hcr_huffman_write_base_qual_freq(GtUword symbol, GtUint64 freq, GT_UNUSED GtBitsequence code, GT_UNUSED unsigned code_length, void *pt) { GtUchar base, qual; WriteNodeInfo *info = (WriteNodeInfo*)pt; gt_safe_assign(base, (symbol % gt_alphabet_size(info->alpha))); if (base == (GtUchar) gt_alphabet_size(info->alpha) - 1) base = (GtUchar) WILDCARD; gt_safe_assign(base, (toupper(gt_alphabet_decode(info->alpha, base)))); gt_xfwrite_one(&base, info->output); gt_safe_assign(qual, (symbol / gt_alphabet_size(info->alpha) + info->qual_offset)); gt_xfwrite_one(&qual, info->output); gt_xfwrite_one(&freq, info->output); return 0; }
static int hcr_next_seq_qual(GtHcrSeqDecoder *seq_dec, char *seq, char *qual, GtError *err) { enum state { HCR_ERROR = -1, END, SUCCESS }; unsigned char base; GtUword i, nearestsample, *symbol; size_t startofnearestsample = 0; enum state status = END; FastqFileInfo cur_read; FastqFileInfo *fileinfo = NULL; if (seq_dec->cur_read <= seq_dec->num_of_reads) { status = SUCCESS; if (seq_dec->symbols == NULL) seq_dec->symbols = gt_array_new(sizeof (GtUword)); else gt_array_reset(seq_dec->symbols); cur_read.readnum = seq_dec->cur_read; gt_log_log("cur_read: "GT_WU"",seq_dec->cur_read); fileinfo = (FastqFileInfo *)gt_rbtree_next_key(seq_dec->file_info_rbt, &cur_read, hcr_cmp_FastqFileInfo, NULL); gt_assert(fileinfo); /* reset huffman_decoder if next read is sampled */ if (gt_sampling_get_next_elementnum(seq_dec->sampling) == seq_dec->cur_read) { gt_log_log("reset because sampled read is next"); (void) gt_sampling_get_next_sample(seq_dec->sampling, &nearestsample, &startofnearestsample); reset_data_iterator_to_pos(seq_dec->data_iter, startofnearestsample); (void) gt_huffman_decoder_get_new_mem_chunk(seq_dec->huff_dec, err); if (gt_error_is_set(err)) status = HCR_ERROR; } if (status != HCR_ERROR) { int ret; ret = gt_huffman_decoder_next(seq_dec->huff_dec, seq_dec->symbols, fileinfo->readlength, err); if (ret != 1) status = HCR_ERROR; if (ret == 0) gt_error_set(err, "reached end of file"); } if (qual || seq) { gt_log_log("set strings"); for (i = 0; i < gt_array_size(seq_dec->symbols); i++) { symbol = (GtUword*) gt_array_get(seq_dec->symbols, i); if (qual != NULL) qual[i] = get_qual_from_symbol(seq_dec, *symbol); if (seq != NULL) { base = get_base_from_symbol(seq_dec, *symbol); seq[i] = (char)toupper(gt_alphabet_decode(seq_dec->alpha, (GtUchar) base)); } } if (qual != NULL) qual[gt_array_size(seq_dec->symbols)] = '\0'; if (seq != NULL) seq[gt_array_size(seq_dec->symbols)] = '\0'; } seq_dec->cur_read++; } return (int) status; }