~ubuntu-branches/ubuntu/saucy/ncbi-tools6/saucy-proposed

« back to all changes in this revision

Viewing changes to algo/blast/core/blast_hspstream.h

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-08-11 22:03:47 UTC
  • mfrom: (1.4.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090811220347-g4b6lzdvphvvbpiu
* New upstream release.
* debian/libncbi6.symbols: update accordingly.
* debian/control: clean up obsolete or redundant relationship declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  $Id: blast_hspstream.h,v 1.6 2007/07/27 18:25:30 kazimird Exp $
 
1
/*  $Id: blast_hspstream.h,v 1.9 2009/05/27 17:39:36 kazimird Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
34
34
#ifndef ALGO_BLAST_CORE__BLAST_HSPSTREAM_H
35
35
#define ALGO_BLAST_CORE__BLAST_HSPSTREAM_H
36
36
 
 
37
#include <algo/blast/core/ncbi_std.h>
37
38
#include <algo/blast/core/blast_export.h>
38
39
#include <algo/blast/core/blast_hits.h>
39
40
#include <algo/blast/core/split_query.h>
 
41
#include <algo/blast/core/blast_program.h>
 
42
#include <algo/blast/core/blast_hits.h>
 
43
#include <algo/blast/core/blast_hspfilter.h>
 
44
#include <connect/ncbi_core.h>
40
45
 
41
46
#ifdef __cplusplus
42
47
extern "C" {
43
48
#endif
44
49
 
 
50
/** Auxiliary structure to allow sorting the results by score for the
 
51
 * composition-based statistics code */
 
52
typedef struct SSortByScoreStruct {
 
53
    Boolean sort_on_read;    /**< Should the results be sorted on the first read
 
54
                               call? */
 
55
    Int4 first_query_index;  /**< Index of the first query to try getting
 
56
                               results from */
 
57
} SSortByScoreStruct;
 
58
 
45
59
/** structure used to hold a collection of hits
46
60
    retrieved from the HSPStream */
47
61
typedef struct BlastHSPStreamResultBatch {
49
63
    BlastHSPList **hsplist_array;  /**< array of HSP lists returned */
50
64
} BlastHSPStreamResultBatch;
51
65
 
52
 
/** create a new batch to hold HSP results 
 
66
/** create a new batch to hold HSP results
53
67
 * @param num_hsplists Maximum number of results to hold
54
68
 * @return Pointer to newly allocated structure
55
69
 */
 
70
NCBI_XBLAST_EXPORT
56
71
BlastHSPStreamResultBatch * Blast_HSPStreamResultBatchInit(
57
72
                                            Int4 num_hsplists);
58
73
 
61
76
 * @param batch Structure to free
62
77
 * @return Always NULL
63
78
 */
 
79
NCBI_XBLAST_EXPORT
64
80
BlastHSPStreamResultBatch * Blast_HSPStreamResultBatchFree(
65
81
                                  BlastHSPStreamResultBatch *batch);
66
82
 
67
83
/** free the list of HSPLists within a batch
68
84
 * @param batch Structure to reset
69
85
 */
 
86
NCBI_XBLAST_EXPORT
70
87
void Blast_HSPStreamResultBatchReset(BlastHSPStreamResultBatch *batch);
71
88
 
72
 
/** The BlastHSPStream ADT is an opaque data type that defines a thread-safe
73
 
 *  interface which is used by the core BLAST code to save lists of HSPs.
74
 
 *  The interface currently provides the following services:
75
 
 *  - Management of the ADT (construction, destruction)
76
 
 *  - Writing lists of HSPs to the ADT
77
 
 *  - Reading lists of HSPs from the ADT
78
 
 *  - Merging two instances of the ADT
79
 
 *  .
80
 
 *  The default implementation simply buffers HSPs from one stage of the
81
 
 *  algorithm to the next @sa FIXME
82
 
 *  Implementations of this interface should provide functions for all
83
 
 *  the functions listed above.
84
 
 */
85
 
typedef struct BlastHSPStream BlastHSPStream;
86
 
 
87
 
/** Function pointer typedef to create a new BlastHSPStream structure.
88
 
 * First argument is a pointer to the structure to be populated (allocated for
89
 
 * client implementations), second argument should be typecast'd to the 
90
 
 * correct type by user-defined constructor function */
91
 
typedef BlastHSPStream* (*BlastHSPStreamConstructor) (BlastHSPStream*, void*);
92
 
 
93
 
/** Function pointer typedef to deallocate a BlastHSPStream structure.
94
 
 * Argument is the BlastHSPStream structure to free, always returns NULL. */
95
 
typedef BlastHSPStream* (*BlastHSPStreamDestructor) (BlastHSPStream*);
96
 
 
97
 
/** Function pointer typedef to implement the read/write functionality of the
98
 
 * BlastHSPStream. The first argument is the BlastHSPStream structure used, 
99
 
 * second argument is the list of HSPs to be saved/read (reading assumes
100
 
 * ownership, writing releases ownership) */
101
 
typedef int (*BlastHSPStreamMethod) (BlastHSPStream*, BlastHSPList**);
102
 
 
103
 
/** Function pointer typedef to implement the batch read functionality of the
104
 
 * BlastHSPStream. The first argument is the BlastHSPStream structure used, 
105
 
 * second argument is the list of HSP listss that are read (reading assumes
106
 
 * ownership) */
107
 
typedef int (*BlastHSPStreamBatchReadMethod) (BlastHSPStream*, 
108
 
                                              BlastHSPStreamResultBatch*);
109
 
 
110
 
/** Function pointer typedef to implement the merge functionality of the
111
 
 * BlastHSPStream. The first argument is the BlastHSPStream structure to merge, 
112
 
 * second argument is the BlastHSPStream that will contain the combined
113
 
 * result. Note that this function does not lock either of it inputs */
114
 
typedef int (*BlastHSPStreamMergeFnType) (SSplitQueryBlk*, Uint4,
115
 
                                     BlastHSPStream*, BlastHSPStream*);
116
 
 
117
 
/** Function pointer typedef to implement the close functionality of the 
118
 
 * BlastHSPStream. Argument is a pointer to the structure to close for 
119
 
 * writing.
120
 
 */
121
 
typedef void (*BlastHSPStreamCloseFnType) (BlastHSPStream*);
 
89
/** Default implementation of BlastHSPStream */
 
90
typedef struct BlastHSPStream {
 
91
   EBlastProgramType program;           /**< BLAST program type */
 
92
   Int4 num_hsplists;          /**< number of HSPlists saved */
 
93
   Int4 num_hsplists_alloc;    /**< number of entries in sorted_hsplists */
 
94
   BlastHSPList **sorted_hsplists; /**< list of all HSPlists from 'results'
 
95
                                       combined, sorted in order of
 
96
                                       decreasing subject OID */
 
97
   BlastHSPResults* results;/**< Structure for saving HSP lists */
 
98
   Boolean results_sorted;  /**< Have the results already been sorted?
 
99
                               Set to true after the first read call. */
 
100
   /**< Non-NULL if the results should be sorted by score as opposed to subject
 
101
    * OID. This is necessary to meet a pre-condition of the composition-based
 
102
    * statistics processing */
 
103
   SSortByScoreStruct* sort_by_score;
 
104
   MT_LOCK x_lock;   /**< Mutex for writing and reading results. */
 
105
   /* support for writer and pipes */
 
106
   BlastHSPWriter* writer;         /**< writer to be applied when writing*/
 
107
   Boolean writer_initialized;     /**< Is writer already initialized? */
 
108
   BlastHSPPipe *pre_pipe;         /**< registered preliminary pipeline (unused
 
109
                                    for now) */
 
110
   BlastHSPPipe *tback_pipe;       /**< registered traceback pipeline */
 
111
} BlastHSPStream;
122
112
 
123
113
/*****************************************************************************/
124
 
 
125
 
/** Structure that contains the information needed for BlastHSPStreamNew to 
126
 
 * fully populate the BlastHSPStream structure it returns */
127
 
typedef struct BlastHSPStreamNewInfo {
128
 
    BlastHSPStreamConstructor constructor; /**< User-defined function to 
129
 
                                           initialize a BlastHSPStream 
130
 
                                           structure */
131
 
    void* ctor_argument;                 /**< Argument to the above function */
132
 
} BlastHSPStreamNewInfo;
133
 
 
134
 
/** Allocates memory for a BlastHSPStream structure and then invokes the
135
 
 * constructor function defined in its first argument, passing the 
136
 
 * ctor_argument member of that same structure. If the constructor function
137
 
 * pointer is not set, NULL is returned.
138
 
 * @param bhsn_info Structure defining constructor and its argument to be
139
 
 *        invoked from this function [in]
 
114
/** Initialize the HSP stream. 
 
115
 * @param program Type of BlAST program [in]
 
116
 * @param extn_opts Extension options to determine composition-based statistics
 
117
 * mode [in]
 
118
 * @param sort_on_read Should results be sorted on the first read call? Only
 
119
 * applicable if composition-based statistics is on [in]
 
120
 * @param num_queries Number of query sequences in this BLAST search [in]
 
121
 * @param writer Writer to be registered [in]
140
122
 */
141
123
NCBI_XBLAST_EXPORT
142
 
BlastHSPStream* BlastHSPStreamNew(const BlastHSPStreamNewInfo* bhsn_info);
 
124
BlastHSPStream* BlastHSPStreamNew(EBlastProgramType program,
 
125
                             const BlastExtensionOptions* extn_opts,
 
126
                             Boolean sort_on_read,
 
127
                             Int4 num_queries,
 
128
                             BlastHSPWriter* writer);
143
129
 
144
 
/** Frees the BlastHSPStream structure by invoking the destructor function set 
 
130
/** Frees the BlastHSPStream structure by invoking the destructor function set
145
131
 * by the user-defined constructor function when the structure is initialized
146
132
 * (indirectly, by BlastHSPStreamNew). If the destructor function pointer is not
147
133
 * set, a memory leak could occur.
158
144
NCBI_XBLAST_EXPORT
159
145
void BlastHSPStreamClose(BlastHSPStream* hsp_stream);
160
146
 
 
147
/** Closes the BlastHSPStream structure after traceback. 
 
148
 * This is mainly to provide a chance to apply post-traceback pipes.
 
149
 * @param hsp_stream The stream to close [in] [out]
 
150
 * @param results The traceback results [in] [out]
 
151
 */
 
152
NCBI_XBLAST_EXPORT
 
153
void BlastHSPStreamTBackClose(BlastHSPStream* hsp_stream,
 
154
                              BlastHSPResults* results);
 
155
 
161
156
/** Moves the HSPlists from an HSPStream into the list contained
162
157
 * by a second HSPStream
163
158
 * @param squery_blk Information needed to map HSPs from one HSPstream
175
170
                        BlastHSPStream* combined_hsp_stream);
176
171
 
177
172
/** Standard error return value for BlastHSPStream methods */
 
173
NCBI_XBLAST_EXPORT
178
174
extern const int kBlastHSPStream_Error;
179
175
 
180
176
/** Standard success return value for BlastHSPStream methods */
 
177
NCBI_XBLAST_EXPORT
181
178
extern const int kBlastHSPStream_Success;
182
179
 
183
180
/** Return value when the end of the stream is reached (applicable to read
190
187
 * @param hsp_stream The BlastHSPStream object [in]
191
188
 * @param hsp_list List of HSPs for the HSPStream to keep track of. The caller
192
189
 * releases ownership of the hsp_list [in]
193
 
 * @return kBlastHSPStream_Success on success, otherwise kBlastHSPStream_Error 
 
190
 * @return kBlastHSPStream_Success on success, otherwise kBlastHSPStream_Error
194
191
 */
195
192
NCBI_XBLAST_EXPORT
196
193
int BlastHSPStreamWrite(BlastHSPStream* hsp_stream, BlastHSPList** hsp_list);
215
212
 * kBlastHSPStream_Eof on end of stream
216
213
 */
217
214
NCBI_XBLAST_EXPORT
218
 
int BlastHSPStreamBatchRead(BlastHSPStream* hsp_stream, 
 
215
int BlastHSPStreamBatchRead(BlastHSPStream* hsp_stream,
219
216
                            BlastHSPStreamResultBatch* batch);
220
217
 
221
 
/*****************************************************************************/
222
 
/* The following enumeration and function are only of interest to implementors
223
 
 * of this interface */
224
 
 
225
 
/** Defines the methods supported by the BlastHSPStream ADT */
226
 
typedef enum EMethodName {
227
 
    eConstructor,       /**< Constructor for a BlastHSPStream implementation */
228
 
    eDestructor,        /**< Destructor for a BlastHSPStream implementation */
229
 
    eRead,              /**< Read from the BlastHSPStream */
230
 
    eBatchRead,         /**< Batch read from the BlastHSPStream */
231
 
    eWrite,             /**< Write to the BlastHSPStream */
232
 
    eMerge,             /**< Merge with a second BlastHSPStream */
233
 
    eClose,             /**< Close the BlastHSPStream for writing */ 
234
 
    eMethodBoundary     /**< Limit to facilitate error checking */
235
 
} EMethodName;
236
 
 
237
 
/** Union to encapsulate the supported methods on the BlastHSPStream interface
238
 
 */
239
 
typedef union BlastHSPStreamFunctionPointerTypes {
240
 
   /** Used for read/write function pointers */
241
 
   BlastHSPStreamMethod method;        
242
 
   
243
 
   /** Used for constructor function pointer */
244
 
   BlastHSPStreamConstructor ctor;     
245
 
   
246
 
   /** Used for destructor function pointer */
247
 
   BlastHSPStreamDestructor dtor;      
248
 
 
249
 
   /** Use for merge function pointer */
250
 
   BlastHSPStreamMergeFnType mergeFn;
251
 
 
252
 
   /** Use for merge function pointer */
253
 
   BlastHSPStreamBatchReadMethod batch_read;
254
 
 
255
 
   /** Use for close function pointer */
256
 
   BlastHSPStreamCloseFnType closeFn;
257
 
} BlastHSPStreamFunctionPointerTypes;
258
 
 
259
 
/** Sets implementation specific data structure 
260
 
 * @param hsp_stream structure to initialize [in]
261
 
 * @param data structure to assign to the hsp_stream [in]
262
 
 * @return kBlastHSPStream_Error if hsp_stream is NULL else,
263
 
 * kBlastHSPStream_Success;
264
 
 */
265
 
NCBI_XBLAST_EXPORT
266
 
int SetData(BlastHSPStream* hsp_stream, void* data);
267
 
 
268
 
/** Gets implementation specific data structure 
269
 
 * @param hsp_stream structure from which to obtain the internal data. It is
270
 
 * expected that the caller (implementation of BlastHSPStream) knows what type
271
 
 * to cast the return value to. [in]
272
 
 * @return pointer to internal data structure of the implementation of the
273
 
 * BlastHSPStream, or NULL if hsp_stream is NULL
274
 
 */
275
 
NCBI_XBLAST_EXPORT
276
 
void* GetData(BlastHSPStream* hsp_stream);
277
 
 
278
 
/** Use this function to set the pointers to functions implementing the various
279
 
 * methods supported in the BlastHSPStream interface 
280
 
 * @param hsp_stream structure to initialize [in]
281
 
 * @param name method for which a function pointer is being provided [in]
282
 
 * @param fnptr_type union containing the pointer to the function specified by
283
 
 * name [in]
284
 
 * @return kBlastHSPStream_Error if hsp_stream is NULL else,
285
 
 * kBlastHSPStream_Success;
286
 
 */
287
 
NCBI_XBLAST_EXPORT
288
 
int SetMethod(BlastHSPStream* hsp_stream, 
289
 
               EMethodName name,
290
 
               BlastHSPStreamFunctionPointerTypes fnptr_type);
 
218
/** Attach a mutex lock to a stream to protect multiple access during writing
 
219
 * @param hsp_stream  The stream to attach [in]
 
220
 * @param lock        Pointer to locking structure for writing by multiple
 
221
 *                    threads. Locking will not be performed if NULL. [in]
 
222
 */
 
223
NCBI_XBLAST_EXPORT
 
224
int BlastHSPStreamRegisterMTLock(BlastHSPStream* hsp_stream,
 
225
                                 MT_LOCK lock);
 
226
 
 
227
/** Insert the user-specified pipe to the *end* of the pipeline.
 
228
 * @param hsp_stream The BlastHSPStream object [in]
 
229
 * @param pipe The pipe to be registered [in]
 
230
 * @param stage At what stage should this pipeline be applied [in]
 
231
 */
 
232
NCBI_XBLAST_EXPORT
 
233
int BlastHSPStreamRegisterPipe(BlastHSPStream* hsp_stream,
 
234
                               BlastHSPPipe* pipe,
 
235
                               EBlastStage stage);
291
236
 
292
237
#ifdef __cplusplus
293
238
}