⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blast_util.c

📁 ncbi源码
💻 C
📖 第 1 页 / 共 3 页
字号:
   Uint1* prot_seq_start;   int byte_value1,byte_value2,byte_value3,byte_value4,byte_value5;      prot_length=0;   if (nt_seq == NULL || prot_seq == NULL ||        (length-ABS(frame)+1) < CODON_LENGTH)      return prot_length;      *prot_seq = NULLB;   prot_seq++;      /* record to determine protein length. */   prot_seq_start = prot_seq;     remainder = length%4;   if (frame > 0) {      nt_seq_end = (Uint1 *) (nt_seq + (length)/4 - 1);      last_remainder = (4*(length/4) - frame + 1)%CODON_LENGTH;      total_remainder = last_remainder+remainder;            state = frame-1;      byte_value = *nt_seq;            /* If there's lots to do, advance to state 0, then enter fast loop */      while (nt_seq < nt_seq_end) {         switch (state)	{         case 0:            codon = (byte_value >> 2);            *prot_seq = translation[codon];            prot_seq++;            /* do state = 3 now, break is NOT missing. */         case 3:            codon = ((byte_value & 3) << 4);            nt_seq++;            byte_value = *nt_seq;	            codon += (byte_value >> 4);            *prot_seq = translation[codon];            prot_seq++;            if (nt_seq >= nt_seq_end) {               state = 2;               break;            }            /* Go on to state = 2 if not at end. */         case 2:            codon = ((byte_value & 15) << 2);            nt_seq++;            byte_value = *nt_seq;	            codon += (byte_value >> 6);            *prot_seq = translation[codon];            prot_seq++;            if (nt_seq >= nt_seq_end) {               state = 1;               break;            }            /* Go on to state = 1 if not at end. */         case 1:            codon = byte_value & 63;            *prot_seq = translation[codon];            prot_seq++;            nt_seq++;            byte_value = *nt_seq;	            state = 0;            break;         } /* end switch */         /* switch ends at state 0, except when at end */                  /********************************************/         /* optimized loop: start in state 0. continue til near end */         while (nt_seq < (nt_seq_end-10)) {            byte_value1 = *(++nt_seq);            byte_value2 = *(++nt_seq);            byte_value3 = *(++nt_seq);            /* case 0: */            codon = (byte_value >> 2);            *prot_seq = translation[codon];            prot_seq++;                        /* case 3: */            codon = ((byte_value & 3) << 4);            codon += (byte_value1 >> 4);            *prot_seq = translation[codon];            prot_seq++;                        byte_value4 = *(++nt_seq);            /* case 2: */            codon = ((byte_value1 & 15) << 2);                        codon += (byte_value2 >> 6);            *prot_seq = translation[codon];            prot_seq++;            /* case 1: */            codon = byte_value2 & 63;            byte_value5 = *(++nt_seq);            *prot_seq = translation[codon];            prot_seq++;                        /* case 0: */            codon = (byte_value3 >> 2);            *prot_seq = translation[codon];            prot_seq++;            /* case 3: */            byte_value = *(++nt_seq);            codon = ((byte_value3 & 3) << 4);            codon += (byte_value4 >> 4);            *prot_seq = translation[codon];            prot_seq++;            /* case 2: */            codon = ((byte_value4 & 15) << 2);            codon += (byte_value5 >> 6);            *prot_seq = translation[codon];            prot_seq++;            /* case 1: */            codon = byte_value5 & 63;            *prot_seq = translation[codon];            prot_seq++;            state=0;         } /* end optimized while */         /********************************************/      } /* end while */            if (state == 1) {          /* This doesn't get done above, DON't do the state = 0            below if this is done. */         byte_value = *nt_seq;         codon = byte_value & 63;         state = 0;         *prot_seq = translation[codon];         prot_seq++;      } else if (state == 0) { /* This one doesn't get done above. */         byte_value = *nt_seq;         codon = ((byte_value) >> 2);         state = 3;         *prot_seq = translation[codon];         prot_seq++;      }      if (total_remainder >= CODON_LENGTH) {         byte_value = *(nt_seq_end);         last_byte = *(nt_seq_end+1);         if (state == 0) {            codon = (last_byte >> 2);         } else if (state == 2) {            codon = ((byte_value & 15) << 2);            codon += (last_byte >> 6);         } else if (state == 3)	{            codon = ((byte_value & 3) << 4);            codon += (last_byte >> 4);         }         *prot_seq = translation[codon];         prot_seq++;      }   } else {      nt_seq_start = (Uint1 *) nt_seq;      nt_seq += length/4;      state = remainder+frame;      /* Do we start in the last byte?  This one has the lowest order         bits set to represent the remainder, hence the odd coding here. */      if (state >= 0) {         last_byte = *nt_seq;         nt_seq--;         if (state == 0) {            codon = (last_byte >> 6);            byte_value = *nt_seq;            codon += ((byte_value & 15) << 2);            state = 1;         } else if (state == 1) {            codon = (last_byte >> 4);            byte_value = *nt_seq;            codon += ((byte_value & 3) << 4);            state = 2;         } else if (state == 2)	{            codon = (last_byte >> 2);            state = 3;         }         *prot_seq = translation[codon];         prot_seq++;      }	else {         state = 3 + (remainder + frame + 1);         nt_seq--;      }            byte_value = *nt_seq;	      /* If there's lots to do, advance to state 3, then enter fast loop */      while (nt_seq > nt_seq_start) {         switch (state) {         case 3:            codon = (byte_value & 63);            *prot_seq = translation[codon];            prot_seq++;            /* do state = 0 now, break is NOT missing. */         case 0:            codon = (byte_value >> 6);            nt_seq--;            byte_value = *nt_seq;	            codon += ((byte_value & 15) << 2);            *prot_seq = translation[codon];            prot_seq++;            if (nt_seq <= nt_seq_start)	{               state = 1;               break;            }            /* Go on to state = 2 if not at end. */         case 1:            codon = (byte_value >> 4);            nt_seq--;            byte_value = *nt_seq;            codon += ((byte_value & 3) << 4);            *prot_seq = translation[codon];            prot_seq++;            if (nt_seq <= nt_seq_start)	{               state = 2;               break;            }            /* Go on to state = 2 if not at end. */         case 2:            codon = (byte_value >> 2);            *prot_seq = translation[codon];            prot_seq++;            nt_seq--;            byte_value = *nt_seq;	            state = 3;            break;         } /* end switch */         /* switch ends at state 3, except when at end */                  /********************************************/         /* optimized area: start in state 0. continue til near end */         while (nt_seq > (nt_seq_start+10)) {            byte_value1 = *(--nt_seq);	            byte_value2 = *(--nt_seq);            byte_value3 = *(--nt_seq);                        codon = (byte_value & 63);            *prot_seq = translation[codon];            prot_seq++;            codon = (byte_value >> 6);            codon += ((byte_value1 & 15) << 2);            *prot_seq = translation[codon];            prot_seq++;            byte_value4 = *(--nt_seq);            codon = (byte_value1 >> 4);            codon += ((byte_value2 & 3) << 4);            *prot_seq = translation[codon];            prot_seq++;            codon = (byte_value2 >> 2);            *prot_seq = translation[codon];            prot_seq++;            byte_value5 = *(--nt_seq);                        codon = (byte_value3 & 63);            *prot_seq = translation[codon];            prot_seq++;            byte_value = *(--nt_seq);            codon = (byte_value3 >> 6);            codon += ((byte_value4 & 15) << 2);            *prot_seq = translation[codon];            prot_seq++;            codon = (byte_value4 >> 4);            codon += ((byte_value5 & 3) << 4);            *prot_seq = translation[codon];            prot_seq++;            codon = (byte_value5 >> 2);            *prot_seq = translation[codon];            prot_seq++;         } /* end optimized while */         /********************************************/               } /* end while */            byte_value = *nt_seq;      if (state == 3) {         codon = (byte_value & 63);         *prot_seq = translation[codon];         prot_seq++;      } else if (state == 2) {         codon = (byte_value >> 2);         *prot_seq = translation[codon];         prot_seq++;      }   }   *prot_seq = NULLB;      return (prot_seq - prot_seq_start);} /* BlastTranslateUnambiguousSequence *//* Reverse a nucleotide sequence in the ncbi4na encoding */Int2 GetReverseNuclSequence(const Uint1* sequence, Int4 length,                             Uint1** rev_sequence_ptr){   Uint1* rev_sequence;   Int4 index;   /* Conversion table from forward to reverse strand residue in the blastna       encoding */   Uint1 conversion_table[17] =       { 0, 8, 4, 12, 2, 10, 9, 14, 1, 6, 5, 13, 3, 11, 7, 15 };   if (!rev_sequence_ptr)      return -1;   rev_sequence = (Uint1*) malloc(length + 2);      rev_sequence[0] = rev_sequence[length+1] = NULLB;   for (index = 0; index < length; ++index) {      rev_sequence[length-index] = conversion_table[sequence[index]];   }   *rev_sequence_ptr = rev_sequence;   return 0;}Int2 BLAST_ContextToFrame(Uint1 prog_number, Int4 context_number){   Int2 frame=255;   if (prog_number == blast_type_blastn) {      if (context_number % 2 == 0)         frame = 1;      else         frame = -1;   } else if (prog_number == blast_type_blastp ||              prog_number == blast_type_rpsblast ||              prog_number == blast_type_tblastn ||              prog_number == blast_type_rpstblastn) {       /* Query and subject are protein, no frame. */      frame = 0;   } else if (prog_number == blast_type_blastx ||               prog_number == blast_type_tblastx) {      context_number = context_number % 6;      frame = (context_number < 3) ? context_number+1 : -context_number+2;   }      return frame;}Int4 BLAST_GetQueryLength(const BlastQueryInfo* query_info, Int4 context){   return query_info->context_offsets[context+1] -      query_info->context_offsets[context] - 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -