Compiling CellPriofiler

cellprofiler

#1

I would like to make some changes to the CellProfiler program, compile it and then run it on another machine.

I started MatLab (V7.2.0.232 on Windows PC) and ran the developer’s version of CellProfiler with no problems. I then compiled the program using the following command:

mcc -m CellProfiler -a ./Modules -a ./DataTools -a ./ImageTools/ -a ./CPsubfunctions/ -d ./Test

When I ran CellProfiler.exe, it gave me the following error message

C:\Program Files\CellProfiler\Development\Test>CellProfiler.exe
Extracting CTF archive. This may take a few seconds, depending on the
size of your application. Please wait…
…CTF archive extraction complete.
??? Reference to non-existent field ‘CellProfilerPathname’.

Error in ==> CellProfiler>CellProfiler_OpeningFcn at 328

Error in ==> CellProfiler>gui_mainfcn at 5498

Error in ==> CellProfiler at 57.

It appears that the directory paths are not properly set. When I compared the directories of your compiled version with mine, I noticed that I have only the CellProfiler_mcr directory and not the Modules directory (with the *.txt files). There are also differences within the CellProfiler_mcr directory.

If I do not include the (-a) options in the compile command, the program gives an error trying to find CPsplash.jpg. I have tried using the MatlLab LCC compiler and the MS Visual Studio 8 C/C++compiler. Am I compiling the program properly? Where would I find more documentation on how to compile the program. Any insight would be most welcome.

Steven.


#2

Hi Steven,

Here are my instructions to compile CellProfiler. You must cut and copy the code for CompileWizard.m (code at bottom) and place this function in the CellProfiler directory. Then remove all copies of CellProfiler from MATLAB PATH except the version you wish to compile. Please ask questions if something does not make sense.

Directions to compile CellProfiler.m into CellProfiler.exe:

Note: You may want to copy CellProfiler code for the specific purpose of compiling.

  1. Run CompileWizard in the directory where CellProfiler.m is located.

  2. Cut and copy the line starting with %#function in CompileWizardText.m (last line of file) to CellProfiler.m before the first line of code (but after Help).

  3. Search for the following line in CellProfiler.m:

Pathname = fullfile(handles.Current.CellProfilerPathname,‘ImageTools’);

  1. At this line (copy over this line), cut and copy the code from CompileWizardText.m down to the load_listbox code and REPLACE ALL TEXT in CellProfiler.m down to this line (but make sure not to delete this line):

guidata(hObject, handles);

  1. Cut and copy the code from CompileWizardText.m for the function load_listbox into CellProfiler.m, replacing the function which is already there

  2. Type ‘mcc –m CellProfiler –a ‘C:\CellProfiler\CPsubfunctions\CPsplash.jpg’ at the MatLab command prompt.

%%%%%%%%%%%%%%%%%%%%%%%%
%%%% CODE FOR COMPILEWIZARD.M %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

function CompileWizard
% CompileWizard
% This function, when run in the default CellProfiler path, will produce a
% file with help information stored in variables to be used in the compiled
% version of CellProfiler.

fid = fopen(‘CompileWizardText.m’,‘w’);

ImageToolfilelist = dir(‘ImageTools/*.m’);
fprintf(fid,’%%%%%% IMAGE TOOL HELP\n’);
fprintf(fid,‘ToolHelpInfo = ‘‘Help information for individual image tools:’’;\n\n’);
for i=1:length(ImageToolfilelist)
ToolName = ImageToolfilelist(i).name;
fprintf(fid,[ToolName(1:end-2),‘Help = sprintf([…\n’]);
body = char(strread(help(ImageToolfilelist(i).name),’%s’,‘delimiter’,’’,‘whitespace’,’’));
for j = 1:size(body,1)
fixedtext = fixthistext(body(j,:));
newtext = ‘’’’,fixedtext,’\n’’…\n’];
fprintf(fid,newtext);
end
fprintf(fid,’]);\n\n’);
fprintf(fid,‘ToolHelp{’,num2str(i),’} = [ToolHelpInfo, ‘’-----------’’ 10 ‘,[ToolName(1:end-2),‘Help’],’];\n\n’]);
if exist(‘ToolList’,‘var’)
ToolList = [ToolList, ’ ‘’’,ToolName(1:end-2),’’’’];
else
ToolList = ‘’’’,ToolName(1:end-2),’’’’];
end
if exist(‘ToolListNoQuotes’,‘var’)
ToolListNoQuotes = [ToolListNoQuotes,’ ‘,ToolName(1:end-2)];
else
ToolListNoQuotes = ToolName(1:end-2);
end
end
fprintf(fid,‘handles.Current.ImageToolsFilenames = {’‘Image tools’’ ‘,ToolList,’};\n’]);
fprintf(fid,‘handles.Current.ImageToolHelp = ToolHelp;\n\n’);

clear ToolList

DataToolfilelist = dir(‘DataTools/*.m’);
fprintf(fid,’%%%%%% DATA TOOL HELP\n’);
fprintf(fid,‘ToolHelpInfo = ‘‘Help information for individual data tools:’’;\n\n’);
for i=1:length(DataToolfilelist)
ToolName = DataToolfilelist(i).name;
fprintf(fid,[ToolName(1:end-2),‘Help = sprintf([…\n’]);
body = char(strread(help(DataToolfilelist(i).name),’%s’,‘delimiter’,’’,‘whitespace’,’’));
for j = 1:size(body,1)
fixedtext = fixthistext(body(j,:));
newtext = ‘’’’,fixedtext,’\n’’…\n’];
fprintf(fid,newtext);
end
fprintf(fid,’]);\n\n’);
fprintf(fid,‘ToolHelp{’,num2str(i),’} = [ToolHelpInfo, ‘’-----------’’ 10 ‘,[ToolName(1:end-2),‘Help’],’];\n\n’]);
if exist(‘ToolList’,‘var’)
ToolList = [ToolList, ’ ‘’’,ToolName(1:end-2),’’’’];
else
ToolList = ‘’’’,ToolName(1:end-2),’’’’];
end
if exist(‘ToolListNoQuotes’,‘var’)
ToolListNoQuotes = [ToolListNoQuotes,’ ‘,ToolName(1:end-2)];
else
ToolListNoQuotes = ToolName(1:end-2);
end
end
fprintf(fid,‘handles.Current.DataToolsFilenames = {’‘Data tools’’ ‘,ToolList,’};\n’]);
fprintf(fid,‘handles.Current.DataToolHelp = ToolHelp;\n\n’);

clear ToolList

Modulesfilelist = dir(‘Modules/*.m’);
fprintf(fid,’%%%%%% MODULES HELP\n’);
for i=1:length(Modulesfilelist)
ToolName = Modulesfilelist(i).name;
fprintf(fid,[ToolName(1:end-2),‘Help = sprintf([…\n’]);
body = char(strread(help(Modulesfilelist(i).name),’%s’,‘delimiter’,’’,‘whitespace’,’’));
for j = 1:size(body,1)
fixedtext = fixthistext(body(j,:));
newtext = ‘’’’,fixedtext,’\n’’…\n’];
fprintf(fid,newtext);
end
fprintf(fid,’]);\n\n’);
fprintf(fid,‘ToolHelp{’,num2str(i),’} = ‘,ToolName(1:end-2),‘Help;\n\n’]);
if exist(‘ToolList’,‘var’)
ToolList = [ToolList, ’ ‘’’,ToolName(1:end-2),’’’’];
else
ToolList = ‘’’’,ToolName(1:end-2),’’’’];
end
if exist(‘ToolListNoQuotes’,‘var’)
ToolListNoQuotes = [ToolListNoQuotes,’ ‘,ToolName(1:end-2)];
else
ToolListNoQuotes = ToolName(1:end-2);
end
end
fprintf(fid,‘handles.Current.ModulesFilenames = {’,ToolList,’};\n’]);
fprintf(fid,‘handles.Current.ModulesHelp = ToolHelp;\n\n’);

clear ToolList

Helpfilelist = dir(‘Help/*.m’);
fprintf(fid,’%%%%%% HELP\n’);
ToolCount=1;
GSToolCount=1;
for i=1:length(Helpfilelist)
ToolName = Helpfilelist(i).name;
if strncmp(ToolName,‘GS’,2)
fprintf(fid,‘GSToolHelp{’,num2str(GSToolCount),’} = sprintf(…\n’]);
GSToolCount=GSToolCount+1;
body = char(strread(help(Helpfilelist(i).name),’%s’,‘delimiter’,’’,‘whitespace’,’’));
for j = 1:size(body,1)
fixedtext = strrep(body(j,:),’’’’,’’’’’’);
fixedtext = strrep(fixedtext,’’,’\\’);
fixedtext = strrep(fixedtext,’%’,’%%%%’);
newtext = ‘’’’,fixedtext,’\n’’…\n’];
fprintf(fid,newtext);
end
fprintf(fid,’]);\n\n’);
if exist(‘GSToolList’,‘var’)
GSToolList = [GSToolList, ’ ‘’’,ToolName(1:end-2),’’’’];
else
GSToolList = ‘’’’,ToolName(1:end-2),’’’’];
end
else
fprintf(fid,‘ToolHelp{’,num2str(ToolCount),’} = sprintf(…\n’]);
ToolCount=ToolCount+1;
body = char(strread(help(Helpfilelist(i).name),’%s’,‘delimiter’,’’,‘whitespace’,’’));
for j = 1:size(body,1)
fixedtext = strrep(body(j,:),’’’’,’’’’’’);
fixedtext = strrep(fixedtext,’’,’\\’);
fixedtext = strrep(fixedtext,’%’,’%%%%’);
newtext = ‘’’’,fixedtext,’\n’’…\n’];
fprintf(fid,newtext);
end
fprintf(fid,’]);\n\n’);
if exist(‘ToolList’,‘var’)
ToolList = [ToolList, ’ ‘’’,ToolName(1:end-2),’’’’];
else
ToolList = ‘’’’,ToolName(1:end-2),’’’’];
end
end
end
fprintf(fid,‘handles.Current.HelpFilenames = {’‘Help’’ ‘,ToolList,’};\n’]);
fprintf(fid,‘handles.Current.Help = ToolHelp;\n\n’);

fprintf(fid,‘handles.Current.GSFilenames = {’‘Help’’ ‘,GSToolList,’};\n’]);
fprintf(fid,‘handles.Current.GS = GSToolHelp;\n\n’);

clear ToolList

Modulefilelist = dir(‘Modules/*.m’);
fprintf(fid,’%%%%%% load_listbox code (replace function in CellProfiler.m)\n\n’);
FileProcessingFiles ={};
PreProcessingFiles={};
ObjectProcessingFiles={};
MeasurementFiles={};
OtherFiles={};
for i=1:length(Modulefilelist)
name=Modulefilelist(i).name;
name=name(1:end-2);
if file_in_category(Modulefilelist(i).name, ‘File Processing’)
FileProcessingFiles(length(FileProcessingFiles)+1)=cellstr(name);
elseif file_in_category(Modulefilelist(i).name, ‘Image Processing’)
PreProcessingFiles(length(PreProcessingFiles)+1)=cellstr(name);
elseif file_in_category(Modulefilelist(i).name, ‘Object Processing’)
ObjectProcessingFiles(length(ObjectProcessingFiles)+1)=cellstr(name);
elseif file_in_category(Modulefilelist(i).name, ‘Measurement’)
MeasurementFiles(length(MeasurementFiles)+1)=cellstr(name);
else
OtherFiles(length(OtherFiles)+1)=cellstr(name);
end

%%% CODE TO WRITE TEXT FILES OF MODULES
fid2=fopen(fullfile(pwd,'Modules',Modulefilelist(i).name));
fid3=fopen(fullfile(pwd,'Modules',[name,'.txt']),'w');
while 1;
    output = fgetl(fid2); if ~ischar(output); break; end;
    if strncmp(output,'%defaultVAR',11)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%choiceVAR',10)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%textVAR',8)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%pathnametextVAR',16)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%filenametextVAR',16)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%infotypeVAR',12)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%inputtypeVAR',13)
        fprintf(fid3,[fixthistext2(output),'\n']);
    elseif strncmp(output,'%%%VariableRevisionNumber',25)
        fprintf(fid3,[fixthistext2(output),'\n']);
    end
end
fclose(fid2);
fclose(fid3);
%%% END CODE TO WRITE TEXT FILES OF MODULES

end
fprintf(fid,‘CategoryList = {’‘File Processing’’ ‘‘Image Processing’’ ‘‘Object Processing’’ ‘‘Measurement’’ ‘‘Other’’};\n’);

fprintf(fid,‘FileProcessingFiles = {’);
for i=1:length(FileProcessingFiles)
fprintf(fid,’’’’,FileProcessingFiles{i},’’’ ‘]);
end
fprintf(fid,’};\n’);

fprintf(fid,‘PreProcessingFiles = {’);
for i=1:length(PreProcessingFiles)
fprintf(fid,’’’’,PreProcessingFiles{i},’’’ ‘]);
end
fprintf(fid,’};\n’);

fprintf(fid,‘ObjectProcessingFiles = {’);
for i=1:length(ObjectProcessingFiles)
fprintf(fid,’’’’,ObjectProcessingFiles{i},’’’ ‘]);
end
fprintf(fid,’};\n’);

fprintf(fid,‘MeasurementFiles = {’);
for i=1:length(MeasurementFiles)
fprintf(fid,’’’’,MeasurementFiles{i},’’’ ‘]);
end
fprintf(fid,’};\n’);

fprintf(fid,‘OtherFiles = {’);
for i=1:length(OtherFiles)
fprintf(fid,’’’’,OtherFiles{i},’’’ ‘]);
end
fprintf(fid,’};\n’);

fprintf(fid,‘set(AddModuleWindowHandles.ModuleCategoryListBox,’‘String’’,CategoryList,’‘Value’’,])\n’);
fprintf(fid,‘set(AddModuleWindowHandles.ModulesListBox,’‘String’’,FileProcessingFiles,’‘Value’’,])\n’);
fprintf(fid,‘AddModuleWindowHandles.ModuleStrings{1} = FileProcessingFiles;\n’);
fprintf(fid,‘AddModuleWindowHandles.ModuleStrings{2} = PreProcessingFiles;\n’);
fprintf(fid,‘AddModuleWindowHandles.ModuleStrings{3} = ObjectProcessingFiles;\n’);
fprintf(fid,‘AddModuleWindowHandles.ModuleStrings{4} = MeasurementFiles;\n’);
fprintf(fid,‘AddModuleWindowHandles.ModuleStrings{5} = OtherFiles;\n’);
fprintf(fid,‘guidata(AddModuleWindowHandles.AddModuleWindow,AddModuleWindowHandles);\n\n’);

CPsubfunctionfilelist = dir(‘CPsubfunctions/*.m’);
for i=1:length(CPsubfunctionfilelist)
ToolName = CPsubfunctionfilelist(i).name;
if exist(‘ToolListNoQuotes’,‘var’)
ToolListNoQuotes = [ToolListNoQuotes,’ ',ToolName(1:end-2)];
else
ToolListNoQuotes = ToolName(1:end-2);
end
end

fprintf(fid,’%%%%%% FUNCTIONS TO ADD (place before first line of code in CellProfiler.m)\n’);
fprintf(fid,’%%#function ',ToolListNoQuotes]);

fclose(fid);

%%%%%%%%%%%%%%%%%%%%
%%% SUBFUNCTIONS %%%
%%%%%%%%%%%%%%%%%%%%

function fixedtext = fixthistext(text)

fixedtext = strrep(text,’’’’,’’’’’’’’’’);
fixedtext = strrep(fixedtext,’’,’\\’);
fixedtext = strrep(fixedtext,’%’,’%%%%’);

function c = file_in_category(filename, category)
h = help(filename);
c = strfind(h, 'Category: ’ category]);

function fixedtext = fixthistext2(text)

fixedtext = strrep(text,’’’’,’’’’’’);
fixedtext = strrep(fixedtext,’’,’\’);
fixedtext = strrep(fixedtext,’%’,’%%’);

%%%%%%%%%%%%%%%%
%%%% END OF CODE %%%%
%%%%%%%%%%%%%%%%


#3

Thanks for the detailed instructions. I recompiled the modified CellProfiler.m program and got the following error messages when it is executed:

??? Reference to non-existent field ‘CellProfilerPathname’.

Error in ==> CellProfiler>CellProfiler_OpeningFcn at 332

Error in ==> CellProfiler>gui_mainfcn at 5911

Error in ==> CellProfiler at 61.

MATLAB:nonExistentField

I have used rmpath within MATLAB to remove reference to other CellProfiler references except for the following:

C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755
C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755\CPsubfunctions
C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755\DataTools
C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755\Help
C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755\ImageTools
C:\Program Files\CellProfiler\MATLAB_CellProfilerv1.0.3755\Modules

I could send you the modified file if you required it for debugging.

Steven.


#4

Hi Steven,

Please look at instruction #3 that I provided in my previous post. You can see from your error that it is failing at this particular line. The next step is to REPLACE this text with the text from CompileWizardText.m, which means this line should not exist when you compile (it will fail otherwise). This means you should be replacing line #332 all the way down to the next specified line guidata(hObject, handles), however you DO NOT replace this line. In the latest version 1.0.4303, this means you will replace lines #332-499. Let me know how it goes.

Regards,
Mike


#5

Thanks for the additional insight in your reply. After trying out a number of different scenarios, I was able to get CellProfiler to compile. What worked was that I replaced

Pathname = fullfile(handles.Current.CellProfilerPathname,‘ImageTools’);
by
Pathname = fullfile(handles.Current.CellProfilerPathname,‘Modules’);

in instruction #3 of your first post. I have also updated to your latest version 1.0.4303, and the lines that was replaced from the original file were #330-, or #332 after inserting the first line according to your instruction #2.

Thanks again, Steven.


#6

Hi Steven,

That make’s sense, since I think I wrote those instructions before we had added the modules folder into this part of the code, thanks for figuring that out!

Mike