Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (63 sloc) 1.793 kB
f5acd5b converted fastacomplement to pipeline model
greg authored
1 /*
2 * Convert each sequence in FASTA input to its reverse complement.
3 *
5e034f6 Added GPLv3 license
greg authored
4 *
5 * Copyright (C) 2011, Greg Benison
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
f5acd5b converted fastacomplement to pipeline model
greg authored
21 */
22
23 #include <getopt.h>
24 #include <stdio.h>
25 #include "parameter.h"
26
29209f9 converted fastastack to pipeline model
greg authored
27 const char *my_optstring = "";
f5acd5b converted fastacomplement to pipeline model
greg authored
28 const struct option my_options[] = {{0,0,0,0}};
29
30 /* FIXME doesn't handle lower-case well */
31 static char
32 complement(char c)
33 {
34 if (c == 'G') return 'C';
35 else if (c == 'C') return 'G';
36 else if (c == 'A') return 'T';
37 else if (c == 'T') return 'A';
38 else return c;
39 }
40
41 static void
42 reverse_string(char *str)
43 {
44 char *head = str;
45 while (*head != 0) ++head;
46 --head;
47 while (str < head) {
48 char tmp = *str;
49 *str = *head;
50 *head = tmp;
51 ++str;
52 --head;
53 }
54 }
55
56 void process_option(int code, char *optarg) { /* pass */ }
57 void post_process() { /* pass */ }
58
59 void
60 process_sequence(char *comment, char *sequence)
61 {
62 reverse_string(sequence);
63 printf(">%s", comment);
64
65 char *head = sequence;
66
67 while (*head != 0) {
68 if (((head - sequence) % COLUMN_WIDTH) == 0) putchar('\n');
69 putchar(complement(*head)); ++head;
70 }
71 }
Something went wrong with that request. Please try again.