-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFastrm.c
167 lines (147 loc) · 4.59 KB
/
Fastrm.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
/********************************************************************************************
*
* FastK: a rapid disk-based k-mer counter for high-fidelity shotgun data sets.
* Uses a novel minimizer-based distribution scheme that permits problems of
* arbitrary size, and a two-staged "super-mer then weighted k-mer" sort to acheive
* greater speed when error rates are low (1% or less). Directly produces sequence
* profiles.
*
* Author: Gene Myers
* Date : October, 2020
*
*********************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <math.h>
#include "gene_core.h"
static char *Usage = "[-if] <source> ...";
int main(int argc, char **argv)
{ int QUERY;
int QUIET;
{ int i, j, k;
int flags[128];
ARG_INIT("Fastrm")
j = 1;
for (i = 1; i < argc; i++)
if (argv[i][0] == '-')
switch (argv[i][1])
{ default:
ARG_FLAGS("if")
break;
}
else
argv[j++] = argv[i];
argc = j;
QUERY = flags['i'];
QUIET = flags['f'];
if (QUIET)
QUERY = 0;
if (argc < 2)
{ fprintf(stderr,"\nUsage: %s %s\n",Prog_Name,Usage);
fprintf(stderr,"\n");
fprintf(stderr," -i: prompt for each (stub) deletion\n");
fprintf(stderr," -f: force operation quietly\n");
exit (1);
}
}
{ int c, len, yes, any, a;
int alen, rlen;
int doh, dot, dop;
char *dir, *root, *fname;
char *command;
struct stat B;
len = 0;
for (c = 1; c < argc; c++)
if ((int) strlen(argv[c]) > len)
len = strlen(argv[c]);
command = Malloc(3*len+50,"Allocating command buffer");
for (c = 1; c < argc; c++)
{ dir = PathTo(argv[c]);
fname = rindex(argv[c],'/');
if (fname == NULL)
fname = argv[c];
else
fname += 1;
root = Root(fname,NULL);
alen = strlen(fname);
rlen = strlen(root);
if (alen == rlen)
doh = dot = dop = 1;
else
{ doh = (strcmp(fname + rlen,".hist") == 0);
dot = (strcmp(fname + rlen,".ktab") == 0);
dop = (strcmp(fname + rlen,".prof") == 0);
if (doh + dot + dop == 0)
{ free(root);
root = Strdup(fname,NULL);
doh = dot = dop = 1;
}
}
any = 0;
if (doh && stat(Catenate(dir,"/",root,".hist"),&B) == 0)
{ yes = 1;
any = 1;
if (QUERY)
{ printf("remove %s/%s.hist? ",dir,root);
yes = 0;
while ((a = getc(stdin)) != '\n')
if (a == 'y' || a == 'Y')
yes = 1;
else if (a == 'n' || a == 'N')
yes = 0;
}
if (yes)
unlink(Catenate(dir,"/",root,".hist"));
}
if (dot && stat(Catenate(dir,"/",root,".ktab"),&B) == 0)
{ yes = 1;
any = 1;
if (QUERY)
{ printf("remove %s/%s.ktab & hidden parts? ",dir,root);
yes = 0;
while ((a = getc(stdin)) != '\n')
if (a == 'y' || a == 'Y')
yes = 1;
else if (a == 'n' || a == 'N')
yes = 0;
}
if (yes)
{ sprintf(command,"rm -f %s/%s.ktab %s/.%s.ktab.*",dir,root,dir,root);
system(command);
}
}
if (dop && stat(Catenate(dir,"/",root,".prof"),&B) == 0)
{ yes = 1;
any = 1;
if (QUERY)
{ printf("remove %s/%s.prof & hidden parts? ",dir,root);
yes = 0;
while ((a = getc(stdin)) != '\n')
if (a == 'y' || a == 'Y')
yes = 1;
else if (a == 'n' || a == 'N')
yes = 0;
}
if (yes)
{ sprintf(command,"rm -f %s/%s.prof %s/.%s.pidx.* %s/.%s.prof.*",
dir,root,dir,root,dir,root);
system(command);
}
}
if (any == 0 && !QUIET)
{ if (doh+dot+dop == 3)
fprintf(stderr,"%s: no FastK output files with root %s\n",Prog_Name,root);
else
fprintf(stderr,"%s: %s does not exist\n",Prog_Name,argv[1]);
}
free(root);
free(dir);
}
free(command);
}
exit (0);
}