Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cram compression container substitution matrix generation. #1562

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions cram/cram_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int process_one_read(cram_fd *fd, cram_container *c,
static int sub_idx(char *key, char val) {
int i;

for (i = 0; *key && *key++ != val; i++);
for (i = 0; i < 4 && *key++ != val; i++);
return i;
}

Expand Down Expand Up @@ -203,31 +203,38 @@ cram_block *cram_encode_compression_header(cram_fd *fd, cram_container *c,

case CRAM_KEY('S','M'): {
char smat[5], *mp = smat;
// Output format is for order ACGTN (minus ref base)
// to store the code value 0-3 for each symbol.
//
// Note this is different to storing the symbols in order
// that the codes occur from 0-3, which is what we used to
// do. (It didn't matter as we always had a fixed table in
// the order.)
*mp++ =
(sub_idx("CGTN", h->substitution_matrix[0][0]) << 6) |
(sub_idx("CGTN", h->substitution_matrix[0][1]) << 4) |
(sub_idx("CGTN", h->substitution_matrix[0][2]) << 2) |
(sub_idx("CGTN", h->substitution_matrix[0][3]) << 0);
(sub_idx(h->substitution_matrix[0], 'C') << 6) |
(sub_idx(h->substitution_matrix[0], 'G') << 4) |
(sub_idx(h->substitution_matrix[0], 'T') << 2) |
(sub_idx(h->substitution_matrix[0], 'N') << 0);
*mp++ =
(sub_idx("AGTN", h->substitution_matrix[1][0]) << 6) |
(sub_idx("AGTN", h->substitution_matrix[1][1]) << 4) |
(sub_idx("AGTN", h->substitution_matrix[1][2]) << 2) |
(sub_idx("AGTN", h->substitution_matrix[1][3]) << 0);
(sub_idx(h->substitution_matrix[1], 'A') << 6) |
(sub_idx(h->substitution_matrix[1], 'G') << 4) |
(sub_idx(h->substitution_matrix[1], 'T') << 2) |
(sub_idx(h->substitution_matrix[1], 'N') << 0);
*mp++ =
(sub_idx("ACTN", h->substitution_matrix[2][0]) << 6) |
(sub_idx("ACTN", h->substitution_matrix[2][1]) << 4) |
(sub_idx("ACTN", h->substitution_matrix[2][2]) << 2) |
(sub_idx("ACTN", h->substitution_matrix[2][3]) << 0);
(sub_idx(h->substitution_matrix[2], 'A') << 6) |
(sub_idx(h->substitution_matrix[2], 'C') << 4) |
(sub_idx(h->substitution_matrix[2], 'T') << 2) |
(sub_idx(h->substitution_matrix[2], 'N') << 0);
*mp++ =
(sub_idx("ACGN", h->substitution_matrix[3][0]) << 6) |
(sub_idx("ACGN", h->substitution_matrix[3][1]) << 4) |
(sub_idx("ACGN", h->substitution_matrix[3][2]) << 2) |
(sub_idx("ACGN", h->substitution_matrix[3][3]) << 0);
(sub_idx(h->substitution_matrix[3], 'A') << 6) |
(sub_idx(h->substitution_matrix[3], 'C') << 4) |
(sub_idx(h->substitution_matrix[3], 'G') << 2) |
(sub_idx(h->substitution_matrix[3], 'N') << 0);
*mp++ =
(sub_idx("ACGT", h->substitution_matrix[4][0]) << 6) |
(sub_idx("ACGT", h->substitution_matrix[4][1]) << 4) |
(sub_idx("ACGT", h->substitution_matrix[4][2]) << 2) |
(sub_idx("ACGT", h->substitution_matrix[4][3]) << 0);
(sub_idx(h->substitution_matrix[4], 'A') << 6) |
(sub_idx(h->substitution_matrix[4], 'C') << 4) |
(sub_idx(h->substitution_matrix[4], 'G') << 2) |
(sub_idx(h->substitution_matrix[4], 'T') << 0);
BLOCK_APPEND(map, smat, 5);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion cram/cram_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct hFILE;
#define BASES_PER_SLICE (SEQS_PER_SLICE*500)
#define SLICE_PER_CNT 1

#define CRAM_SUBST_MATRIX "CGTNAGTNACTNACGNACGT"
#define CRAM_SUBST_MATRIX "CGTNGTANCATNGCANACGT"

#define MAX_STAT_VAL 1024
//#define MAX_STAT_VAL 16
Expand Down