Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: adjust extractAllianceGenomeOrthologs from reading JSON to TSV file #482

Merged
merged 7 commits into from
Feb 21, 2023
35 changes: 4 additions & 31 deletions code/GPRs/extractAllianceGenomeOrthologs.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,10 @@
error('Input file %s cannot be found',string(homologFilename));
end

% load input file
inputPairs = jsondecode(fileread(homologFilename));

% define output structure
fieldList = {'fromGeneId',
'fromSymbol'
'toGeneId',
'toSymbol',
'best',
'bestReverse',
'methodCount',
'totalMethodCount'};


% initialize output structure
for i = 1:length(fieldList)
orthologStructure.(fieldList{i}) = {};
end


% loop through the content to extract corresponding values
for i=1:length(inputPairs.results)
orthologStructure.fromGeneId = [orthologStructure.fromGeneId; inputPairs.results(i).gene.id];
orthologStructure.fromSymbol = [orthologStructure.fromSymbol; inputPairs.results(i).gene.symbol];
orthologStructure.toGeneId = [orthologStructure.toGeneId; inputPairs.results(i).homologGene.id];
orthologStructure.toSymbol = [orthologStructure.toSymbol; inputPairs.results(i).homologGene.symbol];
for j = 5:length(fieldList)
orthologStructure.(fieldList{j}) = [orthologStructure.(fieldList{j}); inputPairs.results(i).(fieldList{j})];
end
end

% load orthologStructure directly from tsv file
orthologStructure = importTsvFile(homologFilename);
fieldList = fieldnames(orthologStructure);

% check countBest
if countBest
Expand Down Expand Up @@ -119,7 +92,7 @@
% if the pairs are neither bestForward nor bestReverse, then only
% reserve the one with highest number of methodCount
if noBestForwardReverse
[~, topMethodCount]=maxk(cell2mat(orthologStructure.methodCount(indMore)), 1);
[~, topMethodCount]=maxk(str2double(orthologStructure.methodCount(indMore)), 1);
output.from = [output.from; orthologStructure.fromSymbol{indMore(topMethodCount)}];
output.to = [output.to; orthologStructure.toSymbol{indMore(topMethodCount)}];
end
Expand Down