Exemple #1
0
cDNA * get_cDNA_from_Transcript(Transcript * trs)
{
  Genomic * gn;
  Sequence * base;
  int i;
  char buffer[64];


  if( trs->cDNA != NULL) 
    return trs->cDNA;

  if( trs->parent == NULL ) {
    warn("Cannot get cDNA, as no parent Gene!");
    return NULL;
  }

  if ( (gn = get_Genomic_from_Gene(trs->parent)) == NULL  ) {
    warn("Cannot get cDNA, as cannot get Genomic sequence from Gene");
    return NULL;
  }

  base = Sequence_alloc();
  sprintf(buffer,"%s.sp",Genomic_name(gn));
  base->name = stringalloc(buffer);
  base->seq = ckcalloc(length_Transcript(trs)+1,sizeof(char));
  base->seq[0]='\0';
  

  for(i=0;i<trs->ex_len;i++) {
    strncat(base->seq,gn->baseseq->seq+trs->exon[i]->start,trs->exon[i]->end-trs->exon[i]->start);
  }
  make_len_type_Sequence(base);
  base->type = SEQUENCE_CDNA;
  trs->cDNA = cDNA_from_Sequence(base);

  return trs->cDNA;
}
Protein * get_Protein_from_Translation(Translation * ts,CodonTable * ct)
{
  cDNA * cd;
  int i,j;
  Sequence * seq;
  char buffer[64];

  assert(ts);
  assert(ct);

  /*  fprintf(stderr,"Codon table is %d\n",ct);*/

  if( ts->protein != NULL)
    return ts->protein;

  if( ts->parent == NULL ) {
    warn("Cannot get Protein from translation as no parent!");
    return NULL;
  }


  cd = get_cDNA_from_Transcript(ts->parent);

  if( cd == NULL ) {
    warn("Cannot make translation as can't get transcript!");
    return NULL;
  }

  if( cd->baseseq == NULL ) {
    warn("A bad error - a non NULL cDNA with a null sequence object. No translation here!");
    return NULL;
  }
  if( cd->baseseq->len == 0 ) {
    warn("Attempting to translate a zero length cDNA. Yikes!");
    return NULL;
  }

  seq = Sequence_alloc();
  sprintf(buffer,"%s.tr",cDNA_name(cd));
  seq->name = stringalloc(buffer);
  seq->seq = ckcalloc((cd->baseseq->len/3) + 2,sizeof(char));
  seq->type = SEQUENCE_PROTEIN;

  if( cd->baseseq->len%3 != 0 ) {
    warn("Problem in making translation, cDNA is not mod3! - length is %d - transcript id %s",cd->baseseq->len,seq->name);
  }


  for(i=0,j=0;i<cd->baseseq->len;i+=3,j++) {
    if( is_stop_codon(codon_from_seq(cd->baseseq->seq+i),ct) == TRUE ) {
      if( i+3 >= cd->baseseq->len ) 
	break;
      else {
	warn("Got a stop codon in the middle of a translation at postion [%d]. Yuk!",i);
	seq->seq[j] = '*';
      }
    } else {
      seq->seq[j] = aminoacid_from_seq(ct,cd->baseseq->seq+i);

    }
  }
  seq->seq[j]='\0';
  make_len_type_Sequence(seq);

  /*write_fasta_Sequence(seq,stdout);*/
  seq->type = SEQUENCE_PROTEIN;
  ts->protein = Protein_from_Sequence(seq);

  return ts->protein;

}