/* --- .Call ENTRY POINT --- */ SEXP write_XStringSet_to_fasta(SEXP x, SEXP filexp_list, SEXP width, SEXP lkup) { XStringSet_holder X; int x_length, width0, lkup_length, i, j1, j2, dest_nbytes; const int *lkup0; SEXP filexp, x_names, desc; Chars_holder X_elt; char buf[IOBUF_SIZE]; X = _hold_XStringSet(x); x_length = _get_length_from_XStringSet_holder(&X); filexp = VECTOR_ELT(filexp_list, 0); width0 = INTEGER(width)[0]; if (width0 >= IOBUF_SIZE) error("'width' must be <= %d", IOBUF_SIZE - 1); buf[width0] = 0; if (lkup == R_NilValue) { lkup0 = NULL; lkup_length = 0; } else { lkup0 = INTEGER(lkup); lkup_length = LENGTH(lkup); } x_names = get_XVectorList_names(x); for (i = 0; i < x_length; i++) { filexp_puts(filexp, FASTA_desc_markup); if (x_names != R_NilValue) { desc = STRING_ELT(x_names, i); if (desc == NA_STRING) error("'names(x)' contains NAs"); filexp_puts(filexp, CHAR(desc)); } filexp_puts(filexp, "\n"); X_elt = _get_elt_from_XStringSet_holder(&X, i); for (j1 = 0; j1 < X_elt.length; j1 += width0) { j2 = j1 + width0; if (j2 > X_elt.length) j2 = X_elt.length; dest_nbytes = j2 - j1; j2--; Ocopy_bytes_from_i1i2_with_lkup(j1, j2, buf, dest_nbytes, X_elt.ptr, X_elt.length, lkup0, lkup_length); buf[dest_nbytes] = 0; filexp_puts(filexp, buf); filexp_puts(filexp, "\n"); } } return R_NilValue; }
/* --- .Call ENTRY POINT --- */ SEXP write_XStringSet_to_fastq(SEXP x, SEXP filexp_list, SEXP qualities, SEXP lkup) { XStringSet_holder X, Q; int x_length, lkup_length, i; const int *lkup0; SEXP filexp, x_names, q_names; const char *id; Chars_holder X_elt; char buf[IOBUF_SIZE]; X = _hold_XStringSet(x); x_length = _get_length_from_XStringSet_holder(&X); if (qualities != R_NilValue) { Q = _hold_XStringSet(qualities); if (_get_length_from_XStringSet_holder(&Q) != x_length) error("'x' and 'qualities' must have the same length"); q_names = get_XVectorList_names(qualities); } else { q_names = R_NilValue; } filexp = VECTOR_ELT(filexp_list, 0); if (lkup == R_NilValue) { lkup0 = NULL; lkup_length = 0; } else { lkup0 = INTEGER(lkup); lkup_length = LENGTH(lkup); } x_names = get_XVectorList_names(x); for (i = 0; i < x_length; i++) { id = get_FASTQ_rec_id(x_names, q_names, i); X_elt = _get_elt_from_XStringSet_holder(&X, i); Ocopy_bytes_from_i1i2_with_lkup(0, X_elt.length - 1, buf, X_elt.length, X_elt.ptr, X_elt.length, lkup0, lkup_length); buf[X_elt.length] = 0; write_FASTQ_id(filexp, FASTQ_line1_markup, id); write_FASTQ_seq(filexp, buf); write_FASTQ_id(filexp, FASTQ_line3_markup, id); if (qualities != R_NilValue) { write_FASTQ_qual(filexp, X_elt.length, &Q, i); } else { write_FASTQ_fakequal(filexp, X_elt.length); } } return R_NilValue; }
static int copy_exon(char * out, const cachedCharSeq *in, int start, int end, int on_minus_strand, SEXP lkup) { int width; start--; end--; width = end - start + 1; if (on_minus_strand) { Orevcopy_bytes_from_i1i2_with_lkup(start, end, out, width, in->seq, in->length, INTEGER(lkup), LENGTH(lkup)); } else { Ocopy_bytes_from_i1i2_with_lkup(start, end, out, width, in->seq, in->length, NULL, 0); } return width; }