0001 function complexInfo = getComplexData(taxonomicID, modelAdapter)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 if nargin < 2 || isempty(modelAdapter)
0035 modelAdapter = ModelAdapterManager.getDefault();
0036 if isempty(modelAdapter)
0037 error('Either send in a modelAdapter or set the default model adapter in the ModelAdapterManager.')
0038 end
0039 end
0040
0041 if nargin<1 || isempty(taxonomicID)
0042 taxonomicID = modelAdapter.getParameters().complex.taxonomicID;
0043 end
0044
0045 params = modelAdapter.params;
0046 if isempty(taxonomicID)
0047 printOrange('WARNING: No taxonomicID specified.');
0048 return
0049 elseif taxonomicID == 0
0050 taxonomicID = [];
0051 end
0052
0053 webOptions = weboptions('Timeout', 30);
0054 try
0055 url1 = 'https://www.ebi.ac.uk/intact/complex-ws/search/*';
0056 if ~isempty(taxonomicID)
0057 url1 = [url1 '?facets=species&filters=species:("' num2str(taxonomicID) '")'];
0058 end
0059 data = webread(url1,webOptions);
0060 catch ME
0061 if (strcmp(ME.identifier,'MATLAB:webservices:HTTP404StatusCodeError'))
0062 error('Cannot connect to the Complex Portal, perhaps the server is not responding');
0063 end
0064 end
0065 if data.size == 0
0066 error('No data could be gathered from Complex Portal for the specified taxonomicID.')
0067 end
0068 complexData = cell(data.size,7);
0069
0070 progressbar('Retrieving information for complexes');
0071 for i = 1:data.size
0072 progressbar(i/data.size)
0073 url2 = 'https://www.ebi.ac.uk/intact/complex-ws/complex/';
0074 complexID = data.elements(i,1).complexAC;
0075 try
0076 temp = webread([url2 complexID],webOptions);
0077 catch ME
0078 if (strcmp(ME.identifier,'MATLAB:webservices:HTTP404StatusCodeError'))
0079 printOrange(['WARNING: Cannot retrieve the information for ' complexID '.\n']);
0080 end
0081 temp = [];
0082 end
0083
0084 if ~isempty(temp)
0085 complexData(i,1) = {temp.complexAc};
0086 complexData(i,2) = {temp.name};
0087 complexData(i,3) = {temp.species};
0088
0089 idxIntType = find(strcmpi({temp.participants.interactorType}, 'protein'));
0090
0091
0092
0093 if numel(idxIntType) > 0
0094 complexData(i,4) = {{temp.participants(idxIntType).name}};
0095 complexData(i,5) = {{temp.participants(idxIntType).identifier}};
0096 else
0097 complexData(i,4) = {{temp.participants.name}};
0098 complexData(i,5) = {{temp.participants.identifier}};
0099 end
0100
0101
0102
0103
0104
0105 if ~cellfun('isempty',{temp.participants.stochiometry})
0106
0107
0108
0109 switch numel(idxIntType)
0110 case 0
0111 stochiometry = split({temp.participants.stochiometry}.', ',');
0112 complexData(i,7) = {2};
0113 case 1
0114 stochiometry = split({temp.participants(idxIntType).stochiometry}.', ',').';
0115 complexData(i,7) = {1};
0116 otherwise
0117 stochiometry = split({temp.participants(idxIntType).stochiometry}.', ',');
0118 complexData(i,7) = {1};
0119 end
0120 values = str2double(erase(stochiometry(:,1),"minValue: ")).';
0121 complexData(i,6) = {values};
0122 else
0123 complexData(i,6) = {repelem(0,numel(complexData{i,4}))};
0124 complexData(i,7) = {0};
0125 end
0126 end
0127 end
0128 fprintf('\n');
0129
0130
0131 complexComplex = find([complexData{:,7}]==2);
0132 if ~isempty(complexComplex)
0133 for i=1:numel(complexComplex)
0134 subComplex = complexData{complexComplex(i),5};
0135 subComplexS = complexData{complexComplex(i),6};
0136 subComplexIdx = find(ismember(complexData(:,1),subComplex));
0137 allGenes = horzcat(complexData{subComplexIdx,4});
0138 allProts = horzcat(complexData{subComplexIdx,5});
0139 allStoch = {complexData{subComplexIdx,6}};
0140 for j=1:numel(subComplex)
0141 allStoch{j}=allStoch{j}*subComplexS(j);
0142 end
0143 allStoch = horzcat(allStoch{:});
0144 [allGenes,ia,ic] = unique(allGenes,'stable');
0145 allProts = allProts(ia);
0146 allStoch = splitapply(@sum, allStoch', ic);
0147 complexData{complexComplex(i),4} = allGenes;
0148 complexData{complexComplex(i),5} = allProts;
0149 complexData{complexComplex(i),6} = allStoch;
0150 end
0151 end
0152
0153 rowHeadings = {'complexID','name','species','geneName','protID','stochiometry','defined'};
0154
0155 complexInfo = cell2struct(complexData, rowHeadings, 2);
0156
0157
0158 jsontxt = jsonencode(cell2table(complexData, 'VariableNames', rowHeadings));
0159
0160 fid = fopen(fullfile(params.path,'data','ComplexPortal.json'), 'w');
0161 fprintf(fid, '%s', jsontxt);
0162 fclose(fid);
0163 fprintf('Model-specific ComplexPortal database stored at %s\n',fullfile(params.path,'data','ComplexPortal.json'));
0164 end