| 1 |
/* |
| 2 |
Scythe - A Simple Bayesian Adapter Contamination Trimmer |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <assert.h> |
| 6 |
#include <ctype.h> |
| 7 |
#include <limits.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
#include <getopt.h> |
| 12 |
#include <zlib.h> |
| 13 |
|
| 14 |
#include "scythe.h"cxx . . $ `<file>/src/scythe.h`/ |
| 15 |
#include "kseq.h"cxx . . $ `<file>/src/kseq.h`/ |
| 16 |
|
| 17 |
__KSEQ_BASICcxx . . $ `src/kseq.h:151:9`!(static, gzFile) |
| 18 |
__KS_GETCcxx . . $ `src/kseq.h:66:9`!(gzread, BUFFER_SIZEcxx . . $ `src/scythe.h:20:9`!) |
| 19 |
__KS_GETUNTILcxx . . $ `src/kseq.h:91:9`!(gzread, BUFFER_SIZEcxx . . $ `src/scythe.h:20:9`!) |
| 20 |
__KSEQ_READcxx . . $ `src/kseq.h:171:9`!(static) |
| 21 |
|
| 22 |
static const float default_priorcxx . . $ default_prior. = 0.3; |
| 23 |
|
| 24 |
#ifndef PROGRAM_NAME |
| 25 |
#define PROGRAM_NAMEcxx . . $ `src/scythe.c:25:9`! "scythe" |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef AUTHORS |
| 29 |
#define AUTHORScxx . . $ `src/scythe.c:29:9`! "Vince Buffalo, UC Davis\nEmail: <[email protected]> (poly-A tail removed)" |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef VERSIONcxx . . $ `<built-in>:410:9`! |
| •33 |
#define VERSION "0.994" |
| 34 |
#endif |
| 35 |
|
| 36 |
/* Options drawn from GNU's coreutils/src/system.h */ |
| 37 |
/* These options are defined so as to avoid conflicting with option |
| 38 |
values used by commands */ |
| 39 |
enumcxx . . $ $anonymous_type_d290fad4f1a7c840_0# { |
| 40 |
GETOPT_HELP_CHARcxx . . $ GETOPT_HELP_CHAR. = (CHAR_MINcxx . . $ `<external>/67164224788392828/limits.h:97:10`! - 2), |
| 41 |
GETOPT_VERSION_CHARcxx . . $ GETOPT_VERSION_CHAR. = (CHAR_MINcxx . . $ `<external>/67164224788392828/limits.h:97:10`! - 3) |
| 42 |
}; |
| 43 |
#define GETOPT_HELP_OPTION_DECLcxx . . $ `src/scythe.c:43:9`! \ |
| 44 |
"help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, GETOPT_HELP_CHAR |
| 45 |
#define GETOPT_VERSION_OPTION_DECLcxx . . $ `src/scythe.c:45:9`! \ |
| 46 |
"version", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, GETOPT_VERSION_CHAR |
| 47 |
#define case_GETOPT_HELP_CHARcxx . . $ `src/scythe.c:47:9`! \ |
| 48 |
case GETOPT_HELP_CHAR: \ |
| 49 |
usage(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!); \ |
| 50 |
break; |
| 51 |
#define case_GETOPT_VERSION_CHARcxx . . $ `src/scythe.c:51:9`!(Program_name, Version, Authors) \ |
| 52 |
case GETOPT_VERSION_CHAR: \ |
| •53 |
fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s version %s\nCopyright (c) 2011 The Regents " \ |
| 54 |
"of University of California, Davis Campus.\n" \ |
| 55 |
"%s is free software and comes with ABSOLUTELY NO WARRANTY.\n" \ |
| 56 |
"Distributed under the MIT License.\n\nWritten by %s\n", \ |
| •57 |
Program_name, Version, Program_name, Authors); \ |
| 58 |
exit(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!); \ |
| 59 |
break; |
| 60 |
/* end code drawn from system.h */ |
| 61 |
|
| 62 |
|
| 63 |
static struct optioncxx . . $ option# long_optionscxx . . $ long_options.[] = { |
| 64 |
/* Options with an argument */ |
| 65 |
{"adapter-file", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'a'}, |
| 66 |
{"prior", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'p'}, |
| 67 |
{"partial", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'P'}, |
| 68 |
{"quality-type", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'q'}, |
| 69 |
{"matches-file", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'm'}, |
| 70 |
{"output-file", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'c'}, |
| 71 |
{"min-match", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'n'}, |
| 72 |
{"min-keep", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'M'}, |
| 73 |
{"quiet", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 'Q'}, |
| 74 |
{"tag", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 't'}, |
| 75 |
{GETOPT_HELP_OPTION_DECLcxx . . $ `src/scythe.c:43:9`!}, |
| 76 |
{GETOPT_VERSION_OPTION_DECLcxx . . $ `src/scythe.c:45:9`!}, |
| 77 |
{NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0} |
| 78 |
}; |
| 79 |
|
| 80 |
void usagecxx . . $ usage(d4f767463ce0a6b3).(int status) { |
| 81 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("\nUsage: scythe -a adapter_file.fasta sequence_file.fastq\n\ |
| 82 |
Trim 3'-end adapter contaminants off sequence files. If no output file\n\ |
| 83 |
is specified, scythe will use stdout.\n\ |
| 84 |
\n\ |
| 85 |
Options:\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 86 |
printfcxx . . $ printf(581fddd72a8db8fc).("\ |
| 87 |
-p, --prior prior (default: %0.3f)\n", default_priorcxx . . $ default_prior.); |
| 88 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("\ |
| 89 |
-q, --quality-type quality type, either illumina, solexa, or sanger (default: sanger)\n\ |
| 90 |
-m, --matches-file matches file (default: no output)\n\ |
| 91 |
-o, --output-file output trimmed sequences file (default: stdout)\n\ |
| 92 |
-t, --tag add a tag to the header indicating Scythe cut a sequence (default: off)\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 93 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("\ |
| 94 |
-n, --min-match smallest contaminant to consider (default: 5)\n\ |
| 95 |
-M, --min-keep filter sequnces less than or equal to this length (default: 35)\n\ |
| 96 |
--quiet don't output statistics about trimming to stdout (default: off)\n\ |
| 97 |
--help display this help and exit\n\ |
| 98 |
--version output version information and exit\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 99 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("\n\ |
| 100 |
Information on quality schemes:\n\ |
| 101 |
phred PHRED quality scores (e.g. from Roche 454). ASCII with no offset, range: [4, 60].\n\ |
| 102 |
sanger Sanger are PHRED ASCII qualities with an offset of 33, range: [0, 93]. From \n\ |
| 103 |
NCBI SRA, or Illumina pipeline 1.8+.\n\ |
| 104 |
solexa Solexa (also very early Illumina - pipeline < 1.3). ASCII offset of\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 105 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("\ |
| 106 |
64, range: [-5, 62]. Uses a different quality-to-probabilities conversion than other\n\ |
| 107 |
schemes.\n\ |
| 108 |
illumina Illumina output from pipeline versions between 1.3 and 1.7. ASCII offset of 64,\n\ |
| 109 |
range: [0, 62]\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 110 |
exitcxx . . $ exit(3ca292c338df9bb3).(status); |
| 111 |
} |
| 112 |
|
| 113 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) { |
| 114 |
kseq_tcxx . . $ kseq_t# *seq; |
| 115 |
int l, index, shift, min=5, min_keep=35; |
| 116 |
int debug=0, verbose=1; |
| 117 |
int contaminated=0, total=0; |
| 118 |
quality_typecxx . . $ quality_type# qual_type=SANGERcxx . . $ SANGER.; |
| 119 |
matchcxx . . $ match# *best_match; |
| 120 |
float *qprobs, prior=default_priorcxx . . $ default_prior.; |
| 121 |
adapter_arraycxx . . $ adapter_array# *aa; |
| 122 |
gzFilecxx . . $ gzFile# adapter_fp=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, fp; |
| 123 |
FILEcxx . . $ FILE# *output_fp=stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, *matches_fp=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 124 |
int optc; |
| 125 |
int add_tag = 0; |
| 126 |
extern char *optargcxx . . $ optarg.; |
| 127 |
|
| 128 |
while (1) { |
| 129 |
int option_index = 0; |
| 130 |
optc = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "dtfp:a:o:q:m:o:n:M:", long_optionscxx . . $ long_options., &option_index); |
| 131 |
|
| 132 |
if (optc == -1) |
| 133 |
break; |
| 134 |
switch (optc) { |
| 135 |
if (long_optionscxx . . $ long_options.[option_index].flagcxx . . $ option#flag. != 0) |
| 136 |
break; |
| 137 |
case 'a': |
| 138 |
adapter_fp = gzopencxx . . $ gzopen(e549dd1a5168a7e3).(optargcxx . . $ optarg., "r"); |
| 139 |
if (!adapter_fp) { |
| 140 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Could not open adapter file '%s'.\n", optargcxx . . $ optarg.); |
| 141 |
return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 142 |
} |
| 143 |
break; |
| 144 |
case 'd': |
| 145 |
debug = 1; |
| 146 |
break; |
| 147 |
case 't': |
| 148 |
add_tag = 1; |
| 149 |
break; |
| 150 |
case 'Q': |
| 151 |
verbose = 0; |
| 152 |
break; |
| 153 |
case 'o': |
| 154 |
output_fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(optargcxx . . $ optarg., "w"); |
| 155 |
if (!output_fp) { |
| 156 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Could not open output file '%s'.\n", optargcxx . . $ optarg.); |
| 157 |
return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 158 |
} |
| 159 |
break; |
| 160 |
case 'm': |
| 161 |
matches_fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(optargcxx . . $ optarg., "w"); |
| 162 |
if (!matches_fp) { |
| 163 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Could not open matches file '%s'.\n", optargcxx . . $ optarg.); |
| 164 |
return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 165 |
} |
| 166 |
break; |
| 167 |
case 'n': |
| 168 |
min = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 169 |
break; |
| 170 |
case 'M': |
| 171 |
min_keep = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 172 |
break; |
| 173 |
case 'q': |
| 174 |
if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(optargcxx . . $ optarg., "illumina") == 0) |
| 175 |
qual_type = ILLUMINAcxx . . $ ILLUMINA.; |
| 176 |
else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(optargcxx . . $ optarg., "solexa") == 0) |
| 177 |
qual_type = SOLEXAcxx . . $ SOLEXA.; |
| 178 |
else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(optargcxx . . $ optarg., "sanger") == 0) |
| 179 |
qual_type = SANGERcxx . . $ SANGER.; |
| 180 |
else { |
| 181 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown quality type '%s'.\n", optargcxx . . $ optarg.); |
| 182 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 183 |
} |
| 184 |
break; |
| 185 |
case 'p': |
| 186 |
/* This truncation is acceptable... priors need not be doubles */ |
| 187 |
prior = (float) atofcxx . . $ atof(9a18bdb0e56c1bc2).(optargcxx . . $ optarg.); |
| 188 |
if (prior > 1 || prior < 0) { |
| 189 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Prior must be between 0 and 1\n"); |
| 190 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 191 |
} |
| 192 |
break; |
| 193 |
|
| 194 |
case_GETOPT_HELP_CHARcxx . . $ `src/scythe.c:47:9`!; |
| 195 |
case_GETOPT_VERSION_CHARcxx . . $ `src/scythe.c:51:9`!(PROGRAM_NAMEcxx . . $ `src/scythe.c:25:9`!, VERSIONcxx . . $ `<built-in>:410:9`!, AUTHORScxx . . $ `src/scythe.c:29:9`!); |
| 196 |
case '?': |
| 197 |
break; |
| 198 |
default: |
| 199 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
if (debug) { |
| 204 |
matches_fp = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 205 |
output_fp = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 206 |
} |
| 207 |
|
| 208 |
if ((index = optindcxx . . $ optind.) == argc) { |
| 209 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "No FASTQ file specified.\n"); |
| 210 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 211 |
} |
| 212 |
|
| 213 |
/* load all adapter sequences into memory */ |
| 214 |
if (!adapter_fp) { |
| 215 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "No adapter file specified.\n"); |
| 216 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 217 |
} |
| 218 |
aa = load_adapterscxx . . $ load_adapters(fb009b0c85c22345).(adapter_fp); |
| 219 |
gzclosecxx . . $ gzclose(4d4947b8d23ad0c4).(adapter_fp); |
| 220 |
|
| 221 |
fp = strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[index], "-") ? gzopencxx . . $ gzopen(e549dd1a5168a7e3).(argv[index], "r") : gzdopencxx . . $ gzdopen(22355c0c2644e5c0).(filenocxx . . $ fileno(89bc1efcdac0ca22).(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!), "r"); |
| 222 |
|
| 223 |
if (!fp) { |
| 224 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "FASTQ file '%s' not found.\n", argv[index]); |
| 225 |
return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 226 |
} |
| 227 |
|
| 228 |
seq = kseq_initcxx . . $ kseq_init(8b28f0577201a580).(fp); |
| 229 |
|
| 230 |
/* Loop through entire sequence file. Write trimmed sequences to |
| •231 |
file (or stdout), and record matches in a match file if specified. |
| 232 |
*/ |
| 233 |
while ((l = kseq_readcxx . . $ kseq_read(9a11b5e3a16dcc01).(seq)) >= 0) { |
| 234 |
shift = -1; |
| 235 |
if (!seq->qualcxx . . $ $anonymous_type_bd94a7007b005cc0_0#qual..scxx . . $ __kstring_t#s.) { |
| 236 |
fputscxx . . $ fputs(874fa6a5e59ab9bd).("Sequence file missing or has malformed quality line.\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 237 |
usagecxx . . $ usage(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 238 |
} |
| 239 |
|
| 240 |
qprobs = qual_to_probscxx . . $ qual_to_probs(a661829a82ca3f60).(seq->qualcxx . . $ $anonymous_type_bd94a7007b005cc0_0#qual..scxx . . $ __kstring_t#s., qual_type); |
| 241 |
best_match = find_best_matchcxx . . $ find_best_match(745595b130767423).(aa, seq->seqcxx . . $ $anonymous_type_bd94a7007b005cc0_0#seq..scxx . . $ __kstring_t#s., qprobs, prior, 0.25, min); |
| 242 |
|
| 243 |
if (best_match && best_match->pscxx . . $ match#ps.->is_contamcxx . . $ posterior_set#is_contam.) { |
| 244 |
contaminated++; |
| 245 |
shift = best_match->shiftcxx . . $ match#shift.; |
| 246 |
if (matches_fp) print_matchcxx . . $ print_match(a58bc8ea36e4852f).(seq, best_match, matches_fp, aa, qual_type); |
| 247 |
/* TODO */ |
| 248 |
/* aa->adapters[best_match->adapter_index].occurrences[best_match->n-1]++; */ |
| 249 |
} |
| 250 |
write_fastqcxx . . $ write_fastq(c1ff00be624d6f38).(output_fp, seq, add_tag, shift, min_keep); |
| 251 |
if (best_match) destroy_matchcxx . . $ destroy_match(972520b2cfa848f0).(best_match); |
| 252 |
freecxx . . $ free(5d22bdacc48458e8).(qprobs); |
| 253 |
total++; |
| 254 |
} |
| 255 |
|
| 256 |
if (verbose) |
| 257 |
print_summarycxx . . $ print_summary(a6616d7498bbe84d).(aa, prior, total-contaminated, contaminated, total); |
| 258 |
|
| 259 |
kseq_destroycxx . . $ kseq_destroy(bc2dde352bd9ac18).(seq); |
| 260 |
destroy_adapterscxx . . $ destroy_adapters(d23ed8633a24bbab).(aa, MAX_ADAPTERScxx . . $ `src/scythe.h:25:9`!); |
| 261 |
if (output_fp != stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! && output_fp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 262 |
fclosecxx . . $ fclose(89bc1efcdac0ca22).(output_fp); |
| 263 |
gzclosecxx . . $ gzclose(4d4947b8d23ad0c4).(fp); |
| 264 |
return 0; |
| 265 |
} |