static inline void tmap_sam_print_fz_and_zf(tmap_file_t *fp, tmap_seq_t *seq) { uint16_t *flowgram = NULL; int32_t flow_start_index; int32_t flowgram_len; flowgram_len = tmap_seq_get_flowgram(seq, &flowgram, 0); if(NULL != flowgram) { tmap_sam_print_flowgram(fp, flowgram, flowgram_len); free(flowgram); } flow_start_index = tmap_seq_get_flow_start_index(seq); if(0 <= flow_start_index) { tmap_file_fprintf(fp, "\tZF:i:%d", flow_start_index); } }
void tmap_seq_update(tmap_seq_t *seq, int32_t idx, sam_header_t *header) { char *rg_id = NULL; sam_header_records_t *records = NULL; sam_header_record_t **record_list = NULL; int32_t n = 0; // Read Group switch(seq->type) { case TMAP_SEQ_TYPE_FQ: case TMAP_SEQ_TYPE_SFF: break; case TMAP_SEQ_TYPE_SAM: case TMAP_SEQ_TYPE_BAM: rg_id = tmap_sam_get_rg_id(seq->data.sam); break; default: tmap_error("type is unrecognized", Exit, OutOfRange); break; } if(NULL == rg_id) { // did not find in SAM/BAM // NB: assume that it is from the ith record in the header records = sam_header_get_records(header, "RG"); if(NULL != records) { // it exists if(idx < 0 || records->n <= idx) { tmap_error("RG records index was out of bounds", Exit, OutOfRange); } seq->rg_record = records->records[idx]; // copy over if(NULL == seq->rg_record) tmap_bug(); } } else { // found in SAM/BAM n = 0; record_list = sam_header_get_record(header, "RG", "ID", rg_id, &n); if(0 == n) { fprintf(stderr, "Read Group Identifier: [%s]\n", rg_id); tmap_error("Did not find the @RG.ID in the SAM/BAM Header", Exit, OutOfRange); } else if(1 < n) { fprintf(stderr, "Read Group Identifier: [%s]\n", rg_id); tmap_error("Found more than one @RG.ID in the SAM/BAM Header", Exit, OutOfRange); } seq->rg_record = record_list[0]; free(record_list); // NB: shallow copied } // Program Group // NB: assumes the last item in the header records = sam_header_get_records(header, "PG"); if(NULL != records && 0 < records->n) { // it exists seq->pg_record = records->records[records->n-1]; // copy over } else { seq->pg_record = NULL; } // key sequence and flow order seq->fo_start_idx = -1; if(NULL != seq->rg_record) { // It should exist in the SAM/BAM Header seq->ks = sam_header_record_get(seq->rg_record, "KS"); seq->fo = sam_header_record_get(seq->rg_record, "FO"); // flow order index start if(NULL != seq->ks && NULL != seq->fo && TMAP_SEQ_TYPE_SFF == seq->type) { // only if it is an SFF // in addition, remove key sequence and trimming seq->fo_start_idx = tmap_seq_remove_key_sequence(seq, 1); } else if(TMAP_SEQ_TYPE_SAM == seq->type || TMAP_SEQ_TYPE_BAM == seq->type) { // Try the ZF tag... seq->fo_start_idx = tmap_sam_get_fo_start_idx(seq->data.sam); } // flowgram information... seq->flowgram_len = tmap_seq_get_flowgram(seq, &seq->flowgram); // check if all flowspace information is available /*if((NULL == seq->ks || NULL == seq->fo || -1 == seq->fo_start_idx || NULL == seq->flowgram)// anything missing && (NULL != seq->ks || NULL != seq->fo || -1 != seq->fo_start_idx || NULL != seq->flowgram)) { // anything exists fprintf(stderr, "@RG.KS %s present.\n", (NULL == seq->ks) ? "is not" : "is"); fprintf(stderr, "@RG.FO %s present.\n", (NULL == seq->fo) ? "is not" : "is"); fprintf(stderr, "@SAM.FZ %s present.\n", (NULL == seq->flowgram) ? "is not" : "is"); fprintf(stderr, "@SAM.ZF %s present.\n", (-1 == seq->fo_start_idx) ? "is not" : "is"); tmap_error("Not all flowspace information available (@RG.KS and @RG.FO, and @SAM.FZ and @SAM.ZF)", Exit, OutOfRange); }*/ } }