Debian Codegraph @

src/match.c

raw symbols SCIP
1 /*
2 matches.c - sequence match scoring for scythe.
3 */
4 #include <assert.h>
5 #include <limits.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include "scythe.h"cxx . . $ `<file>/src/scythe.h`/
10
11 int *score_sequencecxx . . $ score_sequence(573e900797376e94).(int *matches, const char *seq, const char *pattern, size_t n) {
12 /*
13 Score a string using constant match and mismatch scores. Assumes
14 seq is longer than or of equal length to pattern. Only the first
15 n characters of pattern and seq are scored. We explicitly error
16 out of in the case of a null byte.
17
18
19 [----------seq-------------------]
20 |----pattern-----|
21
22 */
23 size_t i;
24 /* These are addressed by the assert below
25 assert(strlen(seq) >= n);
26 assert(strlen(pattern) >= n);
27 */
28 for (i = 0; i < n; i++) {
29 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(seq[i] && pattern[i]); /* no string termination */
30 if (seq[i] == pattern[i])
31 matches[i] = MATCH_SCOREcxx . . $ `src/scythe.h:26:9`!;
32 else
33 matches[i] = MISMATCH_SCOREcxx . . $ `src/scythe.h:27:9`!;
34 }
35 return matches;
36 }
37
38 matchcxx . . $ match# *find_best_matchcxx . . $ find_best_match(745595b130767423).(const adapter_arraycxx . . $ adapter_array# *aa, const char *read,
39 float *p_quals, float prior, float p_match, int min_l) {
40 /*
41 Take an adapter array, and check the read against all
42 adapters. Brute force string matching is used. This is to avoid
43 approximate matching algorithms which required an a priori
44 specified number mismatches.
45
46 */
47
48 matchcxx . . $ match# *best_match=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
49 int i, shift, max_shift, found_contam=0;
50 size_t al, rl = strlencxx . . $ strlen(751346f8406fd082).(read);
51 int *best_arr=xmalloccxx . . $ xmalloc(bfcfa4d6b7f7ef64).(sizeof(int) * rl), best_adapter=0, best_length=0, best_shift=0, best_score=INT_MINcxx . . $ `<external>/67164224788392828/limits.h:118:9`!;
52 int curr_score, *curr_arr=xmalloccxx . . $ xmalloc(bfcfa4d6b7f7ef64).(sizeof(int) * rl);
53 posterior_setcxx . . $ posterior_set# *ps=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
54 float *best_p_quals=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
55
56 max_shift = rl - min_l;
57 for (shift = 0; shift < max_shift; shift++) {
58 for (i = 0; i < aa->ncxx . . $ adapter_array#n.; i++) {
59 if (min_l >= aa->adapterscxx . . $ adapter_array#adapters.[i].lengthcxx . . $ adapter#length.) {
60 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Minimum match length (option -n) greater than or " \
61 "equal to length of adapter.\n");
62 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
63 }
64 al = mincxx . . $ `src/scythe.h:30:9`!(aa->adapters[i].length, rl - shift);
65 score_sequencecxx . . $ score_sequence(573e900797376e94).(curr_arr, &(read)[shift], (aa->adapterscxx . . $ adapter_array#adapters.[i]).seqcxx . . $ adapter#seq., al);
66 curr_score = sumcxx . . $ sum(1ec4c99060f826b5).(curr_arr, al);
67 if (curr_score > best_score) {
68 best_score = curr_score;
69 best_length = al;
70 best_shift = shift;
71 best_p_quals = &(p_quals)[shift];
72 for (size_t iii = 0; iii < al; iii++)
73 best_arr[iii] = curr_arr[iii];
74 best_adapter = i;
75 ps = posteriorcxx . . $ posterior(eda8e32dde0ec8a5).(best_arr, best_p_quals, prior, 0.25, best_length);
76 found_contam = ps->is_contamcxx . . $ posterior_set#is_contam.;
77 if (found_contam) {
78 break;
79 } else {
80 freecxx . . $ free(5d22bdacc48458e8).(ps);
81 ps=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
82 }
83 }
84 }
85 if (found_contam)
86 break;
87 }
88 freecxx . . $ free(5d22bdacc48458e8).(curr_arr);
89 curr_arr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
90
91 if (!found_contam) {
92 /* no match found */
93 freecxx . . $ free(5d22bdacc48458e8).(best_arr);
94 best_arr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
95 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
96 }
97 best_arr = realloccxx . . $ realloc(417ab160f6baadc6).(best_arr, sizeof(*best_arr) * best_length);
98 /* save this match */
99 best_match = xmalloccxx . . $ xmalloc(bfcfa4d6b7f7ef64).(sizeof(matchcxx . . $ match#));
100 best_match->matchcxx . . $ match#match. = best_arr;
101 best_match->shiftcxx . . $ match#shift. = best_shift;
102 best_match->lengthcxx . . $ match#length. = best_length;
103 best_match->pscxx . . $ match#ps. = ps;
104 best_match->scorecxx . . $ match#score. = best_score;
105 best_match->adapter_indexcxx . . $ match#adapter_index. = best_adapter;
106 best_match->p_qualscxx . . $ match#p_quals. = best_p_quals;
107 best_match->match_poscxx . . $ match#match_pos. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(best_length, sizeof(int));
108 for (i = 0; i < best_length; i++)
109 best_match->match_poscxx . . $ match#match_pos.[i] = best_match->matchcxx . . $ match#match.[i] == MATCH_SCOREcxx . . $ `src/scythe.h:26:9`!;
110 return best_match;
111 }
112
113 void destroy_matchcxx . . $ destroy_match(972520b2cfa848f0).(matchcxx . . $ match# *m) {
114 /*
115 Free all memory taken by this match object. m->p_quals is not
116 freed, as this is points to an array allocated within main().
117 */
118 freecxx . . $ free(5d22bdacc48458e8).(m->matchcxx . . $ match#match.);
119 freecxx . . $ free(5d22bdacc48458e8).(m->match_poscxx . . $ match#match_pos.);
120 freecxx . . $ free(5d22bdacc48458e8).(m->pscxx . . $ match#ps.);
121 freecxx . . $ free(5d22bdacc48458e8).(m);
122 }
123