DMPexcel2mat.m refactor
This commit is contained in:
@@ -1,34 +1,100 @@
|
|||||||
%% CALLED BY EASYconsole.m %%
|
%% CALLED BY EASYconsole.m %%
|
||||||
w=pwd
|
|
||||||
numOfMPs=0;
|
global mpdmFile
|
||||||
%GUI input for selecting a MasterPlate Excel file
|
global masterPlateFile
|
||||||
questdlg('\fontsize{20} Select Master Plate File','File Selection','OK', struct('Default','OK','Interpreter','tex'))
|
global drugMediaFile
|
||||||
[Scanfiles, pathname]=uigetfile('*.*','MultiSelect','off');
|
global matDir
|
||||||
if ispc
|
|
||||||
MPdir= fullfile(pathname,'\');
|
% If we already have mpdmFile, don't recreate
|
||||||
else
|
if exist(mpdmFile, 'file') && ~isempty(mpdmFile)
|
||||||
MPdir=fullfile(pathname,'/');
|
disp(strcat('The Drug Media/MasterPlate Annotation File: ', mpdmFile, ' exists, skipping DMPexcel2mat.m'));
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
infile= Scanfiles(1,:);
|
% 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};
|
||||||
|
isempty(mpFiles) && throw(MException('MATLAB:dir', 'No MasterPlate_ files in the default MasterPlate directory'));
|
||||||
|
% 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
|
||||||
|
|
||||||
cd(MPdir)
|
for i-1:5 % give users 5 chances to get it right
|
||||||
|
try
|
||||||
%fid=fopen(infile)%('exp23PrintTimes.xls'); % textread puts date and time sequentially into vector
|
% 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};
|
||||||
|
isempty(mpFiles) && throw(MException('MATLAB:dir', 'No MasterPlate_ files in directory'))
|
||||||
|
% 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
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i-1:5 % give users 5 chances to get it right
|
||||||
|
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};
|
||||||
|
isempty(mpFiles) && throw (MException('MATLAB:dir', 'No MasterPlate_ files in directory'))
|
||||||
|
% 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
|
||||||
|
end
|
||||||
|
else
|
||||||
|
disp(strcat('Using MasterPlate file: ', masterPlateFile, ', skipping directory selection');
|
||||||
|
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
|
if ispc
|
||||||
[num, txt, raw] = xlsread(infile); %,'Yor1HitsMPsetFinal');
|
[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
|
fields= {txt(2,1:15)}; %or 1:17 for later but dont wish to exceed and cause error ? if used
|
||||||
else
|
else
|
||||||
clear MPtbl
|
clear MPtbl
|
||||||
opts = detectImportOptions(infile);
|
opts=detectImportOptions(masterPlateFile);
|
||||||
MPtbl = readtable(infile,opts);
|
MPtbl=readtable(masterPlateFile,opts);
|
||||||
MPtbl= readtable(infile);
|
MPtbl=readtable(masterPlateFile);
|
||||||
fields={opts.VariableNames}; %? if used anywhere although 'saved' to MPDMmat
|
fields={opts.VariableNames}; %? if used anywhere although 'saved' to MPDMmat
|
||||||
MPcell= readcell(infile);
|
MPcell=readcell(masterPlateFile);
|
||||||
end
|
end
|
||||||
|
|
||||||
cd(w)
|
|
||||||
numb=0;
|
numb=0;
|
||||||
clear MP;
|
clear MP;
|
||||||
try
|
try
|
||||||
@@ -50,18 +116,14 @@ try
|
|||||||
MP(numb).orfRep= ' ';
|
MP(numb).orfRep= ' ';
|
||||||
MP(numb).specifics= ' ';
|
MP(numb).specifics= ' ';
|
||||||
end
|
end
|
||||||
|
|
||||||
% Future MP field
|
% Future MP field
|
||||||
% if size(raw,2)>17
|
% if size(raw,2)>17
|
||||||
% MP(numb).specifics2= {raw((excLnNum+1):(excLnNum+384),18)}; % added 12_1008 to specify strain Bkground in MP
|
% MP(numb).specifics2= {raw((excLnNum+1):(excLnNum+384),18)}; % added 12_1008 to specify strain Bkground in MP
|
||||||
% else
|
% else
|
||||||
% MP(numb).specifics2=' ';
|
% MP(numb).specifics2=' ';
|
||||||
% end
|
% end
|
||||||
|
|
||||||
excLnNum=excLnNum+385;
|
excLnNum=excLnNum+385;
|
||||||
|
|
||||||
msg=strcat('NumberOfMP = ',num2str(numb), ' lastLineNo. = ',num2str(excLnNum));
|
msg=strcat('NumberOfMP = ',num2str(numb), ' lastLineNo. = ',num2str(excLnNum));
|
||||||
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
excLnNum=1;
|
excLnNum=1;
|
||||||
@@ -88,49 +150,96 @@ try
|
|||||||
MP(numb).orfRep= ' ';
|
MP(numb).orfRep= ' ';
|
||||||
MP(numb).specifics= ' ';
|
MP(numb).specifics= ' ';
|
||||||
end
|
end
|
||||||
|
|
||||||
excLnNum=excLnNum+385;
|
excLnNum=excLnNum+385;
|
||||||
msg=strcat('NumberOfMP = ',num2str(numb), 'lastLineNo. = ',num2str(excLnNum))
|
msg=strcat('NumberOfMP = ',num2str(numb), 'lastLineNo. = ',num2str(excLnNum))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
catch ME
|
catch ME
|
||||||
h = msgbox(msg,'Check Number of Master Plates and Excel Lines')
|
h = msgbox(ME.message, 'Error', 'error');
|
||||||
uiwait(h);
|
uiwait(h);
|
||||||
end %end for try MP excel sheet input
|
end
|
||||||
|
|
||||||
%DMupload
|
%DMupload
|
||||||
%Drug and Media Plate setup Upload from Excel
|
%Drug and Media Plate setup Upload from Excel
|
||||||
cd(MPdir);
|
|
||||||
excLnNum=1;
|
excLnNum=1;
|
||||||
numOfDrugs=0;
|
numOfDrugs=0;
|
||||||
numOfMedias=0;
|
numOfMedias=0;
|
||||||
|
|
||||||
%GUI input for selecting a MasterPlate Excel file
|
% Grabbing the bare filename from the MasterPlate file to see if we can automatically
|
||||||
questdlg('\fontsize{20} Select DrugMedia File','File Selection','OK', struct('Default','OK','Interpreter','tex'));
|
% find a matching DrugMedia file
|
||||||
[Scanfiles, pathname]=uigetfile('*.*', 'MultiSelect','off');
|
[mpFile, mpPath]=masterPlateFile
|
||||||
DMdir=fullfile(pathname);
|
mpFileParts=strsplit(mpFile, '_');
|
||||||
clear infile;
|
mpBareFileName=strjoin(parts(2:end-1), '_');
|
||||||
infile= Scanfiles(1,:);
|
|
||||||
cd(DMdir)
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
disp(strcat('Using matching DrugMedia file: ', drugMediaFile, ', skipping directory selection'));
|
||||||
|
else
|
||||||
|
% Try to find the DrugMedia file automatically (newest created first)
|
||||||
|
files=dir(matDir)
|
||||||
|
dmFiles={files(strncmp(files.name, 'DrugMedia_', 10)).name};
|
||||||
|
isempty(dmFiles) && throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'))
|
||||||
|
% this sorts by date (newest first)
|
||||||
|
[~, sortedIndices]=sort(datenum({files(strncmp(dmFiles.name, 'DrugMedia_', 10)).date}), 'descend');
|
||||||
|
sortedFiles=dmFiles{sortedIndices};
|
||||||
|
drugMediaFile=sortedFiles{1};
|
||||||
|
disp(strcat('Using newest DrugMedia file: ', drugMediaFile, ', skipping directory selection'));
|
||||||
|
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};
|
||||||
|
isempty(dmFiles) && throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'))
|
||||||
|
% 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
|
||||||
|
end
|
||||||
|
else
|
||||||
|
disp(strcat('Using drugMediaFile: ', drugMediaFile, ', skipping directory selection'));
|
||||||
|
end
|
||||||
|
|
||||||
|
% Drug and Media Plate setup
|
||||||
|
% TODO needs better explanation
|
||||||
if ispc
|
if ispc
|
||||||
[num, txt, raw] = xlsread(infile); %,'Yor1HitsMPsetFinal');
|
[num, txt, raw]=xlsread(drugMediaFile); %'Yor1HitsMPsetFinal');
|
||||||
fields={txt(2,1:5)};
|
fields={txt(2,1:5)};
|
||||||
Linked=num(1,1);
|
Linked=num(1,1);
|
||||||
else
|
else
|
||||||
opts = detectImportOptions(infile);
|
opts=detectImportOptions(drugMediaFile);
|
||||||
DMtbl= readtable(infile,opts);
|
DMtbl=readtable(drugMediaFile,opts);
|
||||||
fields=opts.VariableOptions;
|
fields=opts.VariableOptions;
|
||||||
Linked=DMtbl{1,1};
|
Linked=DMtbl{1,1};
|
||||||
DMcell= readcell(infile);
|
DMcell=readcell(drugMediaFile);
|
||||||
end
|
end
|
||||||
|
|
||||||
cd(w)
|
% TODO needs better explanation
|
||||||
numb=0;
|
numb=0;
|
||||||
|
|
||||||
if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinatorial
|
if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinatorial
|
||||||
clear DM;
|
clear DM;
|
||||||
%try
|
|
||||||
excLnNum=2;
|
excLnNum=2;
|
||||||
if ispc
|
if ispc
|
||||||
while (~isequal(txt{excLnNum,2},'###'))
|
while (~isequal(txt{excLnNum,2},'###'))
|
||||||
@@ -169,7 +278,7 @@ if isequal(Linked,1) %Drugs and Media are linked 1 to 1; else they are combina
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
%Legacy contengency -Not ever used!!
|
% Legacy contengency: not ever used
|
||||||
if isequal(Linked,0) % 0 indicates Drugs and Media are combinatorial
|
if isequal(Linked,0) % 0 indicates Drugs and Media are combinatorial
|
||||||
clear DM;
|
clear DM;
|
||||||
excLnNum=2;
|
excLnNum=2;
|
||||||
@@ -188,7 +297,7 @@ if isequal(Linked,0) %0 indicates Drugs and Media are combinatorial
|
|||||||
DM.media(medCnt) = {raw(excLnNum,4)};
|
DM.media(medCnt) = {raw(excLnNum,4)};
|
||||||
excLnNum=excLnNum+1;
|
excLnNum=excLnNum+1;
|
||||||
end
|
end
|
||||||
else %else if not PC (Then linux or other)
|
else
|
||||||
excLnNum=1;
|
excLnNum=1;
|
||||||
while (~isequal(DMcell{excLnNum+1,2},'###'))
|
while (~isequal(DMcell{excLnNum+1,2},'###'))
|
||||||
drgCnt=drgCnt+1;
|
drgCnt=drgCnt+1;
|
||||||
@@ -206,7 +315,5 @@ if isequal(Linked,0) %0 indicates Drugs and Media are combinatorial
|
|||||||
msg=strcat('NumberOfDrugs = ',num2str(drgCnt), ' NumberOfMedias = ',num2str(medCnt) )
|
msg=strcat('NumberOfDrugs = ',num2str(drgCnt), ' NumberOfMedias = ',num2str(medCnt) )
|
||||||
end
|
end
|
||||||
|
|
||||||
save (fullfile(MPdir,'MPDMmat'), 'fields','MP','DM','Linked');
|
save(mpdmFile, 'fields','MP','DM','Linked');
|
||||||
|
msgbox([strcat('Drug-Media-MasterPlate Annotation File', mpdmFile,'Generation Complete')])
|
||||||
cd(w)
|
|
||||||
msgbox(['Drug-Media-MasterPlate Annotation File Generation Complete'])
|
|
||||||
|
|||||||
Reference in New Issue
Block a user