Skip to content

Instantly share code, notes, and snippets.

@wleepang
Created April 13, 2012 15:40
Show Gist options
  • Save wleepang/2377800 to your computer and use it in GitHub Desktop.
Save wleepang/2377800 to your computer and use it in GitHub Desktop.
CodonOptOutputCompiler:MATLAB
function CodonOptOutputCompiler(xlsFile, outPrefix)
if nargin < 2,
fprintf('USAGE:\n');
fprintf('CodonOptOutputCompiler <input xls> <output prefix>\n');
fprintf('\tinput xls\tMS Excel spreadsheet output from Codon Optimizer\n');
fprintf('\n');
fprintf('\toutput prefix\tPrefix for output files.\n');
fprintf('\t \tOutput is two files:\n');
fprintf('\t \t\t<output prefix>.xls\n');
fprintf('\t \t\t<output prefix>.fasta\n');
return;
end
[status, sheets] = xlsfinfo(xlsFile);
if ~isempty(status),
resNames = sheets(~cellfun(@isempty, regexpi(sheets, '^>')));
% preallocate the results storage array
out = cell(length(resNames), 2);
% get sheets that have output from the optimizer
% they start with '>'
for i = 1:length(resNames),
resName = resNames{i};
% get the sequence name
id = regexpi(resName, '(?<id>[\w\s]+?)-DNA', 'names');
id = id.id;
% get the sequence
[~,seq,~] = xlsread(xlsFile, resName, 'B6');
% write the id and sequence to a compiled list
out(i, :) = {id, seq{1}};
disp(out(i, :));
end
% write the compiled list to an xl spreadsheet
[status, message] = xlswrite([outPrefix '.xls'], out, 'Sheet 1');
if ~status,
disp(message);
end
% write the compiled list to a fasta format text file
fastaData = cell2struct(out, {'Header', 'Sequence'}, 2);
fastawrite([outPrefix, '.fasta'], fastaData);
else
% there was an error
disp(sheets)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment