NCBI C++ ToolKit
thrdsal0.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: thrdsal0.c 32839 2007-03-05 20:41:55Z kazimird $
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: thrdsal0.c
27 *
28 * Author: Stephen Bryant
29 *
30 * Initial Version Creation Date: 08/16/2000
31 *
32 * $Revision: 32839 $
33 *
34 * File Description: threader
35 */
36 
37 
38 
41 
42 /* Initial core segment alignment */
43 
44 /* Find limiting values for alignment of a core segment, given the extents */
45 /* of all segments, loop length ranges, the length of the query sequence, */
46 /* any explicit alignment constraints, and the alignment of other segments */
47 /* that have been assigned already. The query sequence is assumed to be */
48 /* unaligned or only partially aligned with the core motif, and constraints */
49 /* are therefore derived from consieration of the overall length of the */
50 /* query sequence as compared to that required for all other core segments */
51 /* and loops. Explicit alignement constraints or previous alignment of */
52 /* other core segments are also considered, and will further restrict the */
53 /* range of alignments allowed for the current segment */
54 
55 int sal0(Cor_Def* cdf, Qry_Seq* qsq, Cur_Loc* sli, Cur_Aln* sai, int cs, int* mn, int* mx) {
56 /*-----------------------------------------------------------*/
57 /* cdf: Contains specified loop length limits */
58 /* qsq: Sequence to thread with alignment contraints */
59 /* sli: Contains current segment location values */
60 /* sai: Contains current segment alignment values */
61 /* cs: The segment for which constraints are to be found */
62 /* mn,mx: The range of allowed aligments for this segment */
63 /*-----------------------------------------------------------*/
64 
65 int i; /* Counter */
66 int nsc; /* Number of core segments */
67 int sl; /* Core segment lengths */
68 int ec; /* Alignment limit due to explicit constraint */
69 int lm1,lm2; /* Loop length limits */
70 int ntmn,ntmx; /* Alignment range due to n-termnal constraints */
71 int ctmn,ctmx; /* Alignment range due to c-termnal constraints */
72 
73 
74 /* Number of core segments */
75 nsc=cdf->sll.n;
76 
77 /* Find alignment constraints arising from segments n-terminal to this one. */
78 /* These are indices of the most c-terminal query sequence residue assigned */
79 /* to an n-terminal segment or loop. The minimum index assumes minimum loop */
80 /* lengths and explicitly constrained segments at their most n-terminal */
81 /* positions. The maximum index assumes maximum loop lengths and explicitly */
82 /* constrained segments at their most c-terminal positions. */
83 
84 /* Allow for the minimum length of an n-terminal tail */
85 ntmn=-1+cdf->lll.llmn[0];
86 
87 /* Initialize the maximum alignment allowed by n-terminal segments to the */
88 /* end of the sequence. They constrain alignment only one of the n-terminal */
89 /* segments is already aligned or explicitly constrained. */
90 ntmx=qsq->n;
91 
92 /* Loop over n-terminal segments */
93 /* printf("initial ntmn:%d initial ntmx:%d\n",ntmn,ntmx); */
94 /* printf("cs:%d\n",cs); */
95 for(i=0; i<cs; i++) {
96 
97  /* Add segment length */
98  sl=sli->no[i]+sli->co[i]+1;
99  ntmn+=sl;
100  ntmx+=sl;
101  /* printf("sl:%d ntmn:%d ntmx:%d\n",sl,ntmn,ntmx); */
102 
103  /* Reset limits to reflect any explicit constraints */
104  if(qsq->sac.mn[i]>0) {
105  ec=qsq->sac.mn[i]+sli->co[i];
106  ntmn=(ec>ntmn) ? ec : ntmn;}
107  if(qsq->sac.mx[i]>0) {
108  ec=qsq->sac.mx[i]+sli->co[i];
109  ntmx=(ec<ntmx) ? ec : ntmx;}
110 
111  /* Reset limits if this segment has been aligned already */
112  if(sai->al[i]>=0) {
113  ntmn=ntmx=sai->al[i]+sli->co[i];
114  /* printf("ntmx=ntmn:%d\n",ntmn); */
115  }
116 
117  /* Add length limits of the following loop */
118  lm1=sli->lp[i+1];
119  lm2=cdf->lll.llmn[i+1];
120  ntmn+= (lm1>lm2) ? lm1 : lm2;
121  /* printf("lm1:%d lm2:%d ntmn:%d\n",lm1,lm2,ntmn); */
122  lm2=cdf->lll.llmx[i+1];
123  ntmx+= (lm1>lm2) ? lm1 : lm2;
124  /* printf("lm1:%d lm2:%d ntmx:%d\n",lm1,lm2,ntmx); */
125  }
126 
127 /* Add n-terminal offset of current segment to give alignment limits */
128 ntmn+=sli->no[cs]+1;
129 ntmx+=sli->no[cs]+1;
130 /* printf("final ntmn: %d final ntmx: %d\n",ntmn,ntmx); */
131 
132 
133 /* Find alignment constraints arising from segments c-terminal to this one. */
134 
135 /* Allow for the minimum length of a tail. */
136 ctmx=qsq->n-cdf->lll.llmn[nsc];
137 
138 /* Initialize the maximum alignment allowed by c-terminal segments to the */
139 /* start of the sequence. They constrain alignment only one of the */
140 /* c-terminal segments is already aligned or explicitly constrained. */
141 ctmn=-1;
142 
143 /* Loop over all c-terminal segments */
144 /* printf("initial ctmn:%d initial ctmx:%d\n",ctmn,ctmx); */
145 for(i=nsc-1; i>cs; i--) {
146 
147  /* Add segment length */
148  sl=sli->no[i]+sli->co[i]+1;
149  ctmn-=sl;
150  ctmx-=sl;
151  /* printf("sl:%d ctmn:%d ctmx:%d\n",sl,ctmn,ctmx); */
152 
153  /* Reset limits to reflect any explicit constraints */
154  if(qsq->sac.mn[i]>0) {
155  ec=qsq->sac.mn[i]-sli->no[i];
156  ctmn=(ec>ctmn) ? ec : ctmn;}
157  if(qsq->sac.mx[i]>0) {
158  ec=qsq->sac.mx[i]-sli->no[i];
159  ctmx=(ec<ctmx) ? ec : ctmx;}
160 
161  /* Reset limits if this segment has been aligned already */
162  if(sai->al[i]>=0) {
163  ctmn=ctmx=sai->al[i]-sli->no[i];
164  /* printf("ctmx=ctmn:%d\n",ctmn); */
165  }
166 
167  /* Subtract lengths of the preceeding loop */
168  lm1=sli->lp[i];
169  lm2=cdf->lll.llmn[i];
170  ctmx-= (lm1>lm2) ? lm1 : lm2;
171  /* printf("lm1:%d lm2:%d ctmx:%d\n",lm1,lm2,ctmx); */
172  lm2=cdf->lll.llmx[i];
173  ctmn-= (lm1>lm2) ? lm1 : lm2;
174  /* printf("lm1:%d lm2:%d ctmn:%d\n",lm1,lm2,ctmn); */
175  }
176 
177 /* Subtract c-terminal offset of current segment to give alignment limits */
178 ctmn-=sli->co[cs]+1;
179 ctmx-=sli->co[cs]+1;
180 /* printf("final ctmn:%d final ctmx:%d\n",ctmn,ctmx); */
181 
182 
183 /* Signal an error if no alignment falls within the limits identified. */
184 if(ntmn>ctmx||ntmx<ctmn) return(0);
185 
186 /* Reconcile n-termnal and c-termnal aligment limits: alignment must */
187 /* satisfy all the constraints */
188 *mn=(ntmn>ctmn) ? ntmn : ctmn;
189 *mx=(ntmx<ctmx) ? ntmx : ctmx;
190 /* printf("mn:%d mx:%d\n",*mn,*mx); */
191 
192 /* Further reconcile any explict limits on the current segment alignment, */
193 /* and signal an error if these constraints cannot be satisfied. */
194 /* printf("qsq->sac.mn[%d]: %d\n",cs,qsq->sac.mn[cs]); */
195 if(qsq->sac.mn[cs]>=0) {
196  lm1=qsq->sac.mn[cs];
197  if(lm1>*mx) return(0);
198  if(lm1>*mn) *mn=lm1;}
199 /* printf("qsq->sac.mx[%d]: %d\n",cs,qsq->sac.mx[cs]); */
200 if(qsq->sac.mx[cs]>=0) {
201  lm1=qsq->sac.mx[cs];
202  if(lm1<*mn) return(0);
203  if(lm1<*mx) *mx=lm1; }
204 
205 /* printf("mn:%d mx:%d\n",*mn,*mx); */
206 return(1);
207 }
int i
struct _Cor_Def::@23 sll
struct _Cor_Def::@24 lll
int * llmx
Definition: thrdatd.h:78
int * llmn
Definition: thrdatd.h:77
int n
Definition: thrdatd.h:74
int * al
Definition: thrdatd.h:190
int * lp
Definition: thrdatd.h:182
int * no
Definition: thrdatd.h:179
int * co
Definition: thrdatd.h:180
int * mx
Definition: thrdatd.h:96
int * mn
Definition: thrdatd.h:95
int n
Definition: thrdatd.h:93
struct _Qry_Seq::@26 sac
int sal0(Cor_Def *cdf, Qry_Seq *qsq, Cur_Loc *sli, Cur_Aln *sai, int cs, int *mn, int *mx)
Definition: thrdsal0.c:55
Modified on Fri Sep 20 14:57:28 2024 by modify_doxy.py rev. 669887