Ejemplo n.º 1
0
static void
print_rest(FILE *f, const p3_global_settings *pa,
           const seq_args *sa,
           const pair_array_t *best_pairs)
{
    int i;
    int print_lib_sim = lib_sim_specified(pa);


    fprintf(f, "ADDITIONAL OLIGOS\n");
    fprintf(f, "  ");
    print_oligo_header(f, "", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
    for (i = 1; i < best_pairs->num_pairs; i++) {
        fprintf(f, "\n%2d ", i);

        if(pa->modify_left_primer==1) {
            print_oligo_Z(f, TITLE_MOD_LEFT, sa, best_pairs->pairs[i].left, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
        } else {
            print_oligo_Z(f, TITLE_LEFT, sa, best_pairs->pairs[i].left, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
        }

        fprintf(f, "   ");
        if(pa->modify_right_primer==1) {
            print_oligo_Z(f, TITLE_MOD_RIGHT, sa, best_pairs->pairs[i].right, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
        } else {
            print_oligo_Z(f, TITLE_RIGHT, sa, best_pairs->pairs[i].right, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
        }

        if(pa->pick_internal_oligo==1) {
            fprintf(f, "   ");
            if(pa->modify_internal_oligo==1) {
                /* Modified internal oligo */
                /* printing internal_oligo_direction - 20121204 N.Kasahara */
                if((best_pairs->pairs[i].intl)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_MOD_INTL_FW,sa, best_pairs->pairs[i].intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                } else if((best_pairs->pairs[i].intl)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_MOD_INTL_RV,sa, best_pairs->pairs[i].intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                }
            } else {
                /* Normal internal oligo */
                /* printing internal_oligo_direction - 20121204 N.Kasahara */
                if((best_pairs->pairs[i].intl)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_INTL_FW, sa, best_pairs->pairs[i].intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                } else if((best_pairs->pairs[i].intl)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_INTL_RV, sa, best_pairs->pairs[i].intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                }
            }
        }
        if (best_pairs->pairs[i].product_size > 0) {
            fprintf(f, "   ");
            print_pair_info(f, &best_pairs->pairs[i], pa);
            /* Print penalty score - Y.Kimura */
            fprintf(f, "   ");
            fprintf(f, "penalty score: %.4f\n", best_pairs->pairs[i].pair_quality);
        }
    }
}
Ejemplo n.º 2
0
static void
format_pairs(FILE *f,
             const p3_global_settings *pa,
             const seq_args *sa,
             const p3retval *retval,
             const pair_array_t *best_pairs,
             const char *pr_release,
             const pr_append_str *combined_retval_err,
             int explain_flag)
{
  char *warning;
  int print_lib_sim = lib_sim_specified(pa);
  primer_rec *h = NULL;

  PR_ASSERT(NULL != f);
  PR_ASSERT(NULL != pa);
  PR_ASSERT(NULL != sa);
  
  /* If there are errors, print them and return */
  if (!pr_is_empty(combined_retval_err)) {
    format_error(f, sa->sequence_name, 
                 pr_append_str_chars(combined_retval_err));
    return;
    }
  
  /* Print the sequence name if it is provided */
  if (NULL != sa->sequence_name)
    fprintf(f, "PRIMER PICKING RESULTS FOR %s\n\n", sa->sequence_name);
  
  /* Print if a mispriming libraby was used and which one */
  if (pa->p_args.repeat_lib != NULL)
    fprintf(f, "Using mispriming library %s\n",
            pa->p_args.repeat_lib->repeat_file);
  else
    fprintf(f, "No mispriming library specified\n");

  /* Print if a mispriming libraby for the internal oligo 
   * was used and which one */
  if ( pa->pick_internal_oligo == 1 ) {
    if (pa->o_args.repeat_lib != NULL)
      fprintf(f, "Using internal oligo mishyb library %s\n",
              pa->o_args.repeat_lib->repeat_file);
    else
      fprintf(f, "No internal oligo mishyb library specified\n");
  }

  /* Does the sequence start at position 0 or 1 ? */
  fprintf(f, "Using %d-based sequence positions\n",
          pa->first_base_index);
  
  /* Complain if no primers are in the array */
  if (best_pairs->num_pairs == 0) fprintf(f, "NO PRIMERS FOUND\n\n");
  
  /* Print out the warings */
  if ((warning = p3_get_rv_and_gs_warnings(retval, pa)) != NULL) {
    fprintf(f, "WARNING: %s\n\n", warning);
    free(warning);
  }
  
  /* Print the results for the best pair */
  print_summary(f, pa, sa, best_pairs, 0);
  fprintf(f, "\n");

  /* Print nicely out the sequence with the best pair */
  if (print_seq(f, pa, sa, retval, h, best_pairs, 0)) exit(-2); /* ENOMEM */
  
  /* Print out the alternative pairs */
  if (best_pairs->num_pairs > 1 ) print_rest(f, pa, sa, best_pairs);
  
  /* Print the primer picking statistics */
  if (explain_flag)
    print_explain(f, pa, sa, retval, print_lib_sim, pr_release);
  
  /* Flush the buffers and return */
  fprintf(f, "\n\n");
  if (fflush(f) == EOF) {
    perror("fflush(f) failed");
    exit(-1);
  }

}
Ejemplo n.º 3
0
/* add branching condition for printing internal_oligo_direction and modification
 * Created - 20121204 N.Kasahara
 * Modified - 20140109 Y.Kimura
 */
static void
print_summary(FILE *f, const p3_global_settings *pa,
              const seq_args *sa, const pair_array_t *best_pairs,
              int num)
{
    int seq_len = strlen(sa->sequence);
    int print_lib_sim = lib_sim_specified(pa);
    primer_pair *p;
    p = best_pairs->pairs + num;


    if (best_pairs->num_pairs > 0) {
        /*
         * If the following format changes, also change the format in print_oligo.
         */
        print_oligo_header(f, "\nOLIGO ", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
        if(pa->modify_left_primer==1) {
            print_oligo_Z(f, TITLE_MOD_LEFT, sa, p->left, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
        } else {
            print_oligo_Z(f, TITLE_LEFT, sa, p->left, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
        }

        if(pa->modify_right_primer==1) {
            print_oligo_Z(f, TITLE_MOD_RIGHT, sa, p->right, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
        } else {
            print_oligo_Z(f, TITLE_RIGHT, sa, p->right, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
        }

        if ( pa->pick_internal_oligo == 1 ) {
            if(pa->modify_internal_oligo==1) {
                /* Modified internal probe */
                if((p->intl)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_MOD_INTL_FW, sa, p->intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                } else if((p->intl)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_MOD_INTL_RV, sa, p->intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                }
            } else {
                /* Internal probe */
                if((p->intl)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_INTL_FW, sa, p->intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                } else if((p->intl)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_INTL_RV, sa, p->intl, OT_INTL, pa, pa->o_args.repeat_lib, print_lib_sim);
                }
            }
        }
    }
    if (best_pairs->num_pairs > 0) {
        print_pair_info(f, p, pa);
        /* Print penalty score - Y.Kimura */
        fprintf(f, "penalty score: %.4f\n", p->pair_quality);
    }
    fprintf(f, "\n");
    fprintf(f, "SEQUENCE SIZE: %d\n", seq_len);
    fprintf(f, "INCLUDED REGION SIZE: %d\n", sa->incl_l);
    if(sa->tar2.genotyping==0) {
        print_pair_array(f, "TARGETS", sa->tar2.count, sa->tar2.pairs, pa, sa);
    } else if(sa->tar2.genotyping==1) {
        fprintf(f,"TARGET VARIANT * (position,size):");
        if(sa->tar2.char_count==sa->tar2.VAR_sequence_number) {
            fprintf(f," %d,%d",sa->tar2.VAR_start[0],sa->tar2.char_num[sa->tar2.VAR_sequence_number]-1);
        } else {
            fprintf(f," %d,%d",sa->tar2.VAR_start[0],sa->tar2.char_num[sa->tar2.VAR_sequence_number]);
        }
        fprintf(f,"\n\n");
    }
    print_pair_array(f, "EXCLUDED REGIONS", sa->excl2.count, sa->excl2.pairs, pa, sa);
    print_pair_array(f, "INTERNAL PROBE EXCLUDED REGIONS", sa->excl_internal2.count, sa->excl_internal2.pairs, pa, sa);
    print_2_pair_array(f, "PAIR_OK_REGIONS", sa->ok_regions.count, sa->ok_regions.left_pairs, sa->ok_regions.right_pairs, pa, sa);
}
Ejemplo n.º 4
0
static void
format_oligos(FILE *f,
              const p3_global_settings *pa,
              const seq_args    *sa,
              const p3retval *retval,
              const char* pr_release,
              const pr_append_str *combined_retval_err,
              int explain_flag)
{
    char *warning;
    int print_lib_sim = lib_sim_specified(pa);
    int i;
    int print_primers = 0;
    primer_rec  *h = NULL;
    pair_array_t *best_pairs;
    primer_rec *p;
    int rest_count = 0;

    PR_ASSERT(NULL != f);
    PR_ASSERT(NULL != pa);
    PR_ASSERT(NULL != sa);

    best_pairs = NULL;

    if (!pr_is_empty(combined_retval_err)) {
        format_error(f, sa->sequence_name, pr_append_str_chars(combined_retval_err));
        return;
    }

    if (NULL != sa->sequence_name)
        fprintf(f, "PRIMER PICKING RESULTS FOR %s\n\n", sa->sequence_name);
    if (pa->pick_left_primer || pa->pick_right_primer) {
        if (pa->p_args.repeat_lib != NULL)
            fprintf(f, "Using mispriming library %s\n",
                    pa->p_args.repeat_lib->repeat_file);
        else
            fprintf(f, "No mispriming library specified\n");
    }
    if (pa->pick_internal_oligo) {
        if (pa->o_args.repeat_lib != NULL)
            fprintf(f, "Using internal probe mishyb library %s\n", pa->o_args.repeat_lib->repeat_file);
        else
            fprintf(f, "No internal probe mishyb library specified\n");
    }
    fprintf(f, "Using %d-based sequence positions\n", pa->first_base_index);

    if (pa->pick_left_primer) {
        if (retval->fwd.num_elem == 0) {
            fprintf(f, "NO LEFT PRIMER FOUND\n\n");
        } else {
            print_primers = 1;
        }
    }
    if (pa->pick_internal_oligo) {
        if (retval->intl.num_elem == 0) {
            fprintf(f, "NO INTERNAL PROBE FOUND\n\n");
        } else {
            print_primers = 1;
        }
    }
    if (pa->pick_right_primer) {
        if (retval->rev.num_elem == 0) {
            fprintf(f, "NO RIGHT PRIMER FOUND\n\n");
        } else {
            print_primers = 1;
        }
    }
    if ((warning = p3_get_rv_and_gs_warnings(retval, pa)) != NULL) {
        fprintf(f, "\nWARNING: %s\n", warning);
        free(warning);
    }
    if ((pa->primer_task != pick_primer_list ) && (pa->primer_task != pick_sequencing_primers)) {
        if (print_primers == 1) {
            print_oligo_header(f, "OLIGO", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
        }

        /* Print out the first line with the best primers */
        if ((pa->pick_left_primer) && (&retval->fwd != NULL ) && (retval->fwd.num_elem > 0)) {
            if(pa->modify_left_primer==1) {
                print_oligo_Z(f, TITLE_MOD_LEFT, sa, retval->fwd.oligo, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
            } else {
                print_oligo_Z(f, TITLE_LEFT, sa, retval->fwd.oligo, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
            }
            h = retval->fwd.oligo;
            rest_count = 1;
        }

        if ((pa->pick_internal_oligo) && (&retval->intl != NULL ) && (retval->intl.num_elem > 0)) {
            if(pa->modify_internal_oligo==1) {
                if((retval->intl.oligo)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_MOD_INTL_FW, sa, retval->intl.oligo, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                } else if((retval->intl.oligo)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_MOD_INTL_RV, sa, retval->intl.oligo, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                }
            } else {
                if((retval->intl.oligo)->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_INTL_FW, sa, retval->intl.oligo, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                } else if((retval->intl.oligo)->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_INTL_RV, sa, retval->intl.oligo, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                }
            }
            h = retval->intl.oligo;
            rest_count = 1;
        }

        if ((pa->pick_right_primer) && (&retval->rev != NULL ) && (retval->rev.num_elem > 0)) {
            if(pa->modify_right_primer==1) {
                print_oligo_Z(f, TITLE_MOD_RIGHT, sa, retval->rev.oligo, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
            } else {
                print_oligo_Z(f, TITLE_RIGHT, sa, retval->rev.oligo, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
            }
            h = retval->rev.oligo;
            rest_count = 1;
        }
    }

    if(print_primers == 1) {
        fprintf(f, "SEQUENCE SIZE: %ld\n", (long int) strlen(sa->sequence));
        fprintf(f, "INCLUDED REGION SIZE: %d\n\n", sa->incl_l);

        if(sa->tar2.genotyping==0) {
            print_pair_array(f, "TARGETS", sa->tar2.count, sa->tar2.pairs, pa, sa);
        } else if(sa->tar2.genotyping==1) {
            fprintf(f,"TARGET VARIANT * (position,size):");
            if(sa->tar2.char_count==sa->tar2.VAR_sequence_number) {
                fprintf(f," %d,%d",sa->tar2.VAR_start[0],sa->tar2.char_num[sa->tar2.VAR_sequence_number]-1);
            } else {
                fprintf(f," %d,%d",sa->tar2.VAR_start[0],sa->tar2.char_num[sa->tar2.VAR_sequence_number]);
            }
            fprintf(f,"\n\n");
        }

        print_pair_array(f, "EXCLUDED REGIONS", sa->excl2.count, sa->excl2.pairs, pa, sa);
        print_pair_array(f, "INTERNAL PROBE EXCLUDED REGIONS", sa->excl_internal2.count, sa->excl_internal2.pairs, pa, sa);
        print_2_pair_array(f, "PAIR_OK_REGIONS", sa->ok_regions.count, sa->ok_regions.left_pairs, sa->ok_regions.right_pairs, pa, sa);
    }

    if (pa->primer_task != pick_primer_list ) {
        if(pa->pick_internal_oligo==1) {
            if(print_seq(f,pa,sa,retval,retval->intl.oligo,best_pairs,0)) exit(-2);
        }
        else if(pa->pick_left_primer==1) {
            if(print_seq(f,pa,sa,retval,retval->fwd.oligo,best_pairs,0)) exit(-2);
        }
        else if(pa->pick_right_primer==1) {
            if(print_seq(f,pa,sa,retval,retval->rev.oligo,best_pairs,0)) exit(-2);
        }
        else if (print_seq(f, pa, sa, retval, h, best_pairs, 0)) exit(-2); /* ENOMEM */
    }
    fprintf(f, "\n");

    /* Print out the other primers */
    if ((pa->pick_left_primer) && (&retval->fwd != NULL ) && (retval->fwd.num_elem > rest_count)) {
        int n = retval->fwd.num_elem;
        h = retval->fwd.oligo;
        if (rest_count == 1) {
            fprintf(f, "ADDITIONAL OLIGOS\n");
        }
        fprintf(f, "   ");
        print_oligo_header(f, "", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
        for (i = rest_count; i < pa->num_return; i++) {
            if(i > n-1) break;
            p = h + i;
            fprintf(f, "%2d ", i + 1 - rest_count);
            if(pa->modify_left_primer==1) {
                print_oligo_Z(f, TITLE_MOD_LEFT, sa, p, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
            } else {
                print_oligo_Z(f, TITLE_LEFT, sa, p, OT_LEFT, pa, pa->p_args.repeat_lib, print_lib_sim);
            }
        }
        if (rest_count == 0) {
            fprintf(f, "\n ");
        }
    }

    if ((pa->pick_internal_oligo) && (&retval->intl != NULL ) && (retval->intl.num_elem > rest_count)) {
        int n = retval->intl.num_elem;
        h = retval->intl.oligo;

        if (rest_count == 1) {
            fprintf(f, "ADDITIONAL OLIGOS\n");
        }
        fprintf(f, "   ");
        print_oligo_header(f, "", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
        for (i = rest_count; i < pa->num_return; i++) {
            if(i > n-1) break;
            p = h + i;
            fprintf(f, "%2d ", i + 1 - rest_count);

            if(pa->modify_internal_oligo==1) {
                if(p->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_MOD_INTL_FW, sa, p, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                } else if(p->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_MOD_INTL_RV, sa, p, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                }
            } else {
                if(p->oligo_dir==0) {
                    print_oligo_Z(f, TITLE_INTL_FW, sa, p, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                } else if(p->oligo_dir==1) {
                    print_oligo_Z(f, TITLE_INTL_RV, sa, p, OT_INTL, pa, pa->p_args.repeat_lib, print_lib_sim);
                }
            }
        }
        if (rest_count == 0) {
            fprintf(f, "\n ");
        }
    }

    if ((pa->pick_right_primer) && (&retval->rev != NULL ) && (retval->rev.num_elem > rest_count)) {
        int n = retval->rev.num_elem;
        h = retval->rev.oligo;
        if (rest_count == 1) {
            fprintf(f, "ADDITIONAL OLIGOS\n");
        }
        fprintf(f, "   ");
        print_oligo_header(f, "", print_lib_sim, pa->thermodynamic_alignment, sa->tar2.genotyping);
        for (i = rest_count; i < pa->num_return; i++) {
            if(i > n-1) break;
            p = h + i;
            fprintf(f, "%2d ", i + 1 - rest_count);
            if(pa->modify_right_primer==1) {
                print_oligo_Z(f, TITLE_MOD_RIGHT, sa, p, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
            } else {
                print_oligo_Z(f, TITLE_RIGHT, sa, p, OT_RIGHT, pa, pa->p_args.repeat_lib, print_lib_sim);
            }
        }
    }
    if (explain_flag)
        print_explain(f, pa, sa, retval, print_lib_sim, pr_release);
    fprintf(f, "\n\n");
    if (fflush(f) == EOF) {
        perror("fflush(f) failed");
        exit(-1);
    }
}