[Previous] [Up]
Go backward to Header File
Go up to Output Module  

Executable Code

File name: print.c.
#include <stdio.h>
#include "struct.h"             /* Oligo,Sym */
#include "bases.h"              /* print_bases() */
 
void print_parse ( strand, len, order, syms, nsyms )
     int *strand;
     int len;
     int order;  /* Order strand is given in, 0 = 5'->3', 1 = 3'->5' */
     Sym *syms;
     int nsyms;
{
  int start,i,j;
  start=0;
  while(start<len){
    int found=0;
    int best_len = 0;
    int best_sym,l;
    for(i=0;i<nsyms;i++){
      if (best_len < syms[i].len && syms[i].len <= len-start){
        int match=1,rmatch=1;
        if (order == NORMAL_ORDER) {
          for(j=0;j<syms[i].len;j++) {
            if (strand[start+j] != syms[i].bases[j]) {
              match=0;
              break;
            }
          }
          for(j=0;j<syms[i].len;j++) {
            if (strand[start+j] != (syms[i].bases[syms[i].len-1-j]^2)) {
              rmatch=0;
              break;
            }
          }
        } else {  /* Strand is given in reverse (3'->5') order. */
          for(j=0;j<syms[i].len;j++){
            if (strand[start+j] != syms[i].bases[syms[i].len-1-j]) {
              match = 0;
              break;
            }
          }
          for(j=0;j<syms[i].len;j++){
            if (strand[start+j] != (syms[i].bases[j]^2)) {
              rmatch = 0;
              break;
            }
          }
        }
 
        if (match || rmatch) {
          found = match?1:-1;
          best_sym = i;
          best_len = syms[i].len;
        }
      }
    }
 
    if (found) {
      i = best_sym;
 
      if (found == 1) {
        l = strlen(syms[i].name);
        if (l > syms[i].len-2) {
          for(j=0;j<syms[i].len;j++){
            if (j<l)
              putchar(syms[i].name[j]);
            else
              putchar('_');
          }
        } else {
          putchar('[');
          for(j=0;j<syms[i].len-2;j++){
            if (j<l)
              putchar(syms[i].name[j]);
            else
              putchar(' ');
          }
          putchar(']');
        }
      } else {
        l = strlen(syms[i].name);
        if (l > syms[i].len-3) {
          putchar('!');
          for(j=0;j<syms[i].len-1;j++){
            if (j<l)
              putchar(syms[i].name[j]);
            else
              putchar('_');
          }
        } else {
          printf("[!");
          for(j=0;j<syms[i].len-3;j++){
            if (j<l)
              putchar(syms[i].name[j]);
            else
              putchar(' ');
          }
          putchar(']');
        }
      }
 
      start+=syms[i].len;
    } else {
      printf("?");
      start++;
    }
  }
}
 
void print_binders(rstrand,len,occupy,oligos,syms,nsyms)
     int *rstrand;
     int len;
     int *occupy;
     Oligo *oligos;
     Sym *syms;
     int nsyms;
{
  int i,j,o,change;
 
  /* Print a line showing the parse of the binders. */
  for(i=0;i<len;i++){
    if (occupy[i]>=0) {
      o = occupy[i];
      print_parse (oligos[o].bases, oligos[o].len, NORMAL_ORDER, syms, nsyms);
      i+=oligos[o].len-1;
    } else {
      printf(" ");
    }
  }
  printf("\n");
 
  /* Print a line showing the base-sequence of the binders. */
  for(i=0;i<len;i++){
    if (occupy[i] >= 0) {
      o = occupy[i]; j=0;
      print_bases(oligos[o].bases,oligos[o].len);
      i+=oligos[o].len-1;
    } else {
      printf(" ");
    }
  }
  printf("\n");
 
  /* Display a line showing where matches & mismatches are. */
  for(i=0;i<len;i++){
    if (occupy[i]>=0) {
      o = occupy[i];
      j = 0;
    }
    if (occupy[i]>=-1) {
      if (rstrand[i] != (oligos[o].bases[j++]^2))
        printf("X");
      else
        printf(":");
    } else {
      printf(" ");
    }
  }
  printf("\n");
 
  /* Print a line showing the bases of the template strand. */
  print_bases(rstrand,len); printf("\n");
 
  /* Print the parse of the template strand. */
  print_parse(rstrand,len, REVERSE_ORDER,syms,nsyms); printf("\n");
}

- Michael P. Frank, September 12, 1995. Formatted using HyperLaTeX-1.3.

[Previous] [Up]