|
1 | 1 | function res=OPERA_par(varargin) |
2 | 2 |
|
3 | 3 | Version='2.5'; |
4 | | -SubVersion='2.5-beta1'; |
| 4 | +SubVersion='2.5-beta2'; |
5 | 5 | %% |
6 | 6 | % |
7 | 7 | % _______________________________________________________________________ |
|
523 | 523 | end |
524 | 524 | %----------------------------- |
525 | 525 |
|
| 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; |
526 | 534 |
|
527 | 535 | %Start input Matrix |
528 | 536 | if InputMatrix==1 |
|
610 | 618 | if La(i) |
611 | 619 | f=f+1; |
612 | 620 | FoundBy{f,1}=SearchID; |
| 621 | + inputStructure{f,1}=train.DSSToxQSARr{Lb(i),1}; |
613 | 622 | fprintf(fileID,'%s\t%s\n',train.DSSToxQSARr{Lb(i),1},strings{i}); |
614 | 623 | if (ismember('mp',lower(prop))||ismember('logp',lower(prop))) && isempty(FileSalt) |
615 | 624 | salt=1; |
|
619 | 628 | else |
620 | 629 | nf=nf+1; |
621 | 630 | nfID{nf,1}=strings{i}; |
| 631 | + err_index=0; |
622 | 632 | if regexp(strings{i},'[0-9]+-[0-9]+-[0-9]') |
623 | 633 | [~,err_index] = ismember(strings{i},train.StructError{:,2}); |
624 | 634 | elseif regexp(strings{i},'DTXSID[0-9]+') |
|
836 | 846 | Amb_str=strjoin(num2cell(Amb_str(1:length(Amb_str))),', '); |
837 | 847 | error('Structure(s) number: %s exceed recommended size limit. CDK descriptors might fail or take long time.',Amb_str); |
838 | 848 | end |
839 | | - |
840 | | - InputDescCDK=strcat(StructureFile(1:length(StructureFile)-4),'_CDKDesc.csv'); |
841 | 849 | if verbose> 0 |
842 | 850 | fprintf(1,'CDK 2.0 calculating 2D descriptors...\n'); |
843 | 851 | 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')); |
844 | 922 | 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}); |
850 | 939 | 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 |
851 | 944 | 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; |
856 | 956 | end |
857 | 957 | 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'); |
862 | 986 | end |
863 | | - numlines=str2double(strrep(numlines,InputDescCDK,''))-1; |
| 987 | + |
| 988 | + %numlines=str2double(strrep(numlines,InputDescCDK,''))-1; |
864 | 989 | if verbose>0 |
865 | 990 | fprintf(1,'CDK descriptors calculated for: '); |
866 | 991 | fprintf(1, '%d molecules.\n',numlines); |
867 | 992 | end |
868 | 993 | if numlines < str2double(numStruct) |
869 | 994 | error('CDK descriptors failed. Check input structures!'); |
870 | 995 | 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 | + |
889 | 997 | end |
890 | | - XinCDK(:,1)=[]; |
| 998 | + %XinCDK=vertcat(XinCDKTemp{:}); |
| 999 | + |
891 | 1000 | if size(XinCDK,1)~=size(Xin,1) |
892 | 1001 | 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; |
898 | 1002 | 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 |
923 | 1003 | if verbose> 0 |
924 | 1004 | %disp(['The number of loaded CDK descriptors is: ', num2str(length(XlabelsCDK))]); |
925 | 1005 | disp(['Loaded ', num2str(length(XlabelsCDK)),' CDK descriptors for ', num2str(size(XinCDK,1)),' molecules.']); |
926 | | - |
927 | 1006 | end |
928 | | - clear('XinCDK'); |
929 | | - XinCDK=Temp; |
930 | | - clear('Temp'); |
931 | 1007 | end |
932 | | - |
933 | 1008 | end |
| 1009 | + |
934 | 1010 | if fp==1 |
935 | 1011 | if structure==1 && inputFP==0 |
936 | 1012 | InputDescFP=strcat(StructureFile(1:length(StructureFile)-4),'_PadelFP.csv'); |
|
1032 | 1108 | end |
1033 | 1109 | end |
1034 | 1110 | if cdk==1 |
1035 | | - delete(InputDescCDK); |
| 1111 | + delete(InputDescCDKTemp{:}); |
| 1112 | + delete(StructureFileTemp{:}); |
| 1113 | + |
1036 | 1114 | %delete('CDKDesc.csv'); |
1037 | 1115 | 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 |
1040 | 1127 | end |
1041 | 1128 | end |
1042 | 1129 |
|
|
0 commit comments