-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGetChr.cpp
94 lines (77 loc) · 1.94 KB
/
GetChr.cpp
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
int GetChr(char * argv[])
{
clock_t start = clock();
SPAM(("=================\ngetseq.c start!\n"));
char FileName[400];//name of processed Wig file
long unsigned int Location=0;
char tmp;
char str[1000]; //annotation line
char str2[40];
double Value=0;
long unsigned int IntValue=0;
long unsigned int C1=0;
long unsigned int C2=0;
int i;
strcpy(FileName, argv[1]);
FILE *fp;
fp = fopen(FileName, "r");
if (fp == NULL) {
fprintf(stderr, "Can't open input file %s!\n",FileName);
exit(1);
}
strcpy(FileName, argv[2]);
FILE *fpWrite;
fpWrite = fopen(FileName, "w");
if (fpWrite == NULL) {
fprintf(stderr, "Can't open input file %s!\n",FileName);
exit(1);
}
int flag=0;
while (!feof(fp) &&flag==0){
tmp = fgetc(fp);
if (tmp >= '0' && tmp <= '9'){
ungetc(tmp,fp);
fscanf(fp,"%lu %lf\n", &Location,&Value);
//fprintf(fpWrite, "%lu %.2f\n", Location,Value);
}
else{
ungetc(tmp,fp);
fgets(str,sizeof(str),fp);
strcpy(str2,"variableStep chrom=chr2 span=25 \0");
for(i=0;i<23;++i){
if(str[i]!=str2[i]){
printf("%d, Length string wig=%d, Length string2=%d \n", i, strlen(str),strlen(str2));
flag=0;
break;}
}
if(i==23){
puts(str2);
flag=1;}
}
}
int flag2=0;
int ite=0;
while (!feof(fp) &&flag2==0 && ite<100){
tmp = fgetc(fp);
if (tmp >= '0' && tmp <= '9'){
ungetc(tmp,fp);
fscanf(fp,"%lu %lf\n", &Location,&Value);
fprintf(fpWrite, "%lu %.2f\n", Location,Value);
}
else{
ungetc(tmp,fp);
++ite;
fgets(str,sizeof(str),fp);
for(i=0;i<23;++i){
if(str[i]!=str2[i]){
printf("%d, Length string wig=%d, Length string2=%d \n", i, strlen(str),strlen(str2));
flag2=1;
break;
}
}
}
}
fclose(fp);
fclose(fpWrite);
return 1;
}