-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreverse_complement_with_mask.c
67 lines (46 loc) · 1.31 KB
/
reverse_complement_with_mask.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<unistd.h>
#include"binary_array.h"
#include"dataset.h"
void file_error(char* path) {
printf("failed to open file %s\n",path);
_exit(1);
}
int main(int argc, char** argv) {
int i;
dataset ds;
FILE* fasta_f;
FILE* mask_f;
int i_buffer;
char* binary_mask;
if(argc < 3) {
printf("Arguments are:\n");
printf(" [file] fasta file to load sequences from\n");
printf(" [file] mask - file containing\n"
" \"1\"s for sequences to be inverted\n"
" \"2\"s for sequences to be conserved\n");
return(1);
}
if ( NULL == (fasta_f = fopen(argv[1], "r"))) file_error(argv[1]);
ds = dataset_from_fasta(fasta_f);
fclose(fasta_f);
if ( NULL == (mask_f = fopen(argv[2], "r"))) file_error(argv[1]);
binary_mask = alloc_and_set_zero_binary_array((size_t)ds.n_values);
for(i = 0; i < ds.n_values; i++) {
if (1 != fscanf(mask_f,"%i",&i_buffer)) {
printf("Mask file currupt!\n");
return(1);
}
if(i_buffer == 1) {
set_value_in_binary_array_at_index(binary_mask,i);
}
}
reverse_complement_sequences(&ds, binary_mask);
dataset_to_fasta(stdout, ds);
free(binary_mask);
free_sequences_from_dataset(ds);
return(0);
}