-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadbed.c
110 lines (85 loc) · 2.66 KB
/
readbed.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
#include "readbed.h"
#include "valorconfig.h"
#define INITIAL_ARRAY_SIZE 25000
vector_t **read_discordant_bed( char *bed_path){
int i;
vector_t **vectors = (vector_t **) getMem(sizeof(vector_t *) *24); //A vector of intervals for each alignment
fprintf(stderr,"Reading BED file %s.\n", bed_path);
FILE *bed_file = safe_fopen( bed_path, "r");
for( i=0; i<24;i++){
vectors[i] = vector_init(sizeof(interval_discordant),INITIAL_ARRAY_SIZE);
}
char chr_buf[24];
int scan_no = 1;
unsigned long barcode = 0;
int start1,start2,end1,end2,chr;
scan_no = fscanf(bed_file,"%s\t%d\t%d\t%d\t%d\t%*c\t%*c",chr_buf,&start1,&end1,&start2,&end2);
while( scan_no != -1){
chr = chr_atoi(chr_buf);
vector_put(
vectors[chr],
&(interval_discordant){start1,end1,start2,end2,barcode}
);
scan_no = fscanf(bed_file,"%s\t%d\t%d\t%d\t%d\t%*c\t%*c",chr_buf,&start1,&end1,&start2,&end2);
}
fclose(bed_file);
return vectors;
// get_library
}
vector_t **read_barcoded_bed( char* bed_path){
int i;
vector_t **vectors = (vector_t **) getMem(sizeof(vector_t *) *24); //A vector of intervals for each alignment
fprintf(stderr,"Reading BED file %s.\n", bed_path);
FILE *bed_file = safe_fopen( bed_path, "r");
for( i=0; i<24;i++){
vectors[i] = vector_init(sizeof(interval_10X),INITIAL_ARRAY_SIZE);
}
char chr_buf[24];
int scan_no = 1;
unsigned long barcode;
int start,end,chr;
scan_no = fscanf(bed_file,"%s\t%d\t%d\t%lu",chr_buf,&start,&end,&barcode);
while( scan_no != -1){
chr = chr_atoi(chr_buf);
vector_put(
vectors[chr],
&(interval_10X){start,end,barcode}
);
scan_no = fscanf(bed_file,"%s\t%d\t%d\t%lu",chr_buf,&start,&end,&barcode);
}
fclose(bed_file);
return vectors;
// get_library_count( in_bam, bam_header->text);
}
vector_t **read_pcs_bed( char* bed_path, int pool_no){
int i;
vector_t **vectors = (vector_t **) getMem(sizeof(vector_t *) *24); //A vector of intervals for each alignment
fprintf(stderr,"Reading BED file %s.\n", bed_path);
FILE *bed_file = safe_fopen( bed_path, "r");
for( i=0; i<24;i++){
vectors[i] = vector_init(sizeof(interval_10X),INITIAL_ARRAY_SIZE);
}
char chr_buf[24];
int scan_no = 1;
int start,end,chr;
scan_no = fscanf(bed_file,"%s\t%d\t%d",chr_buf,&start,&end);
while( scan_no != -1){
chr = chr_atoi(chr_buf);
unsigned long barcode = pool_no;
vector_put(
vectors[chr],
&(interval_10X){start,end,barcode}
);
scan_no = fscanf(bed_file,"%s\t%d\t%d",chr_buf,&start,&end);
}
fclose(bed_file);
return vectors;
// get_library_count( in_bam, bam_header->text);
}
void destroy_beds(vector_t **reads){
int i;
for( i = 0; i < 24; i++){
vector_free(reads[i]);
}
freeMem(reads,sizeof(vector_t **));
}