-
Notifications
You must be signed in to change notification settings - Fork 10
/
sc_readfile.m
40 lines (36 loc) · 1.09 KB
/
sc_readfile.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
function [X, genelist] = sc_readfile(filename, varargin)
if nargin < 1
[filename, pathname] = uigetfile( ...
{'*.csv;*.tsv;*.tab;*.txt', 'Expression Matrix Files (*.csv, *.tsv, *.tab, *.txt)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a Exprssion Matrix file');
if isequal(filename, 0), X = [];
genelist = [];
return;
end
filename = [pathname, filename];
end
if exist(filename, 'file') ~= 2
error('FileNotFound');
end
p = inputParser;
defaultType = 'tsv';
validTypes = {'tsv', 'mtx', 'h5'};
checkType = @(x) any(validatestring(x, validTypes));
% addRequired(p,'X',@isnumeric);
addOptional(p, 'type', defaultType, checkType)
parse(p, varargin{:})
switch p.Results.type
case 'tsv'
[X, genelist] = sc_readtsvfile(filename);
case 'mtx'
featurestxtfile = 'features.tsv';
if exist(featurestxtfile, 'file')
[X, genelist] = sc_readmtxfile(filename, featurestxtfile);
else
error('Need file ''features.tsv''');
end
case 'h5'
[X, genelist] = sc_read10xh5file(filename);
end
end