1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 #include <vdb/extern.h>
27 
28 #include <sra/sradb.h>
29 #include <vdb/xform.h>
30 #include <klib/data-buffer.h>
31 #include <klib/rc.h>
32 #include <sysalloc.h>
33 
34 #include <string.h>
35 #include <assert.h>
36 
37 static
make_spot_desc(void * self,const VXformInfo * info,int64_t row_id,VRowResult * rslt,uint32_t argc,const VRowData argv[])38 rc_t CC make_spot_desc ( void *self, const VXformInfo *info, int64_t row_id,
39     VRowResult *rslt, uint32_t argc, const VRowData argv [] )
40 {
41     rc_t rc;
42     const uint32_t *spot_len   = argv[0].u.data.base;
43     const uint32_t *fixed_len  = argv[1].u.data.base;
44     const uint32_t *sig_len    = argv[2].u.data.base;
45     const int32_t *trim_start  = argv[3].u.data.base;
46     const uint32_t *trim_len   = argv[4].u.data.base;
47     const uint8_t *num_reads   = argv[5].u.data.base;
48 
49     SRASpotDesc *dst;
50 
51     num_reads += argv[5].u.data.first_elem; /* valid for argv[0].u.data.elem_count */
52     assert( argv[5].u.data.elem_bits == (sizeof( *num_reads ) * 8 ) );
53 
54     spot_len += argv[0].u.data.first_elem;
55     assert( argv[0].u.data.elem_bits == (sizeof( *spot_len ) * 8 ) );
56 
57     fixed_len += argv[1].u.data.first_elem;
58     assert( argv[1].u.data.elem_bits == (sizeof( *fixed_len ) * 8 ) );
59 
60     sig_len += argv[2].u.data.first_elem;
61     assert( argv[2].u.data.elem_bits == (sizeof( *sig_len ) * 8 ) );
62 
63     trim_start += argv[3].u.data.first_elem;
64     assert( argv[3].u.data.elem_bits == (sizeof( *trim_start ) * 8 ) );
65 
66     trim_len += argv[4].u.data.first_elem;
67     assert( argv[4].u.data.elem_bits == (sizeof( *trim_len ) * 8 ) );
68 
69     rslt->data->elem_bits = sizeof(*dst) * 8;
70 
71     rc = KDataBufferResize( rslt->data, 1 );
72     if ( rc == 0 )
73     {
74         dst = rslt->data->base;
75         dst->spot_len = (uint16_t)spot_len[0];
76         dst->fixed_len = (uint16_t)fixed_len[0];
77         dst->signal_len = (uint16_t)sig_len[0];
78         dst->clip_qual_right = (uint16_t)( trim_start[0]+trim_len[0] );
79         dst->num_reads = num_reads[0];
80 
81         memset( dst->align, 0, sizeof( dst->align ) );
82 
83         rslt->elem_bits = sizeof(*dst) * 8;
84         rslt->elem_count = 1;
85     }
86 
87     return rc;
88 }
89 
90 /*
91   function NCBI:SRA:SpotDesc NCBI:SRA:make_spot_desc
92        ( U32 spot_len, U32 fixed_len,  U32 sig_len,
93         INSDC:coord:zero trim_start, U32 trim_len, U8 num_reads )
94 
95  */
96 VTRANSFACT_IMPL( NCBI_SRA_make_spot_desc, 1, 0, 0 ) ( const void *self, const VXfactInfo *info,
97     VFuncDesc *rslt, const VFactoryParams *cp, const VFunctionParams *dp )
98 {
99     rslt -> u . rf = make_spot_desc;
100     rslt -> variant = vftRow;
101     return 0;
102 }
103