Squashed initial commit
This commit is contained in:
325
qhtcp-workflow/apps/matlab/easy/DMPexcel2mat.m
Executable file
325
qhtcp-workflow/apps/matlab/easy/DMPexcel2mat.m
Executable file
@@ -0,0 +1,325 @@
|
||||
%% CALLED BY EASYconsole.m %%
|
||||
|
||||
global mpdmFile
|
||||
global masterPlateFile
|
||||
global drugMediaFile
|
||||
global matDir
|
||||
|
||||
% If we already have mpdmFile, don't recreate
|
||||
if (exist(mpdmFile, 'file') && ~isempty(mpdmFile))
|
||||
fprintf('The Drug Media/MasterPlate Annotation File: %s exists, skipping DMPexcel2mat.m\n', mpdmFile);
|
||||
return
|
||||
end
|
||||
|
||||
% Do our best to find and load a relevant MasterPlate file
|
||||
if ~exist(masterPlateFile, 'file') || isempty(masterPlateFile)
|
||||
if exist(fullfile(matDir), 'dir')
|
||||
% Try to find the masterPlateFile automatically (newest created first)
|
||||
try
|
||||
files=dir(matDir);
|
||||
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
|
||||
if isempty(mpFiles)
|
||||
throw(MException('MATLAB:dir', 'No MasterPlate_ files in the default MasterPlate directory'));
|
||||
end
|
||||
% this sorts by date (newest first)
|
||||
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
|
||||
sortedFiles=mpFiles(sortedIndices);
|
||||
masterPlateFile=sortedFiles{1};
|
||||
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
|
||||
catch ME
|
||||
% This can be silent, not really an error
|
||||
end
|
||||
|
||||
|
||||
try
|
||||
% For standalone mode
|
||||
% GUI input for selecting a MasterPlate Excel file
|
||||
questdlg('Select MasterPlate Directory (containing DrugMedia_ & MasterPlate_ files)','Directory Selection','OK',...
|
||||
struct('Default','OK','Interpreter','tex'))
|
||||
dirToScan=uigetdir();
|
||||
files=dir(dirToScan);
|
||||
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
|
||||
if isempty(mpFiles)
|
||||
throw(MException('MATLAB:dir', 'No MasterPlate_ files in directory'))
|
||||
end
|
||||
% this sorts by date (newest first)
|
||||
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
|
||||
sortedFiles=mpFiles{sortedIndices};
|
||||
masterPlateFile=sortedFiles{1};
|
||||
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
|
||||
break
|
||||
catch ME
|
||||
h=msgbox(ME.message, 'Error', 'error');
|
||||
disp('Rerunning directory selection');
|
||||
% I don't know what else we'll need to do here
|
||||
end
|
||||
else
|
||||
try
|
||||
% For standalone mode
|
||||
% GUI input for selecting a MasterPlate Excel file
|
||||
questdlg('Select MasterPlate Directory (containing DrugMedia_ & MasterPlate_ files)','Directory Selection','OK',...
|
||||
struct('Default','OK','Interpreter','tex'))
|
||||
dirToScan=uigetdir();
|
||||
files=dir(dirToScan);
|
||||
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
|
||||
if isempty(mpFiles)
|
||||
throw (MException('MATLAB:dir', 'No MasterPlate_ files in directory'));
|
||||
end
|
||||
% this sorts by date (newest first)
|
||||
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
|
||||
sortedFiles=mpFiles{sortedIndices};
|
||||
masterPlateFile=sortedFiles{1};
|
||||
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
|
||||
break
|
||||
catch ME
|
||||
h=msgbox(ME.message, 'Error', 'error');
|
||||
uiwait(h);
|
||||
disp('Rerunning directory selection');
|
||||
% I don't know what else we'll need to do here
|
||||
end
|
||||
end
|
||||
else
|
||||
fprintf('Using MasterPlate file: %s skipping directory selection\n', masterPlateFile);
|
||||
end
|
||||
|
||||
% fid=fopen(masterPlateFile)%('exp23PrintTimes.xls'); % textread puts date and time sequentially into vector
|
||||
% TODO needs explanation, it isn't clear what it is for
|
||||
% The input files should be csv, not xlsx
|
||||
% This whole file could be much better and more portable
|
||||
if ispc
|
||||
[num, txt, raw]=xlsread(masterPlateFile); %,'Yor1HitsMPsetFinal');
|
||||
fields={txt(2,1:15)}; %or 1:17 for later but dont wish to exceed and cause error ? if used
|
||||
else
|
||||
clear MPtbl
|
||||
opts=detectImportOptions(masterPlateFile);
|
||||
MPtbl=readtable(masterPlateFile,opts);
|
||||
MPtbl=readtable(masterPlateFile);
|
||||
fields={opts.VariableNames}; %? if used anywhere although 'saved' to MPDMmat
|
||||
MPcell=readcell(masterPlateFile);
|
||||
end
|
||||
|
||||
numb=0;
|
||||
clear MP;
|
||||
try
|
||||
if ispc
|
||||
excLnNum=3;
|
||||
while (isequal(txt{excLnNum,1},'###'))
|
||||
numb=numb+1;
|
||||
MP(numb).head={raw(excLnNum,2:6)};
|
||||
MP(numb).recNum={raw((excLnNum+1):(excLnNum+384),1)};
|
||||
MP(numb).orf={raw((excLnNum+1):(excLnNum+384),2)};
|
||||
MP(numb).strain={raw((excLnNum+1):(excLnNum+384),3)};
|
||||
MP(numb).genename={raw((excLnNum+1):(excLnNum+384),12)};
|
||||
MP(numb).drug={raw((excLnNum+1):(excLnNum+384),8)};
|
||||
MP(numb).media={raw((excLnNum+1):(excLnNum+384),7)};
|
||||
if size(raw,2)>15
|
||||
MP(numb).orfRep={raw((excLnNum+1):(excLnNum+384),16)}; % added 12_1005 to specify replicates Orfs in MP
|
||||
MP(numb).specifics={raw((excLnNum+1):(excLnNum+384),17)}; % added 12_1008 to specify replicates Specific details in MP
|
||||
else
|
||||
MP(numb).orfRep=' ';
|
||||
MP(numb).specifics= ' ';
|
||||
end
|
||||
% Future MP field
|
||||
% if size(raw,2)>17
|
||||
% MP(numb).specifics2= {raw((excLnNum+1):(excLnNum+384),18)}; % added 12_1008 to specify strain Bkground in MP
|
||||
% else
|
||||
% MP(numb).specifics2=' ';
|
||||
% end
|
||||
excLnNum=excLnNum+385;
|
||||
msg=strcat('NumberOfMP=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
|
||||
end
|
||||
else
|
||||
excLnNum=1;
|
||||
while (isequal(MPcell{(excLnNum+2),1},'###'))
|
||||
numb=numb+1;
|
||||
MP(numb).head={MPtbl(excLnNum,2:6)};
|
||||
MP(numb).head{1}=table2cell(MP(numb).head{1});
|
||||
MP(numb).recNum={MPtbl((excLnNum+1):(excLnNum+384),1)};
|
||||
MP(numb).recNum{1}=table2cell(MP(numb).recNum{1});
|
||||
MP(numb).orf={MPtbl((excLnNum+1):(excLnNum+384),2)};
|
||||
MP(numb).orf{1}=table2cell(MP(numb).orf{1});
|
||||
MP(numb).strain={MPtbl((excLnNum+1):(excLnNum+384),3)};
|
||||
MP(numb).strain{1}=table2cell(MP(numb).strain{1});
|
||||
MP(numb).genename={MPtbl((excLnNum+1):(excLnNum+384),12)};
|
||||
MP(numb).genename{1}= table2cell(MP(numb).genename{1});
|
||||
MP(numb).media= {MPtbl((excLnNum+1):(excLnNum+384),7)};
|
||||
MP(numb).media{1}= table2cell(MP(numb).media{1});
|
||||
if size(MPtbl,2)>15
|
||||
MP(numb).orfRep= {MPtbl((excLnNum+1):(excLnNum+384),16)}; % added 12_1005 to specify replicates Orfs in MP
|
||||
MP(numb).orfRep{1}=table2cell(MP(numb).orfRep{1});
|
||||
MP(numb).specifics={MPtbl((excLnNum+1):(excLnNum+384),17)}; % added 12_1008 to specify replicates Specific details in MP
|
||||
MP(numb).specifics{1}=table2cell(MP(numb).specifics{1});
|
||||
else
|
||||
MP(numb).orfRep= ' ';
|
||||
MP(numb).specifics= ' ';
|
||||
end
|
||||
excLnNum=excLnNum+385;
|
||||
msg=strcat('NumberOfMP=',num2str(numb), 'lastLineNo.=',num2str(excLnNum));
|
||||
end
|
||||
end
|
||||
catch ME
|
||||
h=msgbox(ME.message, 'Error', 'error');
|
||||
uiwait(h);
|
||||
end
|
||||
|
||||
%DMupload
|
||||
%Drug and Media Plate setup Upload from Excel
|
||||
excLnNum=1;
|
||||
numOfDrugs=0;
|
||||
numOfMedias=0;
|
||||
|
||||
% Grabbing the bare filename from the MasterPlate file to see if we can automatically
|
||||
% find a matching DrugMedia file
|
||||
[mpFile, mpPath]=fullfile(masterPlateFile);
|
||||
mpFileParts=strsplit(mpFile, '_');
|
||||
mpBareFileName=strjoin(mpFileParts(2:end-1), '_');
|
||||
|
||||
if ~exist(drugMediaFile, 'file') || isempty(drugMediaFile)
|
||||
if exist(fullfile(matDir), 'dir')
|
||||
try
|
||||
dmFileToTest=fullfile(mpPath, 'DrugMedia_', mpBareFileName, '.xlsx');
|
||||
if exist(dmFileToTest, 'file') % Try to find a matching drug media file
|
||||
drugMediaFile=dmFileToTest;
|
||||
fprintf('Using matching DrugMedia file: %s, skipping directory selection\n', drugMediaFile);
|
||||
else
|
||||
% Try to find the DrugMedia file automatically (newest created first)
|
||||
files=dir(matDir);
|
||||
dmFiles={files(strncmp(files.name, 'DrugMedia_', 10)).name};
|
||||
if isempty(dmFiles)
|
||||
throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'));
|
||||
end
|
||||
% this sorts by date (newest first)
|
||||
[~, sortedIndices]=sort(datenum({files(strncmp(dmFiles.name, 'DrugMedia_', 10)).date}), 'descend');
|
||||
sortedFiles=dmFiles{sortedIndices};
|
||||
drugMediaFile=sortedFiles{1};
|
||||
fprintf('Using newest DrugMedia file: %s, skipping directory selection\n', drugMediaFile);
|
||||
end
|
||||
catch Me
|
||||
% This can be silent, not really an error
|
||||
end
|
||||
else
|
||||
for i=1:5 % give users 5 chances to get it right
|
||||
try
|
||||
% GUI input for selecting a DrugMedia file
|
||||
% sort by newest matching DrugMedia file and return that if we find one
|
||||
% For standalone mode
|
||||
% GUI input for selecting a MasterPlate Excel file
|
||||
questdlg('Select DrugMedia directory','Directory Selection','OK',...
|
||||
struct('Default','OK','Interpreter','tex'))
|
||||
dirToScan=uigetdir();
|
||||
files=dir(dirToScan);
|
||||
dmFiles={files(strncmp(files.name, 'DrugMedia_', 10)).name};
|
||||
if isempty(dmFiles)
|
||||
throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'));
|
||||
end
|
||||
% this sorts by date (newest first)
|
||||
[~, sortedIndices]=sort(datenum({files(strncmp(dmFiles.name, 'DrugMedia_', 10)).date}), 'descend');
|
||||
sortedFiles=dmFiles{sortedIndices};
|
||||
drugMediaFile=sortedFiles{1};
|
||||
catch ME
|
||||
h=msgbox(ME.message, 'Error', 'error');
|
||||
uiwait(h);
|
||||
disp('Rerunning directory selection');
|
||||
% I don't know what else we'll need to do here
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
fprintf('Using drugMediaFile: %s, skipping directory selection\n', drugMediaFile);
|
||||
end
|
||||
|
||||
% Drug and Media Plate setup
|
||||
% TODO needs better explanation
|
||||
if ispc
|
||||
[num, txt, raw]=xlsread(drugMediaFile); %'Yor1HitsMPsetFinal');
|
||||
fields={txt(2,1:5)};
|
||||
Linked=num(1,1);
|
||||
else
|
||||
opts=detectImportOptions(drugMediaFile);
|
||||
DMtbl=readtable(drugMediaFile,opts);
|
||||
fields=opts.VariableOptions;
|
||||
Linked=DMtbl{1,1};
|
||||
DMcell=readcell(drugMediaFile);
|
||||
end
|
||||
|
||||
% TODO needs better explanation
|
||||
numb=0;
|
||||
if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinatorial
|
||||
clear DM;
|
||||
excLnNum=2;
|
||||
if ispc
|
||||
while (~isequal(txt{excLnNum,2},'###'))
|
||||
numb=numb+1;
|
||||
DM.drug(numb)={raw(excLnNum,2)};
|
||||
DM.conc(numb)={raw(excLnNum,3)};
|
||||
DM.media(numb)={raw(excLnNum,4)};
|
||||
DM.mod1(numb)={raw(excLnNum,5)};
|
||||
DM.conc1(numb)={raw(excLnNum,6)};
|
||||
DM.mod2(numb)={raw(excLnNum,7)};
|
||||
DM.conc2(numb)={raw(excLnNum,8)};
|
||||
excLnNum=excLnNum+1;
|
||||
msg=strcat('NumberOf1:1DrugMediaPlates=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
|
||||
end
|
||||
else
|
||||
clear DM
|
||||
excLnNum=1;
|
||||
while (~isequal(DMcell{excLnNum+1,2},'###'))
|
||||
numb=numb+1;
|
||||
DM.drug(numb)={DMtbl(excLnNum,2)};
|
||||
DM.drug(numb)=table2cell(DM.drug{numb});
|
||||
DM.conc(numb)={DMtbl(excLnNum,3)};
|
||||
DM.conc(numb)=table2cell(DM.conc{numb});
|
||||
DM.media(numb)={DMtbl(excLnNum,4)};
|
||||
DM.media(numb)=table2cell(DM.media{numb});
|
||||
DM.mod1(numb)={DMtbl(excLnNum,5)};
|
||||
DM.mod1(numb)=table2cell(DM.mod1{numb});
|
||||
DM.conc1(numb)={DMtbl(excLnNum,6)};
|
||||
DM.conc1(numb)=table2cell(DM.conc1{numb});
|
||||
DM.mod2(numb)={DMtbl(excLnNum,7)};
|
||||
DM.mod2(numb)=table2cell(DM.mod2{numb});
|
||||
DM.conc2(numb)={DMtbl(excLnNum,8)};
|
||||
DM.conc2(numb)=table2cell(DM.conc2{numb});
|
||||
excLnNum=excLnNum+1;
|
||||
msg=strcat('NumberOf1:1DrugMediaPlates=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
|
||||
end
|
||||
end
|
||||
end
|
||||
% Legacy contengency: not ever used
|
||||
if isequal(Linked,0) % 0 indicates Drugs and Media are combinatorial
|
||||
clear DM;
|
||||
excLnNum=2;
|
||||
drgCnt=0;
|
||||
medCnt=0;
|
||||
if ispc
|
||||
while (~isequal(txt{excLnNum,2},'###'))
|
||||
drgCnt=drgCnt+1;
|
||||
DM.drug(drgCnt)={raw(excLnNum,2)};
|
||||
DM.conc(drgCnt)={raw(excLnNum,3)};
|
||||
excLnNum=excLnNum+1;
|
||||
end
|
||||
|
||||
while (~isequal(txt{excLnNum,4},'###'))
|
||||
medCnt=medCnt+1;
|
||||
DM.media(medCnt)={raw(excLnNum,4)};
|
||||
excLnNum=excLnNum+1;
|
||||
end
|
||||
else
|
||||
excLnNum=1;
|
||||
while (~isequal(DMcell{excLnNum+1,2},'###'))
|
||||
drgCnt=drgCnt+1;
|
||||
DM.drug(drgCnt)={DMtbl(excLnNum,2)};
|
||||
DM.conc(drgCnt)={DMtbl(excLnNum,3)};
|
||||
excLnNum=excLnNum+1;
|
||||
end
|
||||
|
||||
while (~isequal(DMcel{excLnNum+1,4},'###'))
|
||||
medCnt=medCnt+1;
|
||||
DM.media(medCnt)={DMtbl(excLnNum,4)};
|
||||
excLnNum=excLnNum+1;
|
||||
end
|
||||
end
|
||||
msg=strcat('NumberOfDrugs=',num2str(drgCnt), ' NumberOfMedias=',num2str(medCnt) );
|
||||
end
|
||||
|
||||
save(mpdmFile, 'fields','MP','DM','Linked');
|
||||
msgbox(sprintf('Drug-Media-MasterPlate Annotation File %s Generation Complete', mpdmFile))
|
||||
Reference in New Issue
Block a user