forked from dzerbino/velvet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.c
318 lines (288 loc) · 9.85 KB
/
run.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
Copyright 2007, 2008 Daniel Zerbino ([email protected])
This file is part of Velvet.
Velvet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Velvet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Velvet; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#include <uce-dirent.h>
#define Arc v_Arc
#else
#include <dirent.h>
#endif
#include "run.h"
static void printUsage()
{
puts("Usage:");
puts("./velveth directory hash_length {[-file_format][-read_type][-separate|-interleaved] filename1 [filename2 ...]} {...} [options]");
puts("");
puts("\tdirectory\t: directory name for output files");
printf("\thash_length\t: EITHER an odd integer (if even, it will be decremented) <= %i (if above, will be reduced)\n", MAXKMERLENGTH);
printf("\t\t\t: OR: m,M,s where m and M are odd integers (if not, they will be decremented) with m < M <= %i (if above, will be reduced)\n", MAXKMERLENGTH);
puts("\t\t\t\tand s is a step (even number). Velvet will then hash from k=m to k=M with a step of s");
puts("\tfilename\t: path to sequence file or - for standard input");
puts("");
puts("File format options:");
puts("\t-fasta\t-fastq\t-raw\t-fasta.gz\t-fastq.gz\t-raw.gz\t-sam\t-bam\t-fmtAuto");
puts("\t(Note: -fmtAuto will detect fasta or fastq, and will try the following programs for decompression : gunzip, pbunzip2, bunzip2");
puts("");
puts("File layout options for paired reads (only for fasta and fastq formats):");
puts("\t-interleaved\t: File contains paired reads interleaved in the one file (default)");
puts("\t-separate\t: Read 2 separate files for paired reads");
puts("");
puts("Read type options:");
puts("\t-short\t-shortPaired");
#if CATEGORIES <= 5
Category cat;
for (cat = 2; cat <= CATEGORIES; cat++)
printf("\t-short%i\t-shortPaired%i\n", cat, cat);
#else
puts("\t...");
printf("\t-short%i\t-shortPaired%i\n", CATEGORIES - 1, CATEGORIES - 1);
printf("\t-short%i\t-shortPaired%i\n", CATEGORIES, CATEGORIES);
#endif
puts("\t-long\t-longPaired");
puts("\t-reference");
puts("");
puts("Options:");
puts("\t-strand_specific\t: for strand specific transcriptome sequencing data (default: off)");
puts("\t-reuse_Sequences\t: reuse Sequences file (or link) already in directory (no need to provide original filenames in this case (default: off)");
puts("\t-reuse_binary\t: reuse binary sequences file (or link) already in directory (no need to provide original filenames in this case (default: off)");
puts("\t-noHash\t\t\t: simply prepare Sequences file, do not hash reads or prepare Roadmaps file (default: off)");
puts("\t-create_binary \t: create binary CnyUnifiedSeq file (default: off)");
puts("");
puts("Synopsis:");
puts("");
puts("- Short single end reads:");
puts("\tvelveth Assem 29 -short -fastq s_1_sequence.txt");
puts("");
puts("- Paired-end short reads (remember to interleave paired reads):");
puts("\tvelveth Assem 31 -shortPaired -fasta interleaved.fna");
puts("");
puts("- Paired-end short reads (using separate files for the paired reads)");
puts("\tvelveth Assem 31 -shortPaired -fasta -separate left.fa right.fa");
puts("");
puts("- Two channels and some long reads:");
puts("\tvelveth Assem 43 -short -fastq unmapped.fna -longPaired -fasta SangerReads.fasta");
puts("");
puts("- Three channels:");
puts("\tvelveth Assem 35 -shortPaired -fasta pe_lib1.fasta -shortPaired2 pe_lib2.fasta -short3 se_lib1.fa");
puts("");
puts("Output:");
puts("\tdirectory/Roadmaps");
puts("\tdirectory/Sequences");
puts("\t\t[Both files are picked up by graph, so please leave them there]");
}
int main(int argc, char **argv)
{
ReadSet *allSequences = NULL;
SplayTable *splayTable;
int hashLength, hashLengthStep, hashLengthMax, h;
char *directory, *filename, *seqFilename, *baseSeqName, *buf;
char * token;
boolean double_strand = true;
boolean noHash = false;
boolean multiple_kmers = false;
char buffer[100];
DIR *dir;
setProgramName("velveth");
if (argc < 4) {
printf("velveth - simple hashing program\n");
printf("Version %i.%i.%2.2i\n", VERSION_NUMBER,
RELEASE_NUMBER, UPDATE_NUMBER);
printf("\nCopyright 2007, 2008 Daniel Zerbino ([email protected])\n");
printf("This is free software; see the source for copying conditions. There is NO\n");
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
printf("Compilation settings:\n");
printf("CATEGORIES = %i\n", CATEGORIES);
printf("MAXKMERLENGTH = %i\n", MAXKMERLENGTH);
#ifdef _OPENMP
puts("OPENMP");
#endif
#ifdef LONGSEQUENCES
puts("LONGSEQUENCES");
#endif
#ifdef BIGASSEMBLY
puts("BIGASSEMBLY");
#endif
#ifdef COLOR
puts("COLOR");
#endif
#ifdef DEBUG
puts("DEBUG");
#endif
printf("\n");
printUsage();
return 0;
}
strcpy(buffer, argv[2]);
token = strtok(buffer, ",");
hashLength = atoi(token);
token = strtok(NULL, ",");
if (token == NULL) {
multiple_kmers = false;
hashLengthMax = hashLength + 1;
} else {
multiple_kmers = true;
hashLengthMax = atoi(token);
}
token = strtok(NULL, ",");
if (token == NULL) {
hashLengthStep = 2;
} else {
hashLengthStep = atoi(token);
}
if (hashLength > MAXKMERLENGTH) {
velvetLog
("Velvet can't handle k-mers as long as %i! We'll stick to %i if you don't mind.\n",
hashLength, MAXKMERLENGTH);
hashLength = MAXKMERLENGTH;
}
if (hashLength <= 0) {
velvetLog("Invalid hash length: %s\n", argv[2]);
printUsage();
return 0;
}
if (hashLength % 2 == 0) {
velvetLog
("Velvet can't work with even length k-mers, such as %i. We'll use %i instead, if you don't mind.\n",
hashLength, hashLength - 1);
hashLength--;
}
if (multiple_kmers) {
if (hashLengthMax > MAXKMERLENGTH + 1) {
velvetLog
("Velvet can't handle k-mers as long as %i! We'll stick to %i if you don't mind.\n",
hashLengthMax, MAXKMERLENGTH + 1);
hashLengthMax = MAXKMERLENGTH + 1;
}
if (hashLengthMax <= hashLength) {
velvetLog("hashLengthMin < hashLengthMax is required %s", argv[2]);
printUsage();
return 0;
}
if (hashLengthStep <= 0) {
velvetLog("Non-positive hash length! Setting it to 2\n");
hashLengthStep = 2;
}
if (hashLengthStep % 2 == 1) {
velvetLog
("Velvet can't work with an odd length k-mer step, such as %i. We'll use %i instead, if you don't mind.\n",
hashLengthStep, hashLengthStep + 1);
hashLengthStep++;
}
}
// check if binary sequences should be used
int argIndex;
for (argIndex = 3; argIndex < argc; argIndex++)
if (strcmp(argv[argIndex], "-create_binary") == 0 || strcmp(argv[argIndex], "-reuse_binary") == 0)
setCreateBinary(true);
for (h = hashLength; h < hashLengthMax; h += hashLengthStep) {
resetWordFilter(h);
buf = mallocOrExit(2 * strlen(argv[1]) + 500, char);
if ( multiple_kmers ) {
sprintf(buf,"%s_%d",argv[1],h);
directory = mallocOrExit(strlen(buf) + 100, char);
strcpy(directory,buf);
} else
directory = argv[1];
filename = mallocOrExit(strlen(directory) + 100, char);
seqFilename = mallocOrExit(strlen(directory) + 100, char);
baseSeqName = mallocOrExit(100, char);
dir = opendir(directory);
if (dir == NULL)
mkdir(directory, 0777);
else {
sprintf(buf, "%s/PreGraph", directory);
remove(buf);
sprintf(buf, "%s/Graph", directory);
remove(buf);
sprintf(buf, "%s/Graph2", directory);
remove(buf);
sprintf(buf, "%s/Graph3", directory);
remove(buf);
sprintf(buf, "%s/Graph4", directory);
remove(buf);
}
logInstructions(argc, argv, directory);
strcpy(seqFilename, directory);
if (isCreateBinary()) {
// use the CNY unified seq writer
strcpy(baseSeqName, "/CnyUnifiedSeq");
// remove other style sequences file
sprintf(buf, "%s/Sequences", directory);
remove(buf);
} else {
strcpy(baseSeqName, "/Sequences");
// remove other style sequences file
sprintf(buf, "%s/CnyUnifiedSeq", directory);
remove(buf);
sprintf(buf, "%s/CnyUnifiedSeq.names", directory);
remove(buf);
}
strcat(seqFilename, baseSeqName);
if ( h == hashLength ) {
parseDataAndReadFiles(seqFilename, argc - 2, &(argv[2]), &double_strand, &noHash);
} else {
sprintf(buf,"rm -f %s",seqFilename);
if (system(buf)) {
velvetLog("Command failed!\n");
velvetLog("%s\n", buf);
#ifdef DEBUG
abort();
#endif
exit(1);
}
if (argv[1][0] == '/')
sprintf(buf,"ln -s %s_%d%s %s",argv[1],hashLength,baseSeqName,seqFilename);
else
sprintf(buf,"ln -s `pwd`/%s_%d%s %s",argv[1],hashLength,baseSeqName,seqFilename);
if (system(buf)) {
velvetLog("Command failed!\n");
velvetLog("%s\n", buf);
#ifdef DEBUG
abort();
#endif
exit(1);
}
}
if (noHash)
continue;
splayTable = newSplayTable(h, double_strand);
if (isCreateBinary()) {
allSequences = importCnyReadSet(seqFilename);
} else {
allSequences = importReadSet(seqFilename);
}
velvetLog("%li sequences in total.\n", (long) allSequences->readCount);
strcpy(filename, directory);
strcat(filename, "/Roadmaps");
inputSequenceArrayIntoSplayTableAndArchive(allSequences,
splayTable, filename, seqFilename);
destroySplayTable(splayTable);
if (dir)
closedir(dir);
if (directory != argv[1])
free(directory);
free(filename);
free(seqFilename);
free(baseSeqName);
free(buf);
if (allSequences) {
destroyReadSet(allSequences);
}
}
return 0;
}