forked from evodevosys/AroSpotFindingSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_chromosome_count_to_data_file.m
60 lines (54 loc) · 1.33 KB
/
add_chromosome_count_to_data_file.m
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
function [] = add_chromosome_count_to_data_file(filename)
% this assumes that the chromosome counts file exists already and that the
% specified file exists
run('Aro_parameters.m');
fid = fopen(ChromosomeFile,'r');
i = 1;
tline = fgetl(fid);
if tline ~= -1
chromosome_counts{i} = strsplit(string(tline), ',');
chromosome_counts{i} = chromosome_counts{i}{2};
end
while ischar(tline)
i = i+1;
tline = fgetl(fid);
if tline ~= -1
count = strsplit(string(tline), ',');
count = count{2};
chromosome_counts{i} = count;
else
chromosome_counts{i} = -1;
end
end
fclose(fid);
disp(chromosome_counts);
fid = fopen(filename,'r');
i = 2;
tline = fgetl(fid);
file{1} = 'id, spot count,spot lower estimate,spot upper estimate,chromosome count';
file{i} = tline;
if tline ~= -1
padded = [string(tline) ',' chromosome_counts{i-1}];
file{i} = padded;
end
while ischar(tline)
i = i+1;
tline = fgetl(fid);
if tline ~= -1
padded = [string(tline) ',' chromosome_counts{i-1}];
file{i} = padded;
else
file{i} = -1;
end
end
fclose(fid);
% Write cell array file into specified csv file
fid = fopen(filename, 'w');
for i = 1:numel(file)
if file{i+1} == -1
fprintf(fid,'%s', file{i});
break
else
fprintf(fid,'%s\n', file{i});
end
end