Debian Codegraph @

libs/vxf/wgs-tokenize-accession.c

raw symbols SCIP
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>cxx . . $ `<file>/interfaces/vdb/extern.h`/
27
28 #include <vdb/xform.h>cxx . . $ `<file>/interfaces/vdb/xform.h`/
29 #include <vdb/schema.h>cxx . . $ `<file>/interfaces/vdb/schema.h`/
30 #include <klib/data-buffer.h>cxx . . $ `<file>/interfaces/klib/data-buffer.h`/
31 #include <klib/text.h>cxx . . $ `<file>/interfaces/klib/text.h`/
32 #include <klib/printf.h>cxx . . $ `<file>/interfaces/klib/printf.h`/
33 #include <klib/rc.h>cxx . . $ `<file>/interfaces/klib/rc.h`/
34 #include <sysalloc.h>cxx . . $ `<file>/interfaces/os/unix/sysalloc.h`/
35
36 #include <stdlib.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <os-native.h>cxx . . $ `<file>/interfaces/os/linux/os-native.h`/
40 #include <assert.h>
41
42 enumcxx . . $ $anonymous_type_554a64fcfb4c5e32_0#
43 {
44 NCBI_WGS_acc_token_unrecognizedcxx . . $ NCBI_WGS_acc_token_unrecognized. = 1,
45 NCBI_WGS_acc_token_prefixcxx . . $ NCBI_WGS_acc_token_prefix.,
46 NCBI_WGS_acc_token_contigcxx . . $ NCBI_WGS_acc_token_contig.
47 };
48
49 enumcxx . . $ $anonymous_type_554a64fcfb4c5e32_1#
50 {
51 TTextToken_idcxx . . $ TTextToken_id.,
52 TTextToken_startcxx . . $ TTextToken_start.,
53 TTextToken_lencxx . . $ TTextToken_len.
54 };
55
56
57 static
58 uint32_tcxx . . $ uint32_t# ParseWgsAccessioncxx . . $ ParseWgsAccession(b71279ec1935ea78). ( uint16_tcxx . . $ uint16_t# *tok, const char *acc, size_t acc_len )
59 {
60 /* WGS accessions have form:
61 * [NZ_]<4-letter prefix><2-digit version><6-7 digit contig>
62 */
63 size_t i;
64
65 /* scan non-digits */
66 for ( i = 0; i < acc_len; ++ i )
67 {
68 if ( isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( acc [ i ] ) )
69 break;
70 }
71
72 /* require at least 4 characters... */
73 if ( i >= 4 )
74 {
75 /* require at least 8 digits */
76 if ( acc_len - i >= 8 )
77 {
78 /* 2-digit version */
79 if ( isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( acc [ ++ i ] ) )
80 {
81 /* record first token as prefix */
82 tok [ 0 + TTextToken_idcxx . . $ TTextToken_id. ] = NCBI_WGS_acc_token_prefixcxx . . $ NCBI_WGS_acc_token_prefix.;
83 tok [ 0 + TTextToken_startcxx . . $ TTextToken_start. ] = 0;
84 tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) ++ i;
85
86 /* the remainder should be contig */
87 tok [ 3 + TTextToken_idcxx . . $ TTextToken_id. ] = NCBI_WGS_acc_token_contigcxx . . $ NCBI_WGS_acc_token_contig.;
88 tok [ 3 + TTextToken_startcxx . . $ TTextToken_start. ] = ( uint16_tcxx . . $ uint16_t# ) i;
89 tok [ 3 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) ( acc_len - i );
90
91 /* verify that it is numeric */
92 for ( ; i < acc_len; ++ i )
93 {
94 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( acc [ i ] ) )
95 break;
96 }
97
98 /* great success */
99 if ( i == acc_len )
100 return 2;
101 }
102 }
103 }
104
105 tok [ 0 + TTextToken_idcxx . . $ TTextToken_id. ] = NCBI_WGS_acc_token_unrecognizedcxx . . $ NCBI_WGS_acc_token_unrecognized.;
106 tok [ 0 + TTextToken_startcxx . . $ TTextToken_start. ] = 0;
107 tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) acc_len;
108
109 return 1;
110 }
111
112 static
113 rc_tcxx . . $ rc_t# CCcxx . . $ `interfaces/kfc/callconv.h:44:11`! tokenize_nuc_accessioncxx . . $ tokenize_nuc_accession(c7f02ef3aabbc98b). ( void *obj,
114 const VXformInfocxx . . $ VXformInfo# *info, int64_tcxx . . $ int64_t# row_id, VRowResultcxx . . $ VRowResult# *rslt,
115 uint32_tcxx . . $ uint32_t# argc, const VRowDatacxx . . $ VRowData# argv [] )
116 {
117 rc_tcxx . . $ rc_t# rc;
118 const char *acc;
119
120 assertcxx . . $ `/usr/include/assert.h:118:11`! ( rslt -> elem_bits == 16 * 3 );
121
122 rslt -> datacxx . . $ VRowResult#data. -> elem_bitscxx . . $ KDataBuffer#elem_bits. = rslt -> elem_bitscxx . . $ VRowResult#elem_bits.;
123 rc = KDataBufferResizecxx . . $ KDataBufferResize(daabdf243431d3e4). ( rslt -> datacxx . . $ VRowResult#data., 2 );
124 if ( rc != 0 )
125 return rc;
126
127 acc = argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . basecxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#base.;
128 acc += argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . first_elemcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#first_elem.;
129
130 rslt -> elem_countcxx . . $ VRowResult#elem_count. = ParseWgsAccessioncxx . . $ ParseWgsAccession(b71279ec1935ea78). ( rslt -> datacxx . . $ VRowResult#data. -> basecxx . . $ KDataBuffer#base., acc, argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . elem_countcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#elem_count. );
131 if ( rslt -> elem_countcxx . . $ VRowResult#elem_count. != 2 )
132 rc = KDataBufferResizecxx . . $ KDataBufferResize(daabdf243431d3e4). ( rslt -> datacxx . . $ VRowResult#data., rslt -> elem_countcxx . . $ VRowResult#elem_count. );
133
134 return rc;
135 }
136
137 static
138 uint32_tcxx . . $ uint32_t# ParseProtAccessioncxx . . $ ParseProtAccession(b71279ec1935ea78). ( uint16_tcxx . . $ uint16_t# *tok, const char *acc, size_t acc_len )
139 {
140 /* Protein accessions generally have pattern
141 * <Cap-letter prefix><digital suffix>
142 * If this doesn't hold, use full accession as prefix, and make suffix empty.
143 */
144 size_t i;
145
146 for ( i = 0; i < acc_len; ++ i )
147 {
148 if ( isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( acc [ i ] ) )
149 break;
150 }
151
152 tok [ 0 + TTextToken_idcxx . . $ TTextToken_id. ] = NCBI_WGS_acc_token_prefixcxx . . $ NCBI_WGS_acc_token_prefix.;
153 tok [ 0 + TTextToken_startcxx . . $ TTextToken_start. ] = 0;
154 tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) i;
155
156 for ( ; i < acc_len; ++ i )
157 {
158 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( acc [ i ] ) )
159 break;
160 }
161
162 if ( i == acc_len )
163 {
164 tok [ 3 + TTextToken_idcxx . . $ TTextToken_id. ] = NCBI_WGS_acc_token_contigcxx . . $ NCBI_WGS_acc_token_contig.;
165 tok [ 3 + TTextToken_startcxx . . $ TTextToken_start. ] = tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ];
166 tok [ 3 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) ( i - tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ] );
167 return 2;
168 }
169
170 tok [ 0 + TTextToken_lencxx . . $ TTextToken_len. ] = ( uint16_tcxx . . $ uint16_t# ) acc_len;
171 return 1;
172 }
173
174 static
175 rc_tcxx . . $ rc_t# CCcxx . . $ `interfaces/kfc/callconv.h:44:11`! tokenize_prot_accessioncxx . . $ tokenize_prot_accession(c7f02ef3aabbc98b). ( void *obj,
176 const VXformInfocxx . . $ VXformInfo# *info, int64_tcxx . . $ int64_t# row_id, VRowResultcxx . . $ VRowResult# *rslt,
177 uint32_tcxx . . $ uint32_t# argc, const VRowDatacxx . . $ VRowData# argv [] )
178 {
179 rc_tcxx . . $ rc_t# rc;
180 const char *acc;
181
182 assertcxx . . $ `/usr/include/assert.h:118:11`! ( rslt -> elem_bits == 16 * 3 );
183
184 rslt -> datacxx . . $ VRowResult#data. -> elem_bitscxx . . $ KDataBuffer#elem_bits. = rslt -> elem_bitscxx . . $ VRowResult#elem_bits.;
185 rc = KDataBufferResizecxx . . $ KDataBufferResize(daabdf243431d3e4). ( rslt -> datacxx . . $ VRowResult#data., 2 );
186 if ( rc != 0 )
187 return rc;
188
189 acc = argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . basecxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#base.;
190 acc += argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . first_elemcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#first_elem.;
191
192 rslt -> elem_countcxx . . $ VRowResult#elem_count. = ParseProtAccessioncxx . . $ ParseProtAccession(b71279ec1935ea78). ( rslt -> datacxx . . $ VRowResult#data. -> basecxx . . $ KDataBuffer#base., acc, argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . elem_countcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#elem_count. );
193 if ( rslt -> elem_countcxx . . $ VRowResult#elem_count. != 2 )
194 rc = KDataBufferResizecxx . . $ KDataBufferResize(daabdf243431d3e4). ( rslt -> datacxx . . $ VRowResult#data., rslt -> elem_countcxx . . $ VRowResult#elem_count. );
195
196 return rc;
197 }
198
199 VTRANSFACT_IMPLcxx . . $ `interfaces/vdb/xform.h:791:9`! ( NCBI_WGS_tokenize_nuc_accession, 1, 0, 0 ) ( const void *self, const VXfactInfocxx . . $ VXfactInfo# *info,
200 VFuncDesccxx . . $ VFuncDesc# *rslt, const VFactoryParamscxx . . $ VFactoryParams# *cp, const VFunctionParamscxx . . $ VFunctionParams# *dp )
201 {
202 rslt -> ucxx . . $ VFuncDesc#u. . rfcxx . . $ VFuncDesc#$anonymous_type_7#rf. = tokenize_nuc_accessioncxx . . $ tokenize_nuc_accession(c7f02ef3aabbc98b).;
203 rslt -> variantcxx . . $ VFuncDesc#variant. = vftRowcxx . . $ vftRow.;
204 return 0;
205 }
206
207 VTRANSFACT_IMPLcxx . . $ `interfaces/vdb/xform.h:791:9`! ( NCBI_WGS_tokenize_prot_accession, 1, 0, 0 ) ( const void *self, const VXfactInfocxx . . $ VXfactInfo# *info,
208 VFuncDesccxx . . $ VFuncDesc# *rslt, const VFactoryParamscxx . . $ VFactoryParams# *cp, const VFunctionParamscxx . . $ VFunctionParams# *dp )
209 {
210 rslt -> ucxx . . $ VFuncDesc#u. . rfcxx . . $ VFuncDesc#$anonymous_type_7#rf. = tokenize_prot_accessioncxx . . $ tokenize_prot_accession(c7f02ef3aabbc98b).;
211 rslt -> variantcxx . . $ VFuncDesc#variant. = vftRowcxx . . $ vftRow.;
212 return 0;
213 }