Skip to content

Commit 63344f0

Browse files
committed
v2.5-beta2
1 parent 254bb86 commit 63344f0

3 files changed

Lines changed: 162 additions & 74 deletions

File tree

OPERA_Source_code/OPERA.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function res=OPERA(varargin)
22

33
Version='2.5';
4-
SubVersion='2.5-beta1';
4+
SubVersion='2.5-beta2';
55
%%
66
%
77
% _______________________________________________________________________
@@ -616,6 +616,7 @@
616616
else
617617
nf=nf+1;
618618
nfID{nf,1}=strings{i};
619+
err_index=0;
619620
if regexp(strings{i},'[0-9]+-[0-9]+-[0-9]')
620621
[~,err_index] = ismember(strings{i},train.StructError{:,2});
621622
elseif regexp(strings{i},'DTXSID[0-9]+')

OPERA_Source_code/OPERA_UI.mlapp

-42 Bytes
Binary file not shown.

OPERA_Source_code/OPERA_par.m

Lines changed: 160 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function res=OPERA_par(varargin)
22

33
Version='2.5';
4-
SubVersion='2.5-beta1';
4+
SubVersion='2.5-beta2';
55
%%
66
%
77
% _______________________________________________________________________
@@ -523,6 +523,14 @@
523523
end
524524
%-----------------------------
525525

526+
poolobj = gcp('nocreate');
527+
if cpus && (isempty(poolobj)||poolobj.NumWorkers<cpus)
528+
delete(gcp('nocreate'))
529+
poolobj=parpool(cpus);
530+
elseif isempty(poolobj)
531+
poolobj=parpool;
532+
end
533+
NumWorkers=poolobj.NumWorkers;
526534

527535
%Start input Matrix
528536
if InputMatrix==1
@@ -610,6 +618,7 @@
610618
if La(i)
611619
f=f+1;
612620
FoundBy{f,1}=SearchID;
621+
inputStructure{f,1}=train.DSSToxQSARr{Lb(i),1};
613622
fprintf(fileID,'%s\t%s\n',train.DSSToxQSARr{Lb(i),1},strings{i});
614623
if (ismember('mp',lower(prop))||ismember('logp',lower(prop))) && isempty(FileSalt)
615624
salt=1;
@@ -619,6 +628,7 @@
619628
else
620629
nf=nf+1;
621630
nfID{nf,1}=strings{i};
631+
err_index=0;
622632
if regexp(strings{i},'[0-9]+-[0-9]+-[0-9]')
623633
[~,err_index] = ismember(strings{i},train.StructError{:,2});
624634
elseif regexp(strings{i},'DTXSID[0-9]+')
@@ -836,101 +846,167 @@
836846
Amb_str=strjoin(num2cell(Amb_str(1:length(Amb_str))),', ');
837847
error('Structure(s) number: %s exceed recommended size limit. CDK descriptors might fail or take long time.',Amb_str);
838848
end
839-
840-
InputDescCDK=strcat(StructureFile(1:length(StructureFile)-4),'_CDKDesc.csv');
841849
if verbose> 0
842850
fprintf(1,'CDK 2.0 calculating 2D descriptors...\n');
843851
end
852+
853+
if ~exist('CDKtemp','file')
854+
[status, msg] = mkdir('CDKtemp');
855+
if status==0
856+
if ~isempty(msg) && verbose
857+
disp(msg);
858+
end
859+
error('CDK couldn not create temp files. Check permissions');
860+
end
861+
end
862+
if strcmpi(StructureFile(length(StructureFile)-3:end),'.smi')
863+
fid = fopen(StructureFile,'r');
864+
indic = 1;
865+
while 1
866+
tline = fgetl(fid);
867+
if ~ischar(tline)
868+
break
869+
end
870+
inputStructure{indic}=strtrim(tline);
871+
indic = indic + 1;
872+
end
873+
fclose(fid);
874+
elseif strcmpi(StructureFile(length(StructureFile)-3:end),'.sdf')
875+
fid = fopen(StructureFile,'r');
876+
indic = 1;
877+
lineSDF=1;
878+
%inputStructure{indic}={};
879+
while 1
880+
tline = fgetl(fid);
881+
if ~ischar(tline)
882+
break
883+
end
884+
if strcmp('$$$$',tline)
885+
inputStructure{indic}=sprintf('%s\n',TempStructure{:});
886+
inputStructure{indic}=sprintf('%s%s',inputStructure{indic},'$$$$');
887+
indic = indic + 1;
888+
lineSDF=1;
889+
else
890+
TempStructure{lineSDF,1}= tline;
891+
lineSDF=lineSDF+1;
892+
end
893+
end
894+
fclose(fid);
895+
end
896+
for i=1:NumWorkers
897+
bins=[i:NumWorkers:size(Names,1)];
898+
if strcmpi(StructureFile(length(StructureFile)-3:end),'.txt')|| strcmpi(StructureFile(length(StructureFile)-3:end),'.smi')
899+
StructureFileTemp{i}=fullfile('CDKtemp',strcat('Struct_',num2str(i),'_temp.smi'));
900+
elseif strcmpi(StructureFile(length(StructureFile)-3:end),'.sdf')
901+
StructureFileTemp{i}=fullfile('CDKtemp',strcat('Struct_',num2str(i),'_temp.sdf'));
902+
end
903+
904+
InputDescCDKTemp{i}=fullfile('CDKtemp',strcat('CDKDesc_',num2str(i),'_temp.csv'));
905+
fileIDTemp(i) = fopen(StructureFileTemp{i}, 'w');
906+
for j=1:length(bins)
907+
if strcmpi(StructureFile(length(StructureFile)-3:end),'.txt')
908+
fprintf(fileIDTemp(i),'%s\t%s\n',inputStructure{bins(j)},Names{bins(j)});
909+
elseif strcmpi(StructureFile(length(StructureFile)-3:end),'.smi')
910+
fprintf(fileIDTemp(i),'%s\n',inputStructure{bins(j)});
911+
elseif strcmpi(StructureFile(length(StructureFile)-3:end),'.sdf')
912+
fprintf(fileIDTemp(i),'%s\n',inputStructure{bins(j)});
913+
end
914+
915+
end
916+
fclose(fileIDTemp(i));
917+
end
918+
919+
parfor i=1:NumWorkers
920+
CDKlogfile{i}=fullfile('CDKtemp',strcat('CDKlogfile_',num2str(i),'.log'));
921+
CDKerr{i}=fullfile('CDKtemp',strcat('CDKerr_',num2str(i),'.log'));
844922
if verbose<2
845-
[statusDesc,cmdoutDesc] =system (['java -jar ' strcat('"',fullfile(installdir,'CDKDescUI-2.0.jar'),'"') ' -b -t all -o ' strcat('"',InputDescCDK,'"')...
846-
' ' strcat('"',char(StructureFile),'"') ' > ' strcat('"','CDKlogfile.log','"') ' 2> ' strcat('"','CDKerr.log','"')]);
847-
if statusDesc~=0 && ~isempty(cmdoutDesc)
848-
disp(cmdoutDesc);
849-
error('CDK descriptors failed. Check input structures!');
923+
[statusDescCDK(i),cmdoutDescCDK{i}] =system (['java -jar ' strcat('"',fullfile(installdir,'CDKDescUI-2.0.jar'),'"') ' -b -t all -o ' strcat('"',InputDescCDKTemp{i},'"')...
924+
' ' strcat('"',char(StructureFileTemp{i}),'"') ' > ' strcat('"',char(CDKlogfile{i}),'"') ' 2> ' strcat('"',char(CDKerr{i}),'"')]);
925+
else
926+
statusDescCDK(i) =system (['java -jar ' strcat('"',fullfile(installdir,'CDKDescUI-2.0.jar'),'"') ' -b -t all -o ' strcat('"',InputDescCDKTemp{i},'"')...
927+
' ' strcat('"',char(StructureFileTemp{i}),'"') ' > ' strcat('"',char(CDKlogfile{i}),'"')]);
928+
end
929+
end
930+
if verbose> 0
931+
disp('Checking and loading of CDK descriptors files...');
932+
end
933+
numlines =0;
934+
XinCDK=nan(size(Names,1),286);
935+
for i=1:NumWorkers
936+
if statusDescCDK(i)~=0
937+
if ~isempty(cmdoutDescCDK{i})
938+
disp(cmdoutDescCDK{i});
850939
end
940+
error('CDK descriptors failed. Check input structures!');
941+
end
942+
if ispc
943+
[~, numlinesTemp] = system(['FINDSTR /R /N "^.*" ',InputDescCDKTemp{i},' | FIND /C ":"']); %win
851944
else
852-
statusDesc =system (['java -jar ' strcat('"',fullfile(installdir,'CDKDescUI-2.0.jar'),'"') ' -b -t all -o ' strcat('"',InputDescCDK,'"')...
853-
' ' strcat('"',char(StructureFile),'"') ' > ' strcat('"','CDKlogfile.log','"')]);
854-
if statusDesc~=0
855-
error('CDK descriptors failed. Check input structures!');
945+
[~, numlinesTemp] = system( ['wc -l ', InputDescCDKTemp{i}] ); %linux
946+
end
947+
numlines=numlines+str2double(strrep(numlinesTemp,InputDescCDKTemp{i},''))-1;
948+
try
949+
XinCDKTemp=readtable(InputDescCDKTemp{i},'delimiter','\t','DatetimeType','text');
950+
catch ME
951+
if strcmp(ME.identifier,'MATLAB:readtable:OpenFailed')
952+
error('Unable to open descriptors file');
953+
else
954+
error(ME.message);
955+
return;
856956
end
857957
end
858-
if ispc
859-
[~, numlines] = system(['FINDSTR /R /N "^.*" ',InputDescCDK,' | FIND /C ":"']); %win
860-
else
861-
[~, numlines] = system( ['wc -l ', InputDescCDK] ); %linux
958+
XinCDKTemp(:,1)=[];
959+
if strcmpi(XinCDKTemp.Properties.VariableNames(end),'Zagreb')
960+
XlabelsCDK=XinCDKTemp.Properties.VariableNames;
961+
elseif strcmpi(XinCDKTemp.Properties.VariableNames(end),'nAcid')
962+
XinCDKTemp=XinCDKTemp(:,train.reorder_CDK);
963+
XlabelsCDK=XinCDKTemp.Properties.VariableNames;
964+
else
965+
error('Check or recalculate CDK descriptors');
966+
end
967+
j=1;
968+
%XinCDK=XinCDKTemp{i};
969+
Temp=zeros(size(XinCDKTemp));
970+
971+
while j<=length(XlabelsCDK)
972+
if cellfun(@ischar,table2cell(XinCDKTemp(1,j)))
973+
Temp(:,j)=str2double(table2cell(XinCDKTemp(:,j)));
974+
else
975+
Temp(:,j)=XinCDKTemp{:,j};
976+
end
977+
j=j+1;
978+
end
979+
if size(XinCDKTemp,1)==0 || size(XinCDKTemp,2)==0
980+
error('Empty descriptors file!');
981+
end
982+
clear('XinCDKTemp');
983+
bins=[i:NumWorkers:size(Names,1)];
984+
XinCDK(bins,:)=Temp;
985+
clear('Temp');
862986
end
863-
numlines=str2double(strrep(numlines,InputDescCDK,''))-1;
987+
988+
%numlines=str2double(strrep(numlines,InputDescCDK,''))-1;
864989
if verbose>0
865990
fprintf(1,'CDK descriptors calculated for: ');
866991
fprintf(1, '%d molecules.\n',numlines);
867992
end
868993
if numlines < str2double(numStruct)
869994
error('CDK descriptors failed. Check input structures!');
870995
end
871-
872-
873-
end
874-
if verbose> 0
875-
disp('Loading of CDK descriptors file...');
876-
end
877-
try
878-
XinCDK=readtable(InputDescCDK,'delimiter','\t','DatetimeType','text');
879-
catch ME
880-
if strcmp(ME.identifier,'MATLAB:readtable:OpenFailed')
881-
error('Unable to open descriptors file');
882-
else
883-
error(ME.message);
884-
return;
885-
end
886-
end
887-
if size(XinCDK,1)==0 || size(XinCDK,2)==0
888-
error('Empty descriptors file!');
996+
889997
end
890-
XinCDK(:,1)=[];
998+
%XinCDK=vertcat(XinCDKTemp{:});
999+
8911000
if size(XinCDK,1)~=size(Xin,1)
8921001
error('Mismatch between PaDEL and CDK descriptors files')
893-
elseif strcmpi(XinCDK.Properties.VariableNames(end),'Zagreb')
894-
XlabelsCDK=XinCDK.Properties.VariableNames;
895-
elseif strcmpi(XinCDK.Properties.VariableNames(end),'nAcid')
896-
XinCDK=XinCDK(:,train.reorder_CDK);
897-
XlabelsCDK=XinCDK.Properties.VariableNames;
8981002
else
899-
error('Check or recalculate CDK descriptors');
900-
end
901-
902-
if size(XinCDK,1)==size(Xin,1)
903-
%fprintf(1,'The number of input molecules is: %d \n',size(XinCDK,1));
904-
905-
i=1;
906-
Temp=zeros(size(XinCDK));
907-
if verbose> 0
908-
disp('Checking loaded variables.');
909-
end
910-
% if cpus
911-
% parpool(cpus);
912-
% end
913-
% %parpool(3);
914-
% parfor i=1:length(XlabelsCDK)
915-
while i<=length(XlabelsCDK)
916-
if cellfun(@ischar,table2cell(XinCDK(1,i)))
917-
Temp(:,i)=str2double(table2cell(XinCDK(:,i)));
918-
else
919-
Temp(:,i)=XinCDK{:,i};
920-
end
921-
i=i+1;
922-
end
9231003
if verbose> 0
9241004
%disp(['The number of loaded CDK descriptors is: ', num2str(length(XlabelsCDK))]);
9251005
disp(['Loaded ', num2str(length(XlabelsCDK)),' CDK descriptors for ', num2str(size(XinCDK,1)),' molecules.']);
926-
9271006
end
928-
clear('XinCDK');
929-
XinCDK=Temp;
930-
clear('Temp');
9311007
end
932-
9331008
end
1009+
9341010
if fp==1
9351011
if structure==1 && inputFP==0
9361012
InputDescFP=strcat(StructureFile(1:length(StructureFile)-4),'_PadelFP.csv');
@@ -1032,11 +1108,22 @@
10321108
end
10331109
end
10341110
if cdk==1
1035-
delete(InputDescCDK);
1111+
delete(InputDescCDKTemp{:});
1112+
delete(StructureFileTemp{:});
1113+
10361114
%delete('CDKDesc.csv');
10371115
if verbose <2
1038-
delete('CDKlogfile.log');
1039-
delete('CDKerr.log');
1116+
delete(CDKlogfile{:});
1117+
delete(CDKerr{:});
1118+
end
1119+
if exist('CDKtemp','file')
1120+
[status, msg] = rmdir('CDKtemp','s');
1121+
if status==0 && verbose
1122+
if ~isempty(msg)
1123+
disp(msg);
1124+
end
1125+
warning('CDK could not delete temp files. Check permissions');
1126+
end
10401127
end
10411128
end
10421129

0 commit comments

Comments
 (0)