Example #1
0
void
tmap_sff_reverse(tmap_sff_t *sff)
{
  uint32_t i;

  // reverse flowgram
  for(i=0;i<(sff->gheader->flow_length>>1);i++) {
      uint16_t tmp = sff->read->flowgram[sff->gheader->flow_length-1-i];
      sff->read->flowgram[sff->gheader->flow_length-1-i] = sff->read->flowgram[i];
      sff->read->flowgram[i] = tmp;
  }
  // reverse flow index
  for(i=0;i<(sff->rheader->n_bases>>1);i++) {
      uint8_t tmp = sff->read->flow_index[sff->rheader->n_bases-1-i];
      sff->read->flow_index[sff->rheader->n_bases-1-i] = sff->read->flow_index[i];
      sff->read->flow_index[i] = tmp;
  }
  // reverse compliment the bases
  tmap_string_reverse(sff->read->bases);
  // reverse the qualities
  tmap_string_reverse(sff->read->quality);
}
Example #2
0
void
tmap_sam_reverse_compliment(tmap_sam_t *sam)
{
  tmap_string_reverse_compliment(sam->seq, sam->is_int);
  tmap_string_reverse(sam->qual);
}
Example #3
0
void
tmap_sam_reverse(tmap_sam_t *sam)
{
  tmap_string_reverse(sam->seq);
  tmap_string_reverse(sam->qual);
}
Example #4
0
void
tmap_fq_reverse_compliment(tmap_fq_t *fq)
{
    tmap_string_reverse_compliment(fq->seq, fq->is_int);
    tmap_string_reverse(fq->qual);
}
Example #5
0
void
tmap_fq_reverse(tmap_fq_t *fq)
{
    tmap_string_reverse(fq->seq);
    tmap_string_reverse(fq->qual);
}
Example #6
0
inline void
tmap_sam_print_mapped(tmap_file_t *fp, tmap_seq_t *seq, int32_t sam_flowspace_tags, int32_t bidirectional, int32_t seq_eq, tmap_refseq_t *refseq,
                      uint8_t strand, uint32_t seqid, uint32_t pos, int32_t aln_num,
                      uint32_t end_num, uint32_t m_unmapped, uint32_t m_prop, double m_num_std, uint32_t m_strand,
                      uint32_t m_seqid, uint32_t m_pos, uint32_t m_tlen,
                      uint8_t mapq, uint32_t *cigar, int32_t n_cigar,
                      int32_t score, int32_t ascore, int32_t pscore, int32_t nh, int32_t algo_id, int32_t algo_stage,
                      const char *format, ...)
{
  va_list ap;
  int32_t i;
  tmap_string_t *name=NULL, *bases=NULL, *qualities=NULL;
  char *bases_eq=NULL;
  uint32_t flag;
  tmap_string_t *md;
  int32_t nm;

  /*
  fprintf(stderr, "end_num=%d m_unmapped=%d m_prop=%d m_strand=%d m_seqid=%d m_pos=%d m_tlen=%d\n",
          end_num, m_unmapped, m_prop, m_strand, m_seqid, m_pos, m_tlen);
  */

  name = tmap_seq_get_name(seq);
  bases = tmap_seq_get_bases(seq);
  qualities = tmap_seq_get_qualities(seq);

  if(1 == strand) { // reverse for the output
      tmap_string_reverse_compliment(bases, 0);
      tmap_string_reverse(qualities);
  }

  if(0 == pos + 1) {
      tmap_error("position is out of range", Exit, OutOfRange);
  }

  // compute the MD/NM
  if(1 == seq_eq && 0 < bases->l) {
      bases_eq = tmap_calloc((1 + bases->l), sizeof(char), "bases_eq");
  }
  else {
      bases_eq = NULL;
  }
  md = tmap_sam_md(refseq, bases->s, seqid, pos, cigar, n_cigar, &nm, bases_eq);

  // flag
  flag = 0;
  if(1 == strand) flag |= 0x10; // strand
  if(0 < aln_num) flag |= 0x100; // secondary alignment
  if(0 < end_num) { // mate info
      flag |= 0x1;
      if(0 == m_unmapped && 1 == m_prop) flag |= 0x2; // properly aligned
      if(1 == m_unmapped) flag |= 0x8; // unmapped
      else if(1 == m_strand) flag |= 0x20; // strand 
      flag |= (1 == end_num) ? 0x40 : 0x80; // first/second end
  }

  tmap_file_fprintf(fp, "%s\t%u\t%s\t%u\t%u\t",
                    name->s, flag, refseq->annos[seqid].name->s,
                    pos + 1,
                    mapq);

  // print out the cigar
  if(TMAP_SEQ_TYPE_SFF == seq->type) {
      if(0 == strand && 0 < seq->data.sff->rheader->clip_left) {
          tmap_file_fprintf(fp, "%dH", seq->data.sff->rheader->clip_left);
      }
      else if(1 == strand && 0 < seq->data.sff->rheader->clip_right) {
          tmap_file_fprintf(fp, "%dH", seq->data.sff->rheader->clip_right);
      }
  }
  for(i=0;i<n_cigar;i++) {
      tmap_file_fprintf(fp, "%d%c",
                        cigar[i]>>4, "MIDNSHP"[cigar[i]&0xf]);
  }
  if(TMAP_SEQ_TYPE_SFF == seq->type) {
      if(1 == strand && 0 < seq->data.sff->rheader->clip_left) {
          tmap_file_fprintf(fp, "%dH", seq->data.sff->rheader->clip_left);
      }
      else if(0 == strand && 0 < seq->data.sff->rheader->clip_right) {
          tmap_file_fprintf(fp, "%dH", seq->data.sff->rheader->clip_right);
      }
  }
  
  // mate info
  if(0 == end_num) { // no mate
      tmap_file_fprintf(fp, "\t*\t0\t0");
  }
  else if(1 == m_unmapped) { // unmapped mate
      tmap_file_fprintf(fp, "\t%s\t%u\t%u",
                        "=",
                        pos + 1,
                        0);
  }
  else { // mapped mate
      tmap_file_fprintf(fp, "\t%s\t%u\t%d",
                        refseq->annos[m_seqid].name->s,
                        m_pos+1,
                        m_tlen);
  }

  // bases and qualities
  if(1 == seq_eq && NULL != bases_eq) {
      tmap_file_fprintf(fp, "\t%s\t%s", bases_eq, (0 == qualities->l) ? "*" : qualities->s);
  }
  else {
      tmap_file_fprintf(fp, "\t%s\t%s", bases->s, (0 == qualities->l) ? "*" : qualities->s);
  }
  
  // RG 
  tmap_sam_print_rg(fp, seq);

  // PG
  tmap_file_fprintf(fp, "\tPG:Z:%s", PACKAGE_NAME);

  // MD and NM
  tmap_file_fprintf(fp, "\tMD:Z:%s\tNM:i:%d", md->s, nm);

  // AS
  tmap_file_fprintf(fp, "\tAS:i:%d", score);

  // NH
  if(1 < nh) tmap_file_fprintf(fp, "\tNH:i:%d", nh);
  
  // FZ and ZF
  if(1 == sam_flowspace_tags) {
      tmap_sam_print_fz_and_zf(fp, seq);
  }

  // XA
  if(0 < algo_stage) {
      tmap_file_fprintf(fp, "\tXA:Z:%s-%d", tmap_algo_id_to_name(algo_id), algo_stage);
  }
  
  // XZ
  if(TMAP_SEQ_TYPE_SFF == seq->type && INT32_MIN != ascore) {
      tmap_file_fprintf(fp, "\tXZ:i:%d", ascore);
  }
  
  if(0 < end_num) { // mate info
      tmap_file_fprintf(fp, "\tYP:i:%d", pscore);
      if(0 == m_unmapped) {
          tmap_file_fprintf(fp, "\tYS:f:%f", m_num_std);
      }
  }
  if(1 == bidirectional) {
      tmap_file_fprintf(fp, "\tXB:i:1");
  }

  // optional tags
  if(NULL != format) {
      va_start(ap, format);
      tmap_file_vfprintf(fp, format, ap);
      va_end(ap);
  }
  // new line
  tmap_file_fprintf(fp, "\n");
  if(1 == strand) { // reverse back
      tmap_string_reverse_compliment(bases, 0);
      tmap_string_reverse(qualities);
  }

  // free
  tmap_string_destroy(md);
  free(bases_eq);
}