forked from cooperative-computing-lab/cctools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsand_compress_reads.c
117 lines (102 loc) · 2.34 KB
/
sand_compress_reads.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Copyright (C) 2009- The University of Notre Dame & University of Cambridge
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include "compressed_sequence.h"
#include "cctools.h"
#include "debug.h"
static void show_help(const char *cmd)
{
printf("Use: %s [options] [infile] [outfile]\n", cmd);
printf("where options are:\n");
printf(" -q Quiet mode: suppress summary line.\n");
printf(" -v Show version string.\n");
printf(" -c Remove Celera read_ids if file came from Celera's gatekeeper\n");
printf(" -i Remove read_ids but leave the Celera internal ids if the file came from Celera's gatekeeper\n");
printf(" -h Show this help screen\n");
}
int main(int argc, char ** argv)
{
const char *progname = "sand_compress_reads";
FILE * infile;
FILE * outfile;
int quiet_mode = 0;
struct seq *s;
struct cseq *c;
signed char d;
int clip = 0;
int internal = 0;
char tmp_id[128];
int count = 0;
while((d=getopt(argc,argv,"cvqhi")) > -1) {
switch(d) {
case 'c':
clip = 1;
break;
case 'i':
internal = 1;
break;
case 'q':
quiet_mode = 1;
break;
case 'v':
cctools_version_print(stdout, progname);
exit(0);
break;
case 'h':
default:
show_help(progname);
exit(0);
break;
}
}
cctools_version_debug(D_DEBUG, argv[0]);
if( optind<argc ) {
infile = fopen(argv[optind], "r");
if(!infile) {
fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
return 1;
}
optind++;
} else {
infile = stdin;
}
if( optind<argc ) {
outfile = fopen(argv[optind],"w");
if(!outfile) {
fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
return 1;
}
optind++;
} else {
outfile = stdout;
}
while((s = seq_read(infile))) {
if(clip != 0 || internal != 0){
strcpy(tmp_id, s->name);
strcpy(s->name, strtok(tmp_id,","));
if(internal != 0){
strcpy(s->name, strtok(NULL,","));
}
}
c = seq_compress(s);
cseq_write(outfile,c);
cseq_free(c);
seq_free(s);
count++;
}
if(!quiet_mode) {
fprintf(stderr,"%d sequences compressed.\n",count);
}
fclose(infile);
fclose(outfile);
return 0;
}
/* vim: set noexpandtab tabstop=4: */