forked from jamesjcai/scGEAToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc_ifft.m
33 lines (26 loc) · 831 Bytes
/
sc_ifft.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
function [Y] = sc_ifft(X)
% https://github.com/Sanofi-Public/PMCB-scGFT/blob/master/R/Core.R
X = pkg.norm_libsize(X, 1e4);
X = log1p(X);
ft_mtx = fft(X, [], 2);
[M, N] = size(ft_mtx);
% ft_mtx stores FFT freq. components in rows
% M = number of genes (also components)
a = abs(ft_mtx);
a = a./vecnorm(a, 2, 2);
sigma = var(a, 1, 2);
sigma(1) = 1;
k = randi([2, M], N, 1);
A = normrnd(2, sqrt(sigma(k)));
for cn = 1:N
ft_mtx(k(cn), cn) = A(cn)*ft_mtx(k(cn), cn);
if k(cn) ~= 1 && mod(M, 2)==0 && k(cn) ~= M/2 + 1
ft_mtx(M - k(cn), cn) = A(cn)*ft_mtx(M - k(cn), cn);
end
end
Y = ifft(ft_mtx, [], 2);
Y = real(Y./M);
Y(Y<0) = 0;
% Relative Percent Difference (RPD)
% devs = mean(abs(Y - X));
end