0001
0002
0003 function tests = hmmerTests
0004 tests = functiontests(localfunctions);
0005 end
0006
0007 function testHmmer(testCase)
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 [ST, I]=dbstack('-completenames');
0022 ravenPath=fileparts(fileparts(fileparts(ST(I).file)));
0023
0024
0025 tmpDIR=tempname;
0026 outFile=tempname;
0027
0028
0029 [~, ~]=system(['mkdir "' tmpDIR '"']);
0030
0031 sourceDir = fileparts(which(mfilename));
0032 copyfile(fullfile(sourceDir,'test_data','yeast_galactosidases.fa'),tmpDIR);
0033 copyfile(fullfile(sourceDir,'test_data','human_galactosidases.fa'),tmpDIR);
0034
0035
0036
0037 if isunix
0038 if ismac
0039 binEnd='.mac';
0040 else
0041 binEnd='';
0042 end
0043 elseif ispc
0044 wslPath.tmpDIR = getWSLpath(tmpDIR);
0045 wslPath.hmmbuild = getWSLpath(fullfile(ravenPath,'software','hmmer','hmmbuild'));
0046 wslPath.hmmsearch = getWSLpath(fullfile(ravenPath,'software','hmmer','hmmsearch'));
0047 filesep='/';
0048 else
0049 dispEM('Unknown OS, exiting.')
0050 return
0051 end
0052
0053
0054 actHmmResult.genes = {};
0055 actHmmResult.scores = [];
0056
0057
0058 expHmmResult.genes = {'sp|P41947|MEL6_YEASX','sp|P41946|MEL5_YEASX', 'sp|P41945|MEL2_YEASX', 'sp|P04824|MEL1_YEASX'};
0059 expHmmResult.scores = [10^-250, 10^-250, 10^-250, 10^-250];
0060
0061
0062 cores = evalc('feature(''numcores'')');
0063 cores = strsplit(cores, 'MATLAB was assigned: ');
0064 cores = regexp(cores{2},'^\d*','match');
0065 cores = cores{1};
0066
0067
0068
0069 if ismac || isunix
0070 [~, ~]=system(['"' fullfile(ravenPath,'software','hmmer',['hmmbuild' binEnd]) '" --cpu "' num2str(cores) '" "' fullfile(tmpDIR,'human_galactosidases.hmm') '" "' fullfile(tmpDIR,'yeast_galactosidases.fa') '"']);
0071 else
0072 [~, ~]=system(['wsl "' wslPath.hmmbuild '" --cpu "' num2str(cores) '" "' wslPath.tmpDIR '/human_galactosidases.hmm" "' wslPath.tmpDIR '/yeast_galactosidases.fa"']);
0073 end
0074
0075
0076 if ismac || isunix
0077 [~, output]=system(['"' fullfile(ravenPath,'software','hmmer',['hmmsearch' binEnd]) '" --cpu "' num2str(cores) '" "' fullfile(tmpDIR,'human_galactosidases.hmm') '" "' fullfile(tmpDIR,'yeast_galactosidases.fa') '"']);
0078 else
0079 [~, output]=system(['wsl "' wslPath.hmmsearch '" --cpu "' num2str(cores) '" "' wslPath.tmpDIR '/human_galactosidases.hmm" "' wslPath.tmpDIR '/yeast_galactosidases.fa"']);
0080 end
0081
0082
0083 fid=fopen(outFile,'w');
0084 fwrite(fid,output);
0085 fclose(fid);
0086
0087
0088
0089 geneCounter=0;
0090 fid=fopen(outFile,'r');
0091 beginMatches=false;
0092 while 1
0093
0094 tline = fgetl(fid);
0095
0096
0097 if ~ischar(tline)
0098 break;
0099 end
0100
0101 if and(beginMatches,strcmp(tline,' ------ inclusion threshold ------'))
0102 break;
0103 end
0104
0105 if beginMatches==false
0106
0107 if any(strfind(tline,'E-value '))
0108
0109 tline = fgetl(fid);
0110 beginMatches=true;
0111 end
0112 else
0113
0114 if ~strcmp(tline,' [No hits detected that satisfy reporting thresholds]') && ~isempty(tline)
0115 elements=regexp(tline,' ','split');
0116 elements=elements(cellfun(@any,elements));
0117
0118
0119 score=str2double(elements{1});
0120 gene=elements{9};
0121 if score<=10^-50
0122
0123
0124 if score==0
0125 score=10^-250;
0126 end
0127
0128
0129 geneCounter=geneCounter+1;
0130 actHmmResult.genes{geneCounter}=gene;
0131 actHmmResult.scores(geneCounter)=score;
0132 end
0133 else
0134 break;
0135 end
0136 end
0137 end
0138 fclose(fid);
0139
0140
0141 delete([outFile '*']);
0142
0143
0144 [~, ~]=system(['rm "' tmpDIR '" -r']);
0145
0146
0147
0148 verifyEqual(testCase,actHmmResult,expHmmResult);
0149
0150
0151 actHmmResult.score(2)=1;
0152 verifyNotEqual(testCase,actHmmResult,expHmmResult);
0153 end