/* ---------------- score_mat_string --------------------------
 * This is not a score routine, it is not an alignment routine.
 * Maybe it should go in its own file.
 * Here are the tricks to remember.
 * Our M+N score matrix is actually (M+2)(M+2) so as to allow
 * for empty places and end-gaps. You don't have to use them if
 * you don't like them.
 * The loops below are far more elegant if we temporarily store
 * the strings with end bits at start and end.
 */
char *
score_mat_string (struct score_mat *smat, struct seq *s1, struct seq *s2)
{
    char *ret = NULL;
    char *str1, *str2;
    size_t n_rows = smat->n_rows;
    size_t n_cols = smat->n_cols;
    size_t i, j;
    const char *c_fmt = "%4c ";
    const char *f_fmt = "%4.2f ";
    const char *hat   = "^";
    seq_thomas2std (s1);
    seq_thomas2std (s2);
    str1 = save_str (hat);
    str1 = save_str_append (str1, s1->seq);
    str1 = save_str_append (str1, hat);
    str2 = save_str (hat);
    str2 = save_str_append (str2, s2->seq);
    str2 = save_str_append (str2, hat);

    scr_reset();
    scr_printf (c_fmt, ' ');
    for ( i = 0; i < n_cols; i++)
        scr_printf (c_fmt, str2[i]);
    scr_printf ("\n");
    for ( i = 0; i < n_rows; i++) {
        scr_printf (c_fmt, str1[i]);
        for ( j = 0 ; j < n_cols; j++)
            scr_printf (f_fmt, smat->mat[i][j]);
        ret = scr_printf ("\n");
    }
    free (str1);
    free (str2);
    return (ret);
}
/* ---------------- sub_mat_string ----------------------------
 */
char *
sub_mat_string (const struct sub_mat * smat)
{
    char *ret;
    int i, j;
    const char *cfmt = " %4c";
    const char *ffmt = " %4.1f";
    scr_reset();
    scr_printf ("Substitution matrix from file %s\n", smat->fname);
    if (smat -> comment)
        scr_printf ("File began with comment:\n%s\n", smat->comment);
    scr_printf (cfmt, ' ');
    for (i = 0; i < MAX_AA; i++)
        scr_printf (cfmt, thomas2std_char (i));

    scr_printf ("\n");
    for (i = 0; i < MAX_AA; i++) {
        scr_printf (cfmt, thomas2std_char (i));
        for ( j = 0; j < MAX_AA; j++) {
            mat_t x = smat->data [i] [j];
            if (x == INVALID)
                scr_printf (cfmt, '?');
            else
                scr_printf (ffmt, x);
            }
        ret = scr_printf ("\n");
    }
    return (ret);
}
/* ---------------- pair_set_chimera  --------------------------
 * Given an alignment, write pairs of atoms to a file in a format
 * that chimera can read.
 * We return a char * to space which is allocated by the
 * scr_printf() routines.
 */
char *
pair_set_chimera (struct pair_set *pair_set,
                  const struct coord *c1, const struct coord *c2)
{
    const char *this_sub = "pair_set_chimera";
    int **p;
    char *s1 = NULL;
    char *s2 = NULL;
    char *ret;
    size_t i;
    if (pair_set->n == 0) {
        err_printf (this_sub, "empty pair set\n");
        return NULL;
    }
    s1 = save_str ("#0");
    s2 = save_str ("#1");
    p = pair_set->indices;
    for ( i = 0; i < pair_set->n; i++) {
        int a = p[i][0], b = p[i][1];
        if (( a != GAP_INDEX) && ( b != GAP_INDEX)) {
            s1 = add_res (s1, a, c1);
            s2 = add_res (s2, b, c2);
        }
    }
    scr_reset();
    ret = scr_printf ("match %s %s", s1, s2);
    free (s1);
    free (s2);
    return (ret);
}
Exemple #4
0
/*
 * Redraw window after exposure or size change
 */
static void
resize_window1 (unsigned int width, unsigned int height)
{
  static short first_time = 1;
  int new_ncol = (width - szHint.base_width) / TermWin.fwidth;
  int new_nrow = (height - szHint.base_height) / TermWin.fheight;

  if (first_time ||
      (new_ncol != TermWin.ncol) ||
      (new_nrow != TermWin.nrow))
    {
      int curr_screen = -1;

      /* scr_reset only works on the primary screen */
      if (!first_time)		/* this is not the first time thru */
	{
	  selection_clear ();
	  curr_screen = scr_change_screen (PRIMARY);
	}

      TermWin.ncol = new_ncol;
      TermWin.nrow = new_nrow;

      resize_subwindows (width, height);
      scr_reset ();

      if (curr_screen >= 0)	/* this is not the first time thru */
	scr_change_screen (curr_screen);
      first_time = 0;
    }
}
/* ---------------- funcs2_char --------------------------------
 */
char *
funcs2_char ( void )
{
    static int i = 0;
    const char *this_sub = "funcs2_char";
    scr_reset ();
    scr_printf ("This is %s. I am being called %d times.\n", this_sub, ++i);
    scr_printf ("Call2 from %s", this_sub);
    return (scr_printf ("-Third-%s\n", this_sub));
}
/* ---------------- funcs1_char --------------------------------
 */
char *
funcs1_char ( char *in )
{
    static int i = 0;
    char s[256];
    const char *this_sub = "funcs1_char";
    sprintf (s, "%s has been called %d times and was given %s",
             this_sub, ++i, in);
    scr_reset ();
    return (scr_printf ("%s", s));
}
/* ---------------- prob_vec_info    --------------------------
 * Print information about the probability vector.
 * This uses the ugly machinery to write into scratch space.
 * Changed so it always writes out the total of probabilities
 * and the sum of squares of probabilities.
 */
char *
prob_vec_info (struct prob_vec *p_v)
{
    char *ret = NULL;
    float *totals, *total2;
    size_t i, j, k, m, n, tomall;
    if (p_v -> mship == NULL)
        prob_vec_expand (p_v);
    scr_reset();
    scr_printf ("# Probability vector as ");
    if (p_v->norm_type == PVEC_TRUE_PROB)
        scr_printf ("true probability form\n");
    else if ( p_v->norm_type == PVEC_UNIT_VEC)
        scr_printf ("unit vector normalised\n");
    else
        scr_printf ("unknown normalised form\n");
    scr_printf ("#   protein length: %u ", (unsigned) p_v->prot_len);
    scr_printf (" num vectors: %u ", (unsigned) p_v->n_pvec);
    scr_printf (" fragment length: %u ", (unsigned) p_v->frag_len);
    scr_printf (" num classes: %u\n", (unsigned) p_v->n_class);
    scr_printf ("# res   class\n");
    scr_printf ("# num");
    for (i = 0; i < p_v->n_class; i++)
        scr_printf ("%8d", i + 1);
    scr_printf ("%8s", "total");
    scr_printf ("%8s", "tot^2");
    scr_printf ("\n");
    tomall = p_v->n_pvec * sizeof (totals[0]);
    totals = E_MALLOC (tomall);
    memset (totals, 0, tomall);
    total2 = E_MALLOC (tomall);
    memset (total2, 0, tomall);
    for (j = 0; j < p_v->n_pvec; j++) {
        for (k = 0; k < p_v->n_class; k++) {
            totals [j] += p_v->mship [j][k];
            total2 [j] += (p_v->mship [j][k] * p_v->mship [j][k]);
        }
    }

    for (m = 0; m < p_v->n_pvec; m++) {
        scr_printf ("%5u ", m);
        for (n = 0; n < p_v->n_class; n++)
            scr_printf ("%7.2g ", p_v->mship[m][n]);
        scr_printf ("%7.2g %7.2g", totals[m], total2[m]);
        ret = scr_printf ("\n");
    }
    free (totals);
    free (total2);
    return ret;
}
Exemple #8
0
/*{{{ main() */
int
main (int argc, char *argv[])
{
  int i;
  char *val, **cmd_argv = NULL;
  /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */
  static char windowid_string[20], *display_string;

  for (i = 0; i < argc; i++)
    {
      if (!strcmp (argv[i], "-e"))
	{
	  argc = i;
	  argv[argc] = NULL;
	  if (argv[argc + 1] != NULL)
	    {
	      cmd_argv = (argv + argc + 1);
	      if (cmd_argv[0] != NULL)
		rs_iconName = rs_title = my_basename (cmd_argv[0]);
	    }
	  break;
	}
    }

  rs_name = my_basename (argv[0]);

  /*
   * Open display, get options/resources and create the window
   */
  if ((display_name = getenv ("DISPLAY")) == NULL)
    display_name = ":0";

  get_options (argc, argv);

  Xdisplay = XOpenDisplay (display_name);
  if (!Xdisplay)
    {
      print_error ("can't open display %s", display_name);
      exit (EXIT_FAILURE);
    }
  extract_resources (Xdisplay, rs_name);

  /*
   * set any defaults not already set
   */
  if (!rs_title)
    rs_title = rs_name;
  if (!rs_iconName)
    rs_iconName = rs_name;
  if (!rs_saveLines || (TermWin.saveLines = atoi (rs_saveLines)) < 0)
    TermWin.saveLines = SAVELINES;

  /* no point having a scrollbar without having any scrollback! */
  if (!TermWin.saveLines)
    Options &= ~Opt_scrollBar;

#ifdef PRINTPIPE
  if (!rs_print_pipe)
    rs_print_pipe = PRINTPIPE;
#endif
  if (!rs_cutchars)
    rs_cutchars = CUTCHARS;

#ifndef NO_BOLDFONT
  if (rs_font[0] == NULL && rs_boldFont != NULL)
    {
      rs_font[0] = rs_boldFont;
      rs_boldFont = NULL;
    }
#endif
  for (i = 0; i < NFONTS; i++)
    {
      if (!rs_font[i])
	rs_font[i] = def_fontName[i];
#ifdef KANJI
      if (!rs_kfont[i])
	rs_kfont[i] = def_kfontName[i];
#endif
    }

#ifdef XTERM_REVERSE_VIDEO
  /* this is how xterm implements reverseVideo */
  if (Options & Opt_reverseVideo)
    {
      if (!rs_color[fgColor])
	rs_color[fgColor] = def_colorName[bgColor];
      if (!rs_color[bgColor])
	rs_color[bgColor] = def_colorName[fgColor];
    }
#endif

  for (i = 0; i < NRS_COLORS; i++)
    if (!rs_color[i])
      rs_color[i] = def_colorName[i];

#ifndef XTERM_REVERSE_VIDEO
  /* this is how we implement reverseVideo */
  if (Options & Opt_reverseVideo)
    {
      const char *name;
      /* swap foreground/background colors */

      name = rs_color[fgColor];
      rs_color[fgColor] = rs_color[bgColor];
      rs_color[bgColor] = name;

      name = def_colorName[fgColor];
      def_colorName[fgColor] = def_colorName[bgColor];
      def_colorName[bgColor] = name;
    }
#endif

  /* convenient aliases for setting fg/bg to colors */
  color_aliases (fgColor);
  color_aliases (bgColor);
#ifndef NO_CURSORCOLOR
  color_aliases (cursorColor);
  color_aliases (cursorColor2);
#endif /* NO_CURSORCOLOR */
#ifndef NO_BOLDUNDERLINE
  color_aliases (colorBD);
  color_aliases (colorUL);
#endif /* NO_BOLDUNDERLINE */

  Create_Windows (argc, argv);
  scr_reset ();			/* initialize screen */
  Gr_reset ();			/* reset graphics */

  /* add scrollBar, do it directly to avoid resize() */
  scrollbar_mapping (Options & Opt_scrollBar);

#ifdef DEBUG_X
  XSynchronize (Xdisplay, True);
  XSetErrorHandler ((XErrorHandler) abort);
#else
  XSetErrorHandler ((XErrorHandler) xerror_handler);
#endif

#ifdef DISPLAY_IS_IP
  /* Fixup display_name for export over pty to any interested terminal
   * clients via "ESC[7n" (e.g. shells).  Note we use the pure IP number
   * (for the first non-loopback interface) that we get from
   * network_display().  This is more "name-resolution-portable", if you
   * will, and probably allows for faster x-client startup if your name
   * server is beyond a slow link or overloaded at client startup.  Of
   * course that only helps the shell's child processes, not us.
   *
   * Giving out the display_name also affords a potential security hole
   */
  val = display_name = network_display (display_name);
  if (val == NULL)
#endif /* DISPLAY_IS_IP */
    val = XDisplayString (Xdisplay);
  if (display_name == NULL)
    display_name = val;		/* use broken `:0' value */

  i = strlen (val);
  display_string = MALLOC ((i + 9) * sizeof (char), "display_string");

  sprintf (display_string, "DISPLAY=%s", val);
  sprintf (windowid_string, "WINDOWID=%u", (unsigned int) TermWin.parent);

  /* add entries to the environment:
   * @ DISPLAY:   in case we started with -display
   * @ WINDOWID:  X window id number of the window
   * @ COLORTERM: terminal sub-name and also indicates its color
   * @ TERM:      terminal name
   */
  putenv (display_string);
  putenv (windowid_string);
  if (Xdepth <= 2)
    {
      putenv ("COLORTERM=" COLORTERMENV "-mono");
      putenv ("TERM=" TERMENV);
    }
  else
    {
#ifdef XPM_BACKGROUND
      putenv ("COLORTERM=" COLORTERMENV "-xpm");
#else
      putenv ("COLORTERM=" COLORTERMENV);
#endif
#ifdef DEFINE_XTERM_COLOR
      putenv ("TERM=" TERMENV "-color");
#else
      putenv ("TERM=" TERMENV);
#endif
    }

  init_command (cmd_argv);
  main_loop ();			/* main processing loop */
  return EXIT_SUCCESS;
}