Debian Codegraph @

libs/sraxf/rewrite-spot-name.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 <sra/sradb.h>cxx . . $ `<file>/interfaces/sra/sradb.h`/
29 #include <vdb/xform.h>cxx . . $ `<file>/interfaces/vdb/xform.h`/
30 #include <vdb/table.h>cxx . . $ `<file>/interfaces/vdb/table.h`/
31 #include <kdb/meta.h>cxx . . $ `<file>/interfaces/kdb/meta.h`/
32 #include <klib/data-buffer.h>cxx . . $ `<file>/interfaces/klib/data-buffer.h`/
33 #include <klib/text.h>cxx . . $ `<file>/interfaces/klib/text.h`/
34 #include <klib/rc.h>cxx . . $ `<file>/interfaces/klib/rc.h`/
35 #include <sysalloc.h>cxx . . $ `<file>/interfaces/os/unix/sysalloc.h`/
36
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <os-native.h>cxx . . $ `<file>/interfaces/os/linux/os-native.h`/
42 #include <assert.h>
43
44
45 #define SLX_COORD_LENcxx . . $ `libs/sraxf/rewrite-spot-name.c:45:9`! 10
46
47 static
48 int non_braindead_atoicxx . . $ non_braindead_atoi(5ae29d726ae57f88). ( const char *start, const char *end )
49 {
50 int val = start [ 0 ] - '0';
51 uint32_tcxx . . $ uint32_t# i, count = (uint32_tcxx . . $ uint32_t#)( end - start );
52 for ( i = 1; i < count; ++ i )
53 {
54 val *= 10;
55 val += start [ i ] - '0';
56 }
57 return val;
58 }
59
60 static
61 int scan_hexcxx . . $ scan_hex(cb7559238bb26814). ( const char *str, int count )
62 {
63 int i, val = str [ 0 ] - '0';
64 if ( val > 9 )
65 val = touppercxx . . $ toupper(7864480464b09eea). ( str [ 0 ] ) - 'A' + 10;
66 for ( i = 1; i < count; ++ i )
67 {
68 int d = str [ i ] - '0';
69 if ( d > 9 )
70 d = touppercxx . . $ toupper(7864480464b09eea). ( str [ i ] ) - 'A' + 10;
71 val = val << 4 | d;
72 }
73 return val;
74 }
75
76 static
77 rc_tcxx . . $ rc_t# CCcxx . . $ `interfaces/kfc/callconv.h:44:11`! illumina_rewrite_spot_namecxx . . $ illumina_rewrite_spot_name(c7f02ef3aabbc98b). ( void *data, const VXformInfocxx . . $ VXformInfo# *info, int64_tcxx . . $ int64_t# row_id,
78 VRowResultcxx . . $ VRowResult# *rslt, uint32_tcxx . . $ uint32_t# argc, const VRowDatacxx . . $ VRowData# argv [] )
79 {
80 rc_tcxx . . $ rc_t# rc;
81 char buffer [ 64];
82 uint32_tcxx . . $ uint32_t# coord_len;
83 uint32_tcxx . . $ uint32_t# prefix_len;
84 unsigned int a, b, c, d;
85 KDataBuffercxx . . $ KDataBuffer# *dst = rslt -> datacxx . . $ VRowResult#data.;
86
87 const char *prefix;
88 const char *skey = argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . basecxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#base.;
89 uint64_tcxx . . $ uint64_t# i, j, count = argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . elem_countcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#elem_count.;
90
91 skey += argv [ 0 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . first_elemcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#first_elem.;
92
93 /* find last hex portion */
94 for ( i = count; i > 0; )
95 {
96 if ( ! isxdigitcxx . . $ `<external>/17904084882347303253/ctype.h:199:10`! ( skey [ -- i ] ) )
97 break;
98 }
99
100 if ( count - i < ( SLX_COORD_LENcxx . . $ `libs/sraxf/rewrite-spot-name.c:45:9`! - 1 ) )
101 {
102 const char *end = skey + count;
103
104 /* new format */
105 for ( d = 0, j = 0, i = count; i > 0; )
106 {
107 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( skey [ -- i ] ) )
108 {
109 j = i + 1;
110 break;
111 }
112 }
113 d = non_braindead_atoicxx . . $ non_braindead_atoi(5ae29d726ae57f88). ( & skey [ j ], end );
114 for ( c = 0, j = 0; i > 0; )
115 {
116 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( skey [ -- i ] ) )
117 {
118 j = i + 1;
119 break;
120 }
121 }
122 c = atoicxx . . $ atoi(5c4306d8553b3696). ( & skey [ j ] );
123 for ( b = 0, j = 0; i > 0; )
124 {
125 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( skey [ -- i ] ) )
126 {
127 j = i + 1;
128 break;
129 }
130 }
131 b = atoicxx . . $ atoi(5c4306d8553b3696). ( & skey [ j ] );
132 for ( a = 0, j = 0; i > 0; )
133 {
134 if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`! ( skey [ -- i ] ) )
135 {
136 j = i + 1;
137 break;
138 }
139 }
140 a = atoicxx . . $ atoi(5c4306d8553b3696). ( & skey [ j ] );
141 if ( j > 0 )
142 {
143 if ( i > 0 )
144 -- i;
145 while ( isalphacxx . . $ `<external>/17904084882347303253/ctype.h:190:10`! ( skey [ i ] ) )
146 ++ i;
147 }
148 }
149 else
150 {
151 a = scan_hexcxx . . $ scan_hex(cb7559238bb26814). ( skey, 1 );
152 b = scan_hexcxx . . $ scan_hex(cb7559238bb26814). ( & skey [ 1 ], 3 );
153 c = scan_hexcxx . . $ scan_hex(cb7559238bb26814). ( & skey [ 4 ], 3 );
154 d = scan_hexcxx . . $ scan_hex(cb7559238bb26814). ( & skey [ 7 ], 3 );
155 if ( count > SLX_COORD_LENcxx . . $ `libs/sraxf/rewrite-spot-name.c:45:9`! )
156 {
157 i = count - SLX_COORD_LENcxx . . $ `libs/sraxf/rewrite-spot-name.c:45:9`!;
158 }
159 }
160
161 /* generate coordinates */
162 #ifdef WINDOWS
163 coord_len = sprintf_s ( buffer, sizeof(buffer), ":%d:%d:%d:%d", a, b, c, d );
164 #else
165 coord_len = sprintfcxx . . $ sprintf(26c8642d26409d6d). ( buffer, ":%d:%d:%d:%d", a, b, c, d );
166 #endif
167
168 /* get size of prefix */
169 if ( argc == 1 )
170 {
171 prefix = "";
172 prefix_len = 0;
173 }
174 else
175 {
176 prefix = argv [ 1 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . basecxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#base.;
177 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(argv [ 1 ] . u . data . elem_count >> 32 == 0);
178 prefix_len = (uint32_tcxx . . $ uint32_t#)argv [ 1 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . elem_countcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#elem_count.;
179 prefix += argv [ 1 ] . ucxx . . $ VRowData#u. . datacxx . . $ VRowData#$anonymous_type_1#data. . first_elemcxx . . $ VRowData#$anonymous_type_1#$anonymous_type_2#first_elem.;
180 }
181
182 /* resize output buffer for prefix, name stuff, coordinates */
183 if ( dst -> elem_bitscxx . . $ KDataBuffer#elem_bits. != 8 )
184 {
185 rc = KDataBufferCastcxx . . $ KDataBufferCast(13b757a54c5fcf8d). ( dst, dst, 8, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! );
186 if ( rc != 0 )
187 return rc;
188 }
189 rc = KDataBufferResizecxx . . $ KDataBufferResize(daabdf243431d3e4). ( dst, prefix_len + i + coord_len + 1 );
190 if ( rc != 0 )
191 return rc;
192
193 /* copy in prefix, name prefix, coordinates */
194 #ifdef WINDOWS
195 rslt -> elem_count = sprintf_s ( dst -> base, dst -> elem_count, "%.*s%.*s%s"
196 , ( int ) prefix_len, prefix
197 , ( int ) i, skey
198 , buffer );
199 #else
200 rslt -> elem_countcxx . . $ VRowResult#elem_count. = sprintfcxx . . $ sprintf(26c8642d26409d6d). ( dst -> basecxx . . $ KDataBuffer#base., "%.*s%.*s%s"
201 , ( int ) prefix_len, prefix
202 , ( int ) i, skey
203 , buffer );
204 #endif
205
206 return 0;
207 }
208
209 /* rewrite_spot_name
210 * given an old spotname directly from skey
211 * write according to platform rules, optionally with a prefix
212 *
213 * "platform" [ CONST ] - which platform rules to use
214 *
215 * "skey" [ DATA ] - skey string for row
216 *
217 * "prefix" [ DATA, OPTIONAL ] - prefix for spot
218 */
219 VTRANSFACT_IMPLcxx . . $ `interfaces/vdb/xform.h:791:9`! ( NCBI_SRA_rewrite_spot_name, 1, 0, 0 ) ( const void *self,
220 const VXfactInfocxx . . $ VXfactInfo# *info, VFuncDesccxx . . $ VFuncDesc# *rslt, const VFactoryParamscxx . . $ VFactoryParams# *cp, const VFunctionParamscxx . . $ VFunctionParams# *dp )
221 {
222 const uint8_tcxx . . $ uint8_t# *platform = cp -> argvcxx . . $ VFactoryParams#argv. [ 0 ] . datacxx . . $ VFactoryParams#$anonymous_type_4#data. . u8cxx . . $ VFactoryParams#$anonymous_type_4#$anonymous_type_5#u8.;
223 switch ( platform [ 0 ] )
224 {
225 case SRA_PLATFORM_ILLUMINAcxx . . $ SRA_PLATFORM_ILLUMINA.:
226 break;
227 default:
228 return RCcxx . . $ `interfaces/klib/rc.h:111:9`! ( rcSRA, rcFunction, rcConstructing, rcType, rcUnsupported );
229 }
230
231 rslt -> ucxx . . $ VFuncDesc#u. . ndfcxx . . $ VFuncDesc#$anonymous_type_7#ndf. = illumina_rewrite_spot_namecxx . . $ illumina_rewrite_spot_name(c7f02ef3aabbc98b).;
232 rslt -> variantcxx . . $ VFuncDesc#variant. = vftNonDetRowcxx . . $ vftNonDetRow.;
233 return 0;
234 }