-
Notifications
You must be signed in to change notification settings - Fork 10
/
sc_filterg.m
26 lines (25 loc) · 916 Bytes
/
sc_filterg.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
function [X, genelist] = sc_filterg(X, genelist, cutoff, verbose)
if nargin < 2, genelist = []; end
if nargin < 3, cutoff = 1; end
if nargin < 4, verbose = false; end
if cutoff < 1.0 % e.g., 0.9
if verbose
fprintf('Discard genes with poor expression values (more than %d%% zeros in all cells).\n', ...
100*cutoff);
end
r = sum(X ~= 0, 2) ./ size(X, 2);
i = r >= cutoff;
else
[u] = sum(X, 2);
i = u >= cutoff;
if verbose
fprintf('Discard genes with poor expression values (with less than %d reads among all cells).\n', ...
cutoff);
end
end
% We discard cells with poor gene expression values (more than 90% zeros in all cells)
% As the default, we filter all the genes with less than 5 reads among 99% of the samples
X = X(i, :);
if ~isempty(genelist), genelist = genelist(i, :); end
if verbose, fprintf('%d genes removed.\n', sum(~i)); end
end