Created
March 27, 2023 02:47
-
-
Save davidaknowles/15d683399e4393039436552ec5e5c293 to your computer and use it in GitHub Desktop.
Convert SPLIT-seq Matlab sparse matrices to something useable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mmwrite(filename,A) | |
mmfile = fopen(filename,'w'); | |
[M,N] = size(A); | |
[I,J,V] = find(A); | |
NZ = length(V); | |
fprintf(mmfile,'%%%%MatrixMarket matrix coordinate real general\n'); | |
fprintf(mmfile,'%% Generated %s\n',[date]); | |
fprintf(mmfile,'%d %d %d\n',M,N,NZ); | |
for i=1:NZ | |
fprintf(mmfile,'%d %d %.4g\n',I(i),J(i),V(i)); | |
end | |
fclose(mmfile); | |
end | |
mats = dir("*.mat"); | |
for i=1:length(mats) | |
fn = mats(i).name; | |
a = load(fn); | |
[~, basename, ~] = fileparts(fn); | |
mkdir(basename); | |
writematrix(a.barcodes,fullfile(basename,'barcodes.txt'),'Delimiter','\t') | |
writematrix(a.genes,fullfile(basename,'genes.txt'),'Delimiter','\t') | |
writematrix(a.sample_type,fullfile(basename,'sample_type.txt'),'Delimiter','\t') | |
mmwrite(fullfile(basename,'DGE.mtx'), a.DGE); | |
%[i,j,v]=find(a.DGE); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment