/****************************************************************************** ## # # ##### #### #### # # ##### #### # # # # # # # # # ## ## # # # # # # # # # # # # # ## # # # # ###### # # # # # # # # # # ### # # # # # # # # # # # # # # ### # # # # #### # #### ####### #### # # ##### ### #### ******************************************************************************/ /* This file is part of MAPMAKER 3.0b, Copyright 1987-1992, Whitehead Institute for Biomedical Research. All rights reserved. See READ.ME for license. */ #define INC_LIB #define INC_SHELL #define INC_MISC #include "mapm.h" /* external proccedures WHY WHY WHY FIX FIX FIX */ void try_marker(); /* local */ void maybe_print_together(); #define ASS_ALREADY "%s- already assigned to %s at LOD %4.1lf...not changing\n" /**************** COMMANDS ****************/ #define CANT_MAKE "warning: can't make chromosome '%s'... %s\n" command make_chromosome() { char name[TOKLEN+1]; int i, num; mapm_ready(ANY_DATA,0,0,NULL); if (!nullstr(args)) { while (stoken(&args,sREQUIRED,name)) { if (!valid_name(name)) { sf(ps,CANT_MAKE,name,"illegal name"); pr(); } else if (!valid_new_name(name)) { sf(ps,CANT_MAKE,name,"name is already in use"); pr(); } else if (!make_new_chrom(name,&num)) { sf(ps,CANT_MAKE,name,"chromosome already exists"); pr(); } } } print("chromosomes defined: "); if (num_chromosomes==0) print("none"); else for (i=0; i0) { alloc_list_of_all_loci(seq,&locus,&num_loci); for (i=0; iMAX_CHROM_LOCI) error("too many loci in the sequence for a chromosome framework"); old=get_chrom_frame(chrom,NULL); map=get_map_to_bash(chromosome); if (num_loci==0) { sf(ps,CHROM_NOFRAME,chrom2str(chrom),(old->num_loci>0 ? "now ":"")); pr(); nl(); clean_map(map); set_chrom_frame(chrom,map); return; } run { get_one_order(seq,map); if (old->num_loci>0) { sf(ps,CHROM_FRAME_EXISTS,chrom2str(chrom)); pr(); nl(); } else { sf(ps,CHROM_SETTING,chrom2str(chrom)); pr(); nl(); } init_rec_fracs(map); converge_to_map(map); set_chrom_frame(chrom,map); print(MAP_DIVIDER); sf(title,CHROM_FRAME,chrom2str(chrom)); print_long_map(map,title); print(MAP_DIVIDER); } on_exit { relay_messages; } } #define CHROMS_TITLE \ " Chromosome: #Total #Frame #Anchors #Placed #Unique #Region\n" /*2345678.......234.....234......234.......234......234......234*/ #define CHROMS_FORMAT \ " %-8s %4d %4d %4d %4d %4d %4d\n" command list_chroms() { int frame, total, anchor, placed, unique, region, i, *loci=NULL; int sum_frame, sum_total, sum_anchor, sum_placed, sum_unique, sum_region; mapm_ready(ANY_DATA,0,0,NULL); nomore_args(0); if (num_chromosomes==0) error("no chromosomes presently defined\n"); array(loci,raw.num_markers,int); sum_frame=sum_total=sum_anchor=sum_placed=sum_unique=sum_region= 0; nl(); print(CHROMS_TITLE); for (i=0; inum_maps; i++) { count_chrom_loci(i,&anchor,&frame,&total,&placed,&unique,®ion, TRUE,loci); sf(ps,CHROMS_FORMAT,chrom2str(i),total,frame,anchor,placed, unique,region); pr(); sum_frame+=frame; sum_total+=total; sum_anchor+=anchor; sum_placed+=placed; sum_unique+=unique; sum_region+=region; } sf(ps,CHROMS_FORMAT,"Total:",sum_total,sum_frame,sum_anchor, sum_placed,sum_unique,sum_region); pr(); unarray(loci,int); } command list_assignments() { int chrom, i; mapm_ready(ANY_DATA,0,0,NULL); nomore_args(0); if (num_chromosomes==0) error("no chromosomes presently defined\n"); print("Chromosome assignments of all loci:\n"); nl(); for (chrom=0; chromnum_maps; chrom++) { sf(ps,"%s= ",chrom2str(chrom)); pr(); for (i=0; iexcluded,MAX_CHROM_LOCI+1,bool); unplaced[i]->best_map=allocate_map(MAX_CHROM_LOCI+1); } temp=allocate_map(MAX_CHROM_LOCI+1); sf(ps,PLACE_HEADER,npt_thresh); pr(); for (i=0; inum_maps; chrom++) { /* chrom_locus[], n_to_place is all loci in seq on this chrom */ n_to_place=0; for (i=0; ilocus=chrom_locus[i]; ok=TRUE; if (use_three_pt) { /* three_pt_exclusions sets excluded[x] to FALSE first */ n_allowed=three_pt_exclusions(frame->locus,frame->num_loci, unplaced[i]->locus, unplaced[i]->excluded); find_window(frame->locus,frame->num_loci, unplaced[i]->locus,unplaced[i]->excluded, NPT_WINDOW,&left,&right); } else { /* no three-pt -> all orders are OK */ n_allowed=n_frame+1; left=0; right=n_frame; /* window= all intervals */ } if (n_allowed==0) { /* (un)place_this() does all of the i/o */ unplace_this(unplaced[i]->locus,chrom,M_PROBLEM,TRUE); unplaced[i]->locus=NO_LOCUS; n_to_punt++; } else { place_locus(frame,unplaced[i]->locus,left,right, unplaced[i]->excluded,placements, &unplaced[i]->best_pos,unplaced[i]->best_map, temp); place_this(unplaced[i]->locus,chrom,placements,-npt_thresh, 10000.0,error_net_thresh,unplaced[i]->excluded); /* place_this() calls npt_exclusions() on placements */ } } nl(); if (n_to_place-n_to_punt==0) print("No Valid Placements\n"); else { print("Placements:\n"); new_print_placements(frame,unplaced,n_to_place); for (i=0; ilocus!=NO_LOCUS && placed_locus(unplaced[i]->locus)) { print(SUB_DIVIDER); sf(ps,"Best placement of %s:", rag(loc2str(unplaced[i]->locus))); print_special_map(unplaced[i]->best_map,ps, n_frame,frame->locus); } } } /* next chrom */ if (got_any) print(MAP_DIVIDER); else error(PLACE_NONE); } on_exit { unarray(locus,int); unparray(placements,MAX_CHROM_LOCI+1,real); unarray(chrom_locus,int); unarray(chrom_all,int); free_map(temp); for (i=0; ibest_map); unarray(unplaced[i]->excluded,bool); } unparray(unplaced,n_loci,PLACEME); relay_messages; } } command show_chrom() { int chrom, i, j; bool found_in_frame, found; int *marker=NULL, num_markers, **placement_state=NULL; char name[TOKLEN+1], title[TOKLEN+1]; MAP *map=NULL; mapm_ready(ANY_DATA,0,0,NULL); chrom=get_chrom_arg(FALSE); nomore_args(num_args); run { array(marker,raw.num_markers,int); /* non-frame markers */ get_chrom_loci(chrom,marker,NON_FRAME,&num_markers,NULL); matrix(placement_state,num_markers, chromosome->map_list[chrom]->num_loci+1,int); nl(); print(MAP_DIVIDER); sf(title,CHROM_FRAME,chrom2str(chrom)); print_long_map(chromosome->map_list[chrom],title); print(MAP_DIVIDER); sf(ps,CHROM_MARKS,chrom2str(chrom)); pr(); nl(); get_chrom_loci(chrom,marker,ALL_LOCI,&num_markers,NULL); print_locus_summary(marker,num_markers,TRUE); /* change to FALSE? */ if (use_haplotypes) { nl(); print_haplo_summary(marker,num_markers); } print(MAP_DIVIDER); /* get_chrom_loci(chrom,marker,&num_markers,...); print_3pt_placements(chromosome->map_list[chrom]->locus, chromosome->map_list[chrom]->num_loci, marker,num_markers,placement_state); print(MAP_DIVIDER); */ } on_exit { unarray(marker,int); relay_messages; } } #define PLACE_AT \ "Placing markers at log-likelihood threshold %.1lf:\n" command place_together() { int chrom, i, j, left, right; int *locus=NULL, n_loci, *chrom_locus=NULL, n_to_place, n_allowed; int *chrom_all=NULL, n_chrom, n_frame, n_to_punt, n_unplaced, num, prev; real npt_thresh, diff; bool got_any, ok; PLACEME **unplaced=NULL; MAP *order=NULL, *frame; /* frame is NOT malloced */ mapm_ready(ANY_DATA,1,LIST_SEQ,&n_loci); nomore_args(0); if (npt_threshold==npt_first_threshold) /* globals */ sf(ps,"Placement Threshold %.2lf, Npt-Window %d\n", npt_threshold,npt_window); else sf(ps,"Placement Threshold-1 %.2lf, Threshold-2 %.2lf, Npt-Window %d\n", npt_first_threshold,npt_threshold,npt_window); pr(); run { alloc_list_of_all_loci(seq,&locus,&n_loci); array(chrom_locus,raw.num_markers,int); array(chrom_all,raw.num_markers,int); parray(unplaced,n_loci,PLACEME); for (i=0; iexcluded,MAX_CHROM_LOCI+1,bool); unplaced[i]->best_map=allocate_map(MAX_CHROM_LOCI+1); } order=allocate_map(MAX_CHROM_LOCI+1); sf(ps,PLACE_HEADER,npt_thresh); pr(); for (i=0; inum_maps; chrom++) { /* chrom_locus[], n_to_place is all loci in seq on this chrom */ n_to_place=0; for (i=0; ilocus=chrom_locus[i]; n_unplaced= n_to_place; nl(); sf(ps,PLACE_AT,npt_first_threshold); pr(); extend_order(order,unplaced,&n_unplaced,-npt_first_threshold,TRUE); if (npt_first_threshold!=npt_threshold && n_unplaced>0) { print(SUB_DIVIDER); sf(ps,PLACE_AT,npt_threshold); pr(); extend_order(order,unplaced,&n_unplaced,-npt_threshold,FALSE); } nl(); sf(ps,"order%d= ",num_orders+1); pr(); for (i=0; inum_loci; i++) { sf(ps,"%s ",rag(loc2str(order->locus[i]))); pr(); if (i==0) order_first[0]=order->locus[i]; else order_next[prev]=order->locus[i]; prev=order->locus[i]; /* lint warning is OK */ } nl(); sf(ps,"other%d= ",num_orders+1); pr(); for (i=0; ilocus))); pr(); if (i==0) unorder_first[0]=unplaced[i]->locus; else order_next[prev]=unplaced[i]->locus; prev=unplaced[i]->locus; } nl(); num_orders++; if (print_all_maps) for (i=0; ibest_map->num_loci>0) { print(SUB_DIVIDER); sf(ps,"Best placement of %s:", rag(loc2str(unplaced[i]->locus))); print_special_map(unplaced[i]->best_map,ps, order->num_loci,order->locus); } } /* next chrom */ if (got_any) print(MAP_DIVIDER); else error(PLACE_NONE); } on_exit { /* add FREEs */ relay_messages; } } command draw_chromosome() { int chrom; char name[PATH_LENGTH+1]; FILE *fp=NULL; mapm_ready(ANY_DATA,0,0,NULL); use_uncrunched_args(); chrom=get_chrom_arg(FALSE); get_arg(stoken,chrom2str(chrom),name); nomore_args(num_args); run { if (!make_filename(name,FORCE_EXTENSION,PS_EXT)) { sf(ps,"illegal filename '%s'",name); error(ps); } fp= open_file(name,WRITE); sf(ps,"Drawing chromosome %s in PostScript file '%s'... \n", chrom2str(chrom),name); pr(); print_ps_chrom(fp,chrom); close_file(fp); print("ok\n"); } except { when CANTOPEN: sf(ps,"Can't create output file '%s'",name); error(ps); when CANTCLOSE: error("\nCan't close file - disk is full?"); default: close_file(fp); relay_messages; } } command draw_all_chromosomes() { int chrom; char name[PATH_LENGTH+1]; FILE *fp=NULL; mapm_ready(ANY_DATA,0,0,NULL); use_uncrunched_args(); get_arg(stoken,raw.filename,name); nomore_args(num_args); run { /* print all chroms in same file to same scale */ if (!make_filename(name,FORCE_EXTENSION,PS_EXT)) { sf(ps,"illegal filename '%s'",name); error(ps); } fp=open_file(name,WRITE); sf(ps,"Drawing all chromosomes in PostScript file '%s'... \n",name); pr(); print_all_ps_chroms(fp); close_file(fp); print("ok\n"); } except { when CANTOPEN: sf(ps,"Can't create output file '%s'",name); error(ps); when CANTCLOSE: error("\nCan't close file - disk is full?"); default: close_file(fp); relay_messages; } }