~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to api/alignmgr2.h

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
*
29
29
* Version Creation Date:  10/01 
30
30
*
31
 
* $Revision: 6.10 $
 
31
* $Revision: 6.21 $
32
32
*
33
33
* File Description: SeqAlign indexing, access, and manipulation functions
34
34
*
35
35
* Modifications:
36
36
* --------------------------------------------------------------------------
37
37
* $Log: alignmgr2.h,v $
 
38
* Revision 6.21  2003/10/09 13:46:39  rsmith
 
39
* Add AlnMgr2GetFirstNForSipList.
 
40
*
 
41
* Revision 6.20  2003/04/23 20:37:06  rsmith
 
42
* Added four functions in section 11 to allow examination of Std-Seg alignments.
 
43
*
 
44
* Revision 6.19  2003/03/31 20:17:11  todorov
 
45
* Added AlnMgr2IndexSeqAlignEx
 
46
*
 
47
* Revision 6.18  2002/08/07 21:57:33  kans
 
48
* added AlignMgr2GetFirstNForStdSeg
 
49
*
 
50
* Revision 6.17  2002/07/11 14:35:51  kans
 
51
* fixed Mac complaints about prototypes
 
52
*
 
53
* Revision 6.16  2002/07/11 12:55:33  wheelan
 
54
* added support for std-seg alignments
 
55
*
 
56
* Revision 6.15  2002/05/21 12:26:25  wheelan
 
57
* added n5 field to AMSmallPtr
 
58
*
 
59
* Revision 6.14  2002/04/09 18:21:55  wheelan
 
60
* changed params for AlnMgr2IndexAsRows
 
61
*
 
62
* Revision 6.13  2002/03/04 17:19:29  wheelan
 
63
* added AlnMgr2FuseSet, changed behavior of RemoveInconsistent
 
64
*
 
65
* Revision 6.12  2002/01/30 19:12:20  wheelan
 
66
* added RemoveInconsistentAlnsFromSet, ExtractPairwiseSeqAlign, changed behavior of GetSubAlign, changed structures and behavior of GetNextAlnBit, added GetInterruptInfo
 
67
*
 
68
* Revision 6.11  2001/12/28 22:53:46  wheelan
 
69
* added AlnMgr2DupAlnAndIndexes, changed amaip struct
 
70
*
38
71
* Revision 6.10  2001/12/14 12:38:35  wheelan
39
72
* added functions for ddv
40
73
*
76
109
#include <salutil.h>
77
110
#include <salpedit.h>
78
111
#include <samutil.h>
 
112
#include <sequtil.h>
79
113
 
80
114
#undef NLM_EXTERN
81
115
#ifdef NLM_IMPORT
92
126
#define AM_NUCSIZE   6
93
127
#define AM_PROTSIZE  26
94
128
 
 
129
/* max seqport window */
 
130
#define AM_SEQPORTSIZE 20000
 
131
 
95
132
/* defines for AlnMgr2ComputeScoreForPairwiseSeqAlign */
96
133
#define AM_GAPOPEN  -11
97
134
#define AM_GAPEXT   -1
100
137
#define INDEX_CHILD   1
101
138
#define INDEX_PARENT  2
102
139
 
103
 
/* defines for amp->type */
 
140
/* defines for amp->type and interrupt->type */
104
141
#define AM_SEQ        1
105
142
#define AM_GAP        2
 
143
#define AM_INSERT     3
 
144
#define AM_UNALIGNED  4
106
145
 
107
146
#define AM2_LEFT_TAIL   0
108
147
#define AM2_RIGHT_TAIL  1
109
148
 
 
149
#define AM2_LEFT        1
 
150
#define AM2_RIGHT       2
 
151
 
110
152
/* defines for AlnMgr2AddInNewSA */
111
153
#define AM_START    -1
112
154
#define AM_STOP      1
154
196
   Int4                   score;
155
197
   Boolean                aligned;
156
198
   SeqAlignPtr            top;
 
199
   Int4                   tmp;
157
200
} SAIndex2, PNTR SAIndex2Ptr;
158
201
 
159
202
NLM_EXTERN Boolean LIBCALLBACK SAIndex2Free2(VoidPtr index);
160
203
 
 
204
typedef struct am_interrinfo {
 
205
   Uint1    strand;
 
206
   Int4Ptr  starts;
 
207
   Int4Ptr  lens;
 
208
   Int4Ptr  types;
 
209
   Int4     num;
 
210
} AMInterrInfo, PNTR AMInterrInfoPtr;
 
211
 
 
212
NLM_EXTERN void AlnMgr2FreeInterruptInfo(AMInterrInfoPtr interrupt);
 
213
 
 
214
typedef struct am_insert {
 
215
   Int4Ptr  starts;
 
216
   Int4Ptr  lens;
 
217
   Int4     which_side;
 
218
} AMInsert, PNTR AMInsertPtr;
 
219
 
161
220
typedef struct am_unalign {
162
221
   Int4Ptr  starts;
163
222
   Int4Ptr  lens;
164
223
   Int4     which_side;
165
224
} AMUnalign, PNTR AMUnalignPtr;
166
225
 
167
 
typedef struct am_insert {
168
 
   Int4Ptr  starts;
169
 
   Int4Ptr  lens;
170
 
   Int4     which_side;
171
 
} AMInsert, PNTR AMInsertPtr;
172
 
 
173
226
typedef struct am_parcel {
174
227
   Int4          alnstart;
175
228
   Int4          sap_source;
184
237
   Int4                   anchor;
185
238
   Int4                   numrows;
186
239
   SeqIdPtr               PNTR ids;  /* one SeqId per row */
187
 
   Int4Ptr                aligncoords;
188
240
   Int4                   numsaps;
189
241
   SeqAlignPtr            PNTR saps;
190
242
   Boolean                PNTR aligned; /* for each sap -- is it used in the overall alignment? */
193
245
 
194
246
NLM_EXTERN Boolean LIBCALLBACK AMAlignIndex2Free2(VoidPtr index);
195
247
 
196
 
typedef struct am_adjacent {
197
 
   Int4  from;
198
 
   Int4  to;
199
 
} AMAdjac, PNTR AMAdjacPtr;
 
248
typedef struct {
 
249
   Int4  insertlen;
 
250
   Int4  unalnlen;
 
251
   Int4  segnum;
 
252
   Int4  row;
 
253
   Int4  which_side;
 
254
} AMInterrupt, PNTR AMInterruptPtr;
200
255
 
201
256
typedef struct am_msg2 {
202
257
/* fields filled in by calling function */
203
 
   Int4        from_aln; /* from is in alignment coordinates */
204
 
   Int4        to_aln;   /* to is in alignment coordinates */
205
 
   Int4        row_num; /* which row the function wants to retrieve */
 
258
   Int4            from_aln; /* from is in alignment coordinates */
 
259
   Int4            to_aln;   /* to is in alignment coordinates */
 
260
   Int4            row_num; /* which row the function wants to retrieve */
 
261
 
206
262
/* fields filled in by AlnMgr2GetNextAlnBit */
207
 
   Int4        from_row;
208
 
   Int4        to_row;
209
 
   Uint1       strand;
210
 
   Uint1       type; /* AM_SEQ or AM_GAP */
211
 
   AMAdjacPtr  left_insert;
212
 
   AMAdjacPtr  right_insert;
213
 
   AMAdjacPtr  left_unaligned;
214
 
   AMAdjacPtr  right_unaligned;
 
263
   Int4            from_row;
 
264
   Int4            to_row;
 
265
   Uint1           strand;
 
266
   Uint1           type; /* AM_SEQ or AM_GAP */
 
267
   AMInterruptPtr  left_interrupt;
 
268
   AMInterruptPtr  right_interrupt;
 
269
 
215
270
/* fields used internally */
216
 
   Int4        len;
217
 
   Int4        real_from;
 
271
   Int4            len;
 
272
   Int4            real_from;
218
273
} AlnMsg2, PNTR AlnMsg2Ptr;
219
274
 
220
275
NLM_EXTERN AlnMsg2Ptr AlnMsgNew2(void);
226
281
   Int4  n2;
227
282
   Int4  n3;
228
283
   Int4  n4;
 
284
   Int4  n5;
229
285
   struct am_small PNTR next;
230
286
} AM_Small2, PNTR AM_Small2Ptr;
231
287
 
 
288
typedef struct am_consistset {
 
289
   Int4         numrows;
 
290
   Int4Ptr      starts;
 
291
   Int4Ptr      stops;
 
292
   Uint1Ptr     strands;
 
293
   SeqAlignPtr  sap;
 
294
   Int4         used;
 
295
   Int4Ptr      which;
 
296
   struct am_consistset PNTR next;
 
297
} AMConsSet, PNTR AMConsSetPtr;
 
298
 
232
299
typedef struct am_coreinf {
233
300
   Int4      start_core;
234
301
   Int4      len;
324
391
/***************************************************************************
325
392
*
326
393
*  SECTION 1: Functions for allocating and freeing data structures used
327
 
*  by the alignment manager.
 
394
*  by the alignment manager; copying functions are also here.
328
395
*
329
396
***************************************************************************/
330
397
NLM_EXTERN void AMFreqFree(AMFreqPtr afp);
331
398
NLM_EXTERN void AMAlignIndexFreeEitherIndex(SeqAlignPtr sap);
 
399
NLM_EXTERN SeqAlignPtr AlnMgr2DupAlnAndIndexes(SeqAlignPtr sap);
332
400
 
333
401
/***************************************************************************
334
402
*
376
444
*
377
445
***************************************************************************/
378
446
NLM_EXTERN void AlnMgr2IndexSeqAlign(SeqAlignPtr sap);
 
447
NLM_EXTERN void AlnMgr2IndexSeqAlignEx(SeqAlignPtr sap, Boolean replace_gi);
379
448
 
380
449
/***************************************************************************
381
450
*
387
456
***************************************************************************/
388
457
NLM_EXTERN void AlnMgr2ReIndexSeqAlign(SeqAlignPtr sap);
389
458
 
 
459
NLM_EXTERN Boolean AlnMgr2IndexAsRows(SeqAlignPtr sap, Uint1 strand, Boolean truncate);
 
460
 
390
461
/***************************************************************************
391
462
*
392
463
*  AlnMgr2IndexIndexedChain takes a linked list of indexed seqaligns
430
501
***************************************************************************/
431
502
NLM_EXTERN Boolean AlnMgr2GetNextAlnBit(SeqAlignPtr sap, AlnMsg2Ptr amp);
432
503
 
 
504
/* SECTION 4a */
 
505
/***************************************************************************
 
506
*
 
507
*  AlnMgr2GetInterruptInfo returns a structure describing the inserts and
 
508
*  unaligned regions in an interrupt. The structure is allocated by this
 
509
*  function and must be freed with AlnMgr2FreeInterruptInfo.
 
510
*
 
511
***************************************************************************/
 
512
NLM_EXTERN AMInterrInfoPtr AlnMgr2GetInterruptInfo(SeqAlignPtr sap, AMInterruptPtr interrupt);
 
513
 
433
514
/* SECTION 4b */
434
515
/***************************************************************************
435
516
*
454
535
*  AlnMgr2GetNthSeqRangeInSA returns the smallest and largest sequence
455
536
*  coordinates contained in the nth row of an indexed seqalign. Either
456
537
*  start or stop can be NULL to only retrieve one of the coordinates.
 
538
*  If start and stop are -1, there is an error; if they are both -2, the
 
539
*  row is just one big insert. RANGE
457
540
*
458
541
***************************************************************************/
459
542
NLM_EXTERN void AlnMgr2GetNthSeqRangeInSA(SeqAlignPtr sap, Int4 n, Int4Ptr start, Int4Ptr stop);
560
643
 
561
644
/***************************************************************************
562
645
*
 
646
*  AlnMgr2GetFirstNForSipList returns the first row that one of a list of seqids occur on,
 
647
*  or -1 if none of the seqids are in the alignment or if there is another
 
648
*  error. 
 
649
*  Handy if sip comes from a BioSeq, where it can point to a linked list
 
650
*  of SeqIds.
 
651
*
 
652
***************************************************************************/
 
653
NLM_EXTERN Int4 AlnMgr2GetFirstNForSipList(SeqAlignPtr sap, SeqIdPtr sip);
 
654
 
 
655
/***************************************************************************
 
656
*
563
657
*  AlnMgr2GetParent returns the top-level seqalign associated with a given
564
658
*  indexed alignment. It returns the actual pointer, not a copy.
565
659
*
658
752
*  'from' to 'to' in the row coordinates specified, or if which_row is 0,
659
753
*  'from' and 'to' are assumed to be alignment coordinates. If 'to' is -1,
660
754
*  the subalignment will go to the end of the specified row (or to the end
661
 
*  of the whole alignment).
 
755
*  of the whole alignment). If the alignment is discontinuous and fill_in
 
756
*  is FALSE, the alignment will be returned as an SAS_DISC set, each piece
 
757
*  represented by a single alignment. If the alignment is discontinuous and
 
758
*  fill_in is TRUE, the unaligned regions will be added in to the alignment,
 
759
*  with all gaps in all other rows. If the alignment is continuous, it
 
760
*  doesn't matter whether fill_in is TRUE or FALSE. (SUBALIGN)
662
761
*
663
762
***************************************************************************/
664
 
NLM_EXTERN SeqAlignPtr AlnMgr2GetSubAlign(SeqAlignPtr sap, Int4 from, Int4 to, Int4 row);
 
763
NLM_EXTERN SeqAlignPtr AlnMgr2GetSubAlign(SeqAlignPtr sap, Int4 from, Int4 to, Int4 which_row, Boolean fill_in);
665
764
 
666
765
/***************************************************************************
667
766
*
763
862
***************************************************************************/
764
863
NLM_EXTERN SeqAlignPtr AlnMgr2PadConservatively(SeqAlignPtr sap);
765
864
 
 
865
/***************************************************************************
 
866
*
 
867
*  AlnMgr2ExtractPairwiseSeqAlign takes an indexed alignment (parent or
 
868
*  child, but must be fully indexed, not lite) and extracts a pairwise
 
869
*  subalignment containing the two requested rows. The subalignment is
 
870
*  unindexed and may have internal unaligned regions.
 
871
*
 
872
***************************************************************************/
 
873
NLM_EXTERN SeqAlignPtr AlnMgr2ExtractPairwiseSeqAlign(SeqAlignPtr sap, Int4 n1, Int4 n2);
 
874
 
 
875
/***************************************************************************
 
876
*
 
877
*  AlnMgr2RemoveInconsistentAlnsFromSet takes an alignment that is
 
878
*  indexed at least at the AM2_LITE level, and prunes the child
 
879
*  alignments so that the remaining alignments form a consistent, 
 
880
*  nonoverlapping set. All alignments must have the same number of rows,
 
881
*  and they must be the same rows (although not necessarily in the same
 
882
*  order). The function uses a simple greedy algorithm to construct the
 
883
*  nonoverlapping set, starting with the highest-scoring alignment.
 
884
*  If fuzz is negative, the function creates the best nonoverlapping set
 
885
*  by actually truncating alignments.
 
886
*
 
887
***************************************************************************/
 
888
NLM_EXTERN void AlnMgr2RemoveInconsistentAlnsFromSet(SeqAlignPtr sap_head, Int4 fuzz);
 
889
 
 
890
/***************************************************************************
 
891
*
 
892
*  AlnMgr2FuseSet takes a set of alignments sharing all their rows and orders
 
893
*  the alignments, then fuses together any adjacent alignments. If returnall
 
894
*  is TRUE, all pieces are returned; if not, then only the largest piece is
 
895
*  returned. This function will work best when called after
 
896
*  AlnMgr2RemoveInconsistentAlnsFromSet(sap_head, -1).
 
897
*
 
898
***************************************************************************/
 
899
NLM_EXTERN SeqAlignPtr AlnMgr2FuseSet(SeqAlignPtr sap_head, Boolean returnall);
 
900
 
 
901
/* SECTION 11 -- functions for std-segs */
 
902
NLM_EXTERN Int4 AlignMgr2GetFirstNForStdSeg(SeqAlignPtr sap, SeqIdPtr sip);
 
903
NLM_EXTERN SeqIdPtr AlnMgr2GetNthSeqIdPtrStdSeg(SeqAlignPtr sap, Int4 n);
 
904
NLM_EXTERN void AlnMgr2GetNthSeqRangeInSAStdSeg(SeqAlignPtr sap, Int4 n, Int4Ptr start, Int4Ptr stop);
 
905
 
 
906
/***************************************************************************
 
907
*
 
908
*   AlnMgr2GetSeqRangeForSipInSAStdSeg  returns the smallest and largest sequence
 
909
*  coordinates in in a Std-Seg seqalign for a given Sequence Id.  Also return the 
 
910
*  strand type if it is the same on every segment, else set it to Seq_strand_unknown.
 
911
*  Either start, stop or strand can be NULL to only retrieve some of them.
 
912
*  If start and stop are -1, there is an error (not a std-seg), the SeqID does not participate in this
 
913
*  alignment or the alignment is one big insert on that id.  Returns true if the sip was found
 
914
*  in the alignment with real coordinates, i.e. *start would not be -1.  RANGE
 
915
*
 
916
***************************************************************************/
 
917
NLM_EXTERN Boolean AlnMgr2GetSeqRangeForSipInSAStdSeg(SeqAlignPtr sap, SeqIdPtr sip, Int4Ptr start, Int4Ptr stop, Uint1Ptr strand);
 
918
 
 
919
/***************************************************************************
 
920
*
 
921
*   AlnMgr2GetSeqRangeForSipInStdSeg  returns the start and stop sequence
 
922
*  coordinates in a Std-Segment for a given Sequence Id.  Also return the 
 
923
*  strand type.  Either start, stop, strand or segType can be NULL to only retrieve some of them.
 
924
*  Returns false if the SeqID was not found in this segment, so no meaningful 
 
925
*    data was passed back in other arguments.  
 
926
*  Returns true if the sip was found, even if it is a gap (start, stop = -1).
 
927
*  segType is set to AM_SEQ if the SeqID Sequence is not empty and one of 
 
928
*  the other sequences aligned with it is also not empty.  To AM_GAP if
 
929
*  the other sequences are all empty, and to AM_INSERT if the main sequence
 
930
*  is empty. 
 
931
*  RANGE
 
932
*
 
933
***************************************************************************/
 
934
NLM_EXTERN Boolean AlnMgr2GetSeqRangeForSipInStdSeg(
 
935
    StdSegPtr   ssp, 
 
936
    SeqIdPtr    sip, 
 
937
    Int4Ptr     start, 
 
938
    Int4Ptr     stop, 
 
939
    Uint1Ptr    strand,
 
940
    Uint1Ptr    segType); /* AM_SEQ, AM_GAP, AM_INSERT */
 
941
 
 
942
/***************************************************************************
 
943
*
 
944
*   AlnMgr2GetNthStdSeg  returns the a pointer to the Nth segment of
 
945
*   a standard segment alignment.
 
946
*   returns NULL if not n segments or is not a std-seg aligment.
 
947
*   Useful to pass its return value to AlnMgr2GetSeqRangeForSipInStdSeg()
 
948
*
 
949
***************************************************************************/
 
950
NLM_EXTERN StdSegPtr AlnMgr2GetNthStdSeg(SeqAlignPtr sap, Int2 n);
 
951
 
 
952
/***************************************************************************
 
953
*
 
954
*  AlnMgr2GetNumStdSegs returns the number of segments in a standar-seg alignment.
 
955
*   returns -1 if sap is null or not a standard-seg alignment.
 
956
*   the Std-Seg version of AlnMgr2GetNumSegs
 
957
*
 
958
***************************************************************************/
 
959
NLM_EXTERN Int4 AlnMgr2GetNumStdSegs(SeqAlignPtr sap);
 
960
 
 
961
/***************************************************************************
 
962
*
 
963
*  The two mapping functions act a little differently for std-segs. The
 
964
*  alignment coordinates are 1:1 linearly correlated with the longest
 
965
*  seqloc in the set; the others may be significantly shorter.
 
966
*  The mapping functions deal with % lengths, and map those instead of
 
967
*  coordinates (which may not be linear);
 
968
*
 
969
***************************************************************************/
 
970
NLM_EXTERN Int4 AlnMgr2MapBioseqToSeqAlignStdSeg(SeqAlignPtr sap, Int4 n, Int4 pos);
 
971
NLM_EXTERN Int4 AlnMgr2MapSeqAlignToBioseqStdSeg(SeqAlignPtr sap, Int4 n, Int4 pos);
 
972
NLM_EXTERN Int4 AlnMgr2GetAlnLengthStdSeg(SeqAlignPtr sap);
 
973
 
766
974
/***************************************************************************/
767
975
 
768
976