1 /* $Id: thrdsgoi.c,v 1.2 2004/04/01 13:43:05 lavr Exp $
2 *===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name:  thrdsgoi.c
27 *
28 * Author:  Stephen Bryant
29 *
30 * Initial Version Creation Date: 08/16/2000
31 *
32 * $Revision: 1.2 $
33 *
34 * File Description: threader
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: thrdsgoi.c,v $
39 * Revision 1.2  2004/04/01 13:43:05  lavr
40 * Spell "occurred", "occurrence", and "occurring"
41 *
42 * Revision 1.1  2000/08/16 20:45:21  hurwitz
43 * initial check in of threading routines
44 *
45 * ==========================================================================
46 */
47 
48 
49 
50 /* Set core segment sampling order */
51 
52 #include <thrdatd.h>
53 #include <thrddecl.h>
54 
sgoi(int is,int it,Rnd_Smp * pvl,Seg_Ord * sgo)55 int sgoi(int is, int it, Rnd_Smp* pvl, Seg_Ord* sgo) {
56 /*----------------------------------------------------*/
57 /* is:   Code to determine order of segment sampling  */
58 /* it:   Code to determine order of terminus sampling */
59 /* pvl:	 Storage for segment location probabilities   */
60 /* sgo:  Segment samping order                        */
61 /*----------------------------------------------------*/
62 
63 int	nsc;		/* Number of threaded core segments */
64 int	i,j,k;		/* Counters */
65 int	*si;		/* Segment index by order of sampling */
66 int	*so;		/* Flags segments already assigned an order */
67 int	*to;		/* Order of terminus sampling, 0=Nterm, 1=Cterm. */
68 float	pv;		/* P value */
69 
70 
71 /* Number of core segments */
72 nsc=sgo->nsc;
73 
74 /* Initialize alignment order arrays */
75 si=sgo->si;
76 so=sgo->so;
77 for(i=0; i<nsc; i++) so[i]=1;
78 to=sgo->to;
79 
80 /* Determine the order of core segment alignment */
81 /* printf("is:%d\n",is); */
82 switch(is) {
83 
84 	default: {	/* Order randomly */
85 		/* printf("segment order by default random method\n"); */
86 		pvl->n=nsc;
87 		for(i=0; i<nsc; i++) {
88 			pv=1./(nsc-i);
89 			for(j=0; j<nsc; j++) {
90 				if(so[j]==1) pvl->p[j]=pv;
91 				else pvl->p[j]=0.; }
92 			k=rsmp(pvl); so[k]=0; si[i]=k; }
93 			break; }
94 
95 	case 1: {	/* Order by occurrence in the core definition */
96 
97 		/* printf("segment order by occurrence, case 1\n"); */
98 		for(i=0; i<nsc; i++)  si[i]=i;  break; }
99 
100 		}
101 
102 
103 /* Select the terminus to sample first, using the specified method */
104 /* printf("it:%d\n",it); */
105 switch(it) {
106 
107 	default: {	/* Choose n- or c-terminus at random */
108 		/* printf("terminus order by default random method\n");*/
109 		for(i=0; i<nsc; i++) {
110 			pvl->n=2; pvl->p[0]=.5; pvl->p[1]=.5;
111 			to[i]=rsmp(pvl); } break; }
112 
113 	case 1: {	/* N-terminus first */
114 		/* printf("segment order n-terminus first, case 1\n"); */
115 		for(i=0; i<nsc; i++) to[i]=0; break; }
116 
117 	case 2: {	/* C-terminus first */
118 		/* printf("segment order c-terminus first, case 2\n"); */
119 		for(i=0; i<nsc; i++) to[i]=1; break; }
120 
121 		}
122 
123 }
124 
125