-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_average_hic_profile_1d.m
62 lines (51 loc) · 1.69 KB
/
calculate_average_hic_profile_1d.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
60
61
function avg_contact = calculate_average_hic_profile_1d(ds,varargin)
%Average together multiple hi-c profiles into an aggregate profile
params = {'cell_lines',...
'wts'};
dflts = {'',...
struct([])};
arg = parse_args(params,dflts,varargin{:});
%Subset ds to cell lines of interest
if ~isempty(arg.cell_lines)
idx = ismember({ds.cell_line},arg.cell_lines);
ds_all = ds;
ds = ds(idx);
end
%weights vector
if isempty(arg.wts)
temp_wts = 1 / length(ds);
wts = struct('cell_line',{ds.cell_line},...
'wt',temp_wts);
else
wts = arg.wts;
idx = ismember({wts.cell_line},arg.cell_lines);
wts = wts(idx);
end
%Get support of avg_profile as union of all provided supports
%Need to use ds_all here. Need to include the target cell line in the union
%computation
avg_support = [];
for ii = 1:length(ds_all)
avg_support = union(avg_support,ds_all(ii).genome_coordinates);
end
%Map all provided profiles to bigger support
%Use linear interpolation
for ii = 1:length(ds)
ds(ii).hic_contacts_interp = interp1(ds(ii).genome_coordinates,...
ds(ii).hic_contacts,...
avg_support,...
'linear',...
'extrap');
end
%Put cell lines in same order
assert(isequal(sort({wts.cell_line}),sort({ds.cell_line})),'Cell line sets not the same!');
[~,loc] = ismember({ds.cell_line},{wts.cell_line});
wts = wts(loc);
assert(isequal({wts.cell_line},{ds.cell_line}),'Cell Lines not in same order!');
%compute average
assert(isequal({wts.cell_line},{ds.cell_line}),'Cell Lines not in same order!');
avg_profile = ([wts.wt] * ([ds.hic_contacts_interp])')';
avg_contact = struct('hic_contacts',avg_profile,...
'genome_coordinates',avg_support',...
'wts',wts);
end