コード例 #1
0
ファイル: util.C プロジェクト: macmanes-lab/wgs-assembler
void
Sim4::free_align(edit_script_list *aligns) {
  edit_script_list *head;

  head = aligns;

  while ((head=aligns)!=NULL) {
    aligns = aligns->next_script;
    Free_script(head->script);
    ckfree(head);
  }
}
コード例 #2
0
ファイル: sim4.init.c プロジェクト: 5432935/crossbridge
static void
print_align_lat(uchar *seq1, uchar *seq2, result_p_t r)
{
  int *S;
  edit_script_list_p_t head, aligns;

  if (r->sList == NULL)
    return;
  aligns = r->sList;
  while (aligns != NULL) {
    head = aligns;
    aligns = aligns->next_script;
    S = (int *) xmalloc((2 * head->len2 + 1 + 1) * sizeof(int));
    S++;
    S2A(head->script, S, 0);
    Free_script(head->script);
    IDISPLAY(seq1 + head->offset1 - 1 - 1, seq2 + head->offset2 - 1 - 1,
	     head->len1, head->len2, S,
	     head->offset1, head->offset2, &r->eCol, r->direction);
    free(S - 1);
    free(head);
  }
  r->sList = NULL;
}
コード例 #3
0
ファイル: poly.c プロジェクト: gitpan/GH
/* s2 is the cdna */
static void trim_polyT_align(struct edit_script_list **Sptr, Exon **exons, const int ec, int *pT, uchar *s1, uchar *s2)
{
    edit_script_list *head = *Sptr;
    edit_script *tp;
    int tmpi = 0, num, idents = 0;
    uchar *a, *b;
    Exon *t;

    int i, j;  /* i index in the cDNA */

    if (ec<head->offset2) {
        *pT = ec; 
        return;
    }

    if (ec==head->offset2+head->len2-1) {
        /* cDNA gap: remove the entire script */
        *Sptr = head->next_script;
        Free_script(head->script);
        free(head);
        while ((*exons)->from2<ec) {
           t = *exons; *exons = t->next_exon; free(t);
        }
        *pT = ec;
        return;
    }
 
    i = head->offset2;
    j = head->offset1;
    tp = head->script;

    while (i<=ec && tp) {
       num = tp->num;
       switch (tp->op_type) {
          case INSERT:
                   if (i<=ec && ec<i+num-1) {
                       tmpi += ec-i+1; tp->num -= ec-i+1; i = ec+1; 
                   } else {
                       i += num; tmpi += num; head->script = tp->next; 
                       free(tp); tp = head->script; 
                   }
                   break;
          case DELETE:     
                   j += num; tmpi += num; head->script = tp->next;
                   free(tp); tp = head->script; 
                   break;
          case SUBSTITUTE:
                   if (i<=ec && ec<i+num-1) {
                       a = s2+i-1; b = s1+j-1;
                       while (a<s2+ec) {
                          if (*a++!=*b++) tmpi++; else idents++;
                       }
                       j += ec-i+1; tp->num -= ec-i+1; i = ec+1;
                   } else {
                       /* at most 1 nt remaining */
                       a = s2+i-1; b = s1+j-1;
                       while (a<s2+i+tp->num-1) {
                          if (*a++!=*b++) tmpi++; else idents++;
                       }

                       i +=num; j += num;
                       head->script = tp->next;
                       free(tp); tp = head->script; 
                   }
                   break;
          default: fatalf("Unrecognized opcode %d.\n",tp->op_type);
       }
       /* indel walk */
    }
    assert(i==ec+1);
     
    while (tp->op_type!=SUBSTITUTE && j-1<=(*exons)->to1) {
       if (tp->op_type==INSERT) {
           i += tp->num; tmpi += tp->num;
       } else if (j>=(*exons)->to1 && i>=(*exons)->to2) {
           j += tp->num;
       } else {
           j += tp->num; tmpi += tp->num;
       }
       head->script = tp->next;
       free(tp); tp = head->script;
    }
    
    if (head->script==NULL) {
        *Sptr = head->next_script;
        free(head);
    } else {
        head->len1 -= j-head->offset1;
        head->len2 -= i-head->offset2;
        head->offset2 = i;
        head->offset1 = j;          
        head->score -= tmpi;
    }

    if ((*exons)->to2<i) {
        t = *exons; *exons = t->next_exon; free(t);
    } else {
        double tmp_matches;
        (*exons)->from2 = i; 
        (*exons)->from1 = j;
        (*exons)->length = (*exons)->to2-(*exons)->from2+1;
        tmp_matches = (*exons)->nmatches - idents;
        (*exons)->alen -= tmpi+idents;
        (*exons)->match = (int)(100*tmp_matches/(*exons)->alen);
    }
    *pT = i-1;
    return;
}
コード例 #4
0
ファイル: poly.c プロジェクト: gitpan/GH
static void trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exons, const int bc, int *pA, uchar *s1,uchar *s2) 
{
    edit_script_list *head = *Sptr;
    edit_script *tp;
    int tmpi = 0, num, idents = 0;
    uchar *a, *b;
    Exon *prev;

    int i, j;  /* i index in the cDNA */

    if (bc>head->offset2+head->len2-1) {
        *pA = bc;
        return;
    }

    if (bc==head->offset2) {
        /* cDNA gap: remove the entire script; this should be properly sorted */
        *Sptr = head->next_script;
        Free_script(head->script);
        free(head);
        while ((*exons)->from2>=bc) {
           prev = find_previous(lblock,*exons);
           prev->next_exon = (*exons)->next_exon;
           free(*exons); *exons = prev;
        }
        *pA = bc;
        return;
    }

    Flip_script(&(head->script));
    i = head->offset2 + head->len2 -1;
    j = head->offset1 + head->len1 -1;
    tp = head->script;

    while (i>=bc && tp) {
       num = tp->num;
       switch (tp->op_type) {
          case INSERT:
                   if (i>=bc && bc>i-num+1) {
                       tmpi += i-bc+1; tp->num -= i-bc+1; i = bc-1;
                   } else {
                       i -= num; tmpi += num; head->script = tp->next;
                       free(tp); tp = head->script;
                   }
                   break;
          case DELETE:
                   j -= num; tmpi += num; head->script = tp->next;
                   free(tp); tp = head->script;
                   break;
          case SUBSTITUTE:
                   if (i>=bc && bc>i-num+1) {
                       a = s2+i-1; b = s1+j-1;
                       while (a>=s2+bc-1) {
                          if (*a--!=*b--) tmpi++; else idents++;
                       }
                       j -= i-bc+1; tp->num -= i-bc+1; i = bc-1;
                   } else {
                       /* at most 1 nt remaining */
                       a = s2+i-1; b = s1+j-1;
                       while (a>=s2+i-num) {
                          if (*a--!=*b--) tmpi++; else idents++;
                       }

                       i -= num; j -= num;
                       head->script = tp->next;
                       free(tp); tp = head->script;
                   }
                   break;
          default: fatalf("Unrecognized opcode %d.\n",tp->op_type);
       }
       /* indel walk */
    }
    assert(i==bc-1);

    while (tp->op_type!=SUBSTITUTE && j+1>=(*exons)->from1) {
       if (tp->op_type==INSERT) {
           i -= tp->num; tmpi += tp->num;
       } else if (j<(*exons)->from1 && i<(*exons)->from2) {
           j -= tp->num;
       } else {
           j -= tp->num; tmpi += tp->num;
       }
       head->script = tp->next;
       free(tp); tp = head->script;
    }

    if (head->script==NULL) {
        *Sptr = head->next_script;
        free(head);
    } else {
        head->len1 = j-head->offset1+1;
        head->len2 = i-head->offset2+1;
        head->score -= tmpi;
        Flip_script(&(head->script));
    }

    if ((*exons)->from2>i) {
        prev = find_previous(lblock,*exons);
        prev->next_exon = (*exons)->next_exon;
        free(*exons); *exons = prev;
    } else {
        double tmp_matches;
        (*exons)->to2 = i;
        (*exons)->to1 = j;
        (*exons)->length = (*exons)->to2-(*exons)->from2+1;
        tmp_matches = (*exons)->nmatches - idents;
        (*exons)->alen -= tmpi+idents;
        (*exons)->match = (int)(100*tmp_matches/(*exons)->alen);
    }
    *pA = i+1;

    return;
}
コード例 #5
0
ファイル: poly.C プロジェクト: macmanes-lab/wgs-assembler
void
Sim4::trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exons, const int bc, int *pA, char *s1,char *s2) 
{
  edit_script_list *head = *Sptr;
  edit_script *tp;
  int tmpi = 0, num, idents = 0, identsN = 0;
  char *a, *b;
  Exon *prev;

  int i, j;  /* i index in the cDNA */

  if (bc>head->offset2+head->len2-1) {
    *pA = bc;
    return;
  }

  if (bc==head->offset2) {
    /* cDNA gap: remove the entire script; is this properly sorted? LLL */
    *Sptr = head->next_script;
    Free_script(head->script);
    ckfree(head);
    while ((*exons)->frEST>=bc) {
      prev = find_previous(lblock,*exons);

      if (prev == 0L) {
        fprintf(stderr, "trim_polyA_align(): Corrupted exon list, cannot find the previous exon (remove entire script).\n");
        for (; lblock; lblock = lblock->next_exon)
          fprintf(stderr, "  GEN f=%8d t=%8d  EST f=%8d t=%8d   flag=%d\n",
                  lblock->frGEN, lblock->toGEN, lblock->frEST, lblock->toEST, lblock->flag);
        kill(getpid(), SIGKILL);
      }

      prev->next_exon = (*exons)->next_exon;
      //freeExon(*exons);  garbage collected
      *exons = prev;
    }
    *pA = bc;
    return;
  }

  Flip_script(&(head->script));
  i = head->offset2 + head->len2 -1;
  j = head->offset1 + head->len1 -1;
  tp = head->script;

  while (i>=bc && tp) {
    num = tp->num;
    switch (tp->op_type) {
      case INSERT:
        if (i>=bc && bc>i-num+1) {
          (*exons)->numInDel -= i - bc + 1;
          (*exons)->numEdits -= i - bc + 1;
          tmpi    += i-bc+1;
          tp->num -= i-bc+1;
          i        = bc-1;
        } else {
          (*exons)->numInDel -= num;
          (*exons)->numEdits -= num;
          tmpi += num;
          i    -= num;
          head->script = tp->next;
          ckfree(tp);
          tp = head->script;
        }
        break;
      case DELETE:
        (*exons)->numInDel -= num;
        (*exons)->numEdits -= num;
        j    -= num;
        tmpi += num;
        head->script = tp->next;
        ckfree(tp);
        tp = head->script;
        break;
      case SUBSTITUTE:
        if (i>=bc && bc>i-num+1) {
          a = s2+i-1; b = s1+j-1;
          while (a>=s2+bc-1) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a--;
            b--;
          }
          j -= i-bc+1; tp->num -= i-bc+1; i = bc-1;
        } else {
          /* at most 1 nt remaining */
          a = s2+i-1; b = s1+j-1;
          while (a>=s2+i-num) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a--;
            b--;
          }

          i -= num; j -= num;
          head->script = tp->next;
          ckfree(tp);
          tp = head->script;
        }
        break;
#if 0
      default:
        fatalf("Unrecognized opcode %d.\n",tp->op_type);
#endif
    }
    /* indel walk */
  }
  assert(i==bc-1);

  while ((tp != 0L) &&
         (tp->op_type != SUBSTITUTE) && (j+1 >= (*exons)->frGEN)) {
    if (tp->op_type==INSERT) {
      i -= tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    } else if (j<(*exons)->frGEN && i<(*exons)->frEST) {
      j -= tp->num;
    } else {
      j -= tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    }
    head->script = tp->next;
    ckfree(tp);
    tp = head->script;
  }

  if (head->script==NULL) {
    *Sptr = head->next_script;
    ckfree(head);
  } else {
    head->len1 = j-head->offset1+1;
    head->len2 = i-head->offset2+1;
    head->score -= tmpi;
    Flip_script(&(head->script));
  }

  if ((*exons)->frEST>i) {
    prev = find_previous(lblock,*exons);

    if (prev == 0L) {
      fprintf(stderr, "trim_polyA_align(): Corrupted exon list, cannot find the previous exon (frEST).\n");
      for (; lblock; lblock = lblock->next_exon)
        fprintf(stderr, "  GEN f=%8d t=%8d  EST f=%8d t=%8d   flag=%d\n",
                lblock->frGEN, lblock->toGEN, lblock->frEST, lblock->toEST, lblock->flag);
      kill(getpid(), SIGKILL);
    }

    prev->next_exon = (*exons)->next_exon;
    //freeExon(*exons);  garbage collected
    *exons = prev;
  } else {
    (*exons)->toEST = i;
    (*exons)->toGEN = j;
    (*exons)->length = (*exons)->toEST-(*exons)->frEST+1;

    (*exons)->alignmentLength = ((*exons)->toGEN - (*exons)->frGEN + 1 +
                                 (*exons)->toEST - (*exons)->frEST + 1 +
                                 (*exons)->numInDel);
    (*exons)->percentID   = computePercentIdentity((*exons)->numEdits,
                                                   (*exons)->alignmentLength);
  }
  *pA = i+1;

  return;
}
コード例 #6
0
ファイル: poly.C プロジェクト: macmanes-lab/wgs-assembler
/* s2 is the cdna */
void
Sim4::trim_polyT_align(struct edit_script_list **Sptr, Exon **exons, const int ec, int *pT, char *s1, char *s2)
{
  edit_script_list *head = *Sptr;
  edit_script *tp;
  int tmpi = 0, num, idents = 0, identsN = 0;
  char *a, *b;
  Exon *t;

  int i, j;  /* i index in the cDNA */

  if (ec<head->offset2) {
    *pT = ec; 
    return;
  }

  if (ec==head->offset2+head->len2-1) {
    /* cDNA gap: remove the entire script */
    *Sptr = head->next_script;
    Free_script(head->script);
    ckfree(head);
    while ((*exons)->frEST<ec) {
      t = *exons;
      *exons = t->next_exon;
      //freeExon(t);  garbage collected
    }
    *pT = ec;
    return;
  }
 
  i = head->offset2;
  j = head->offset1;
  tp = head->script;

  while (i<=ec && tp) {
    num = tp->num;
    switch (tp->op_type) {
      case INSERT:
        if (i<=ec && ec<i+num-1) {
          (*exons)->numInDel -= ec - i + 1;
          (*exons)->numEdits -= ec - i + 1;
          tmpi    += ec-i+1;
          tp->num -= ec-i+1;
          i        = ec+1; 
        } else {
          (*exons)->numInDel -= num;
          (*exons)->numEdits -= num;
          tmpi += num;
          i    += num;
          head->script = tp->next; 
          ckfree(tp);
          tp = head->script; 
        }
        break;
      case DELETE:     
        (*exons)->numInDel -= num;
        (*exons)->numEdits -= num;
        j    += num;
        tmpi += num;
        head->script = tp->next;
        ckfree(tp);
        tp = head->script; 
        break;
      case SUBSTITUTE:
        if (i<=ec && ec<i+num-1) {
          a = s2+i-1; b = s1+j-1;
          while (a<s2+ec) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a++;
            b++;
          }
          j += ec-i+1; tp->num -= ec-i+1; i = ec+1;
        } else {
          /* at most 1 nt remaining */
          a = s2+i-1; b = s1+j-1;
          while (a<s2+i+tp->num-1) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a++;
            b++;
          }

          i +=num; j += num;
          head->script = tp->next;
          ckfree(tp);
          tp = head->script; 
        }
        break;
    }
    /* indel walk */
  }
  assert(i==ec+1);

  while ((tp != 0L) &&
         (tp->op_type!=SUBSTITUTE) && (j-1<=(*exons)->toGEN)) {
    if (tp->op_type==INSERT) {
      i += tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    } else if (j>=(*exons)->toGEN && i>=(*exons)->toEST) {
      j += tp->num;
    } else {
      j += tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    }
    head->script = tp->next;
    ckfree(tp);
    tp = head->script;
  }
    
  if (head->script==NULL) {
    *Sptr = head->next_script;
    ckfree(head);
  } else {
    head->len1 -= j-head->offset1;
    head->len2 -= i-head->offset2;
    head->offset2 = i;
    head->offset1 = j;          
    head->score -= tmpi;
  }

  if ((*exons)->toEST<i) {
    t = *exons;
    *exons = t->next_exon;
    //freeExon(t);  garbage collected
  } else {
    (*exons)->frEST = i; 
    (*exons)->frGEN = j;
    (*exons)->length = (*exons)->toEST-(*exons)->frEST+1;

    (*exons)->alignmentLength = ((*exons)->toGEN - (*exons)->frGEN + 1 +
                                 (*exons)->toEST - (*exons)->frEST + 1 +
                                 (*exons)->numInDel);
    (*exons)->percentID   = computePercentIdentity((*exons)->numEdits,
                                                   (*exons)->alignmentLength);
  }
  *pT = i-1;
  return;
}