Home > testing > unit_tests > cdhitTests.m

cdhitTests

PURPOSE ^

run this test case with the command

SYNOPSIS ^

function tests = cdhitTests

DESCRIPTION ^

run this test case with the command
results = runtests('cdhitTests.m')

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %run this test case with the command
0002 %results = runtests('cdhitTests.m')
0003 function tests = cdhitTests
0004 tests = functiontests(localfunctions);
0005 end
0006 
0007 function testCdhit(testCase)
0008 %This unit test comprises the functionality test for CD-HIT in RAVEN:
0009 % 1. Check for resulting file against the expected one.
0010 
0011 %%
0012 %Get the directory for RAVEN Toolbox
0013 [ST, I]=dbstack('-completenames');
0014 ravenPath=fileparts(fileparts(fileparts(ST(I).file)));
0015 
0016 %Identify the operating system
0017 if isunix
0018     if ismac
0019         binEnd='.mac';
0020     else
0021         binEnd='';
0022     end
0023 elseif ispc
0024     binEnd='.exe';
0025 else
0026     dispEM('Unknown OS, exiting.')
0027     return
0028 end
0029 
0030 %Import structure that contains expected MAFFT results
0031 sourceDir = fileparts(which(mfilename));
0032 load([sourceDir,'/test_data/expCdhitMafftOutput.mat'],'expCdhitMafftOutput');
0033 
0034 %Generate temporary names for working directory and outFile
0035 tmpDIR=tempname;
0036 outFile=tempname;
0037 
0038 %Run CD-HIT multi-threaded to use all logical cores assigned to MATLAB
0039 cores = evalc('feature(''numcores'')');
0040 cores = strsplit(cores, 'MATLAB was assigned: ');
0041 cores = regexp(cores{2},'^\d*','match');
0042 cores = cores{1};
0043 
0044 %Create a temporary folder and copy multi-FASTA file there
0045 [~, ~]=system(['mkdir "' tmpDIR '"']);
0046 
0047 sourceDir = fileparts(which(mfilename));
0048 copyfile(fullfile(sourceDir,'test_data','yeast_galactosidases.fa'),tmpDIR);
0049 
0050 %%
0051 %Run protein clustering with CD-HIT
0052 if ispc
0053     % Define WSL paths
0054     wslPath.fastaFile=getWSLpath([tmpDIR filesep 'yeast_galactosidases.fa']);
0055     wslPath.outFile=getWSLpath(outFile);
0056     wslPath.cdhit=getWSLpath(fullfile(ravenPath,'software','cd-hit','cd-hit'));
0057     [~, ~]=system(['wsl "' wslPath.cdhit '" -T "' num2str(cores) '" -i "' wslPath.fastaFile '" -o "' wslPath.outFile '" -c 1.0 -n 5 -M 2000']);
0058 else
0059     [~, ~]=system(['"' fullfile(ravenPath,'software','cd-hit',['cd-hit' binEnd]) '" -T "' num2str(cores) '" -i "' fullfile(tmpDIR, 'yeast_galactosidases.fa') '" -o "' outFile '" -c 1.0 -n 5 -M 2000']);
0060 end
0061 
0062 %%
0063 %Open actual cdhit results file
0064 actCdhitOutput=importdata(fullfile(outFile));
0065 
0066 %Remove the old tempfiles
0067 delete([outFile '*']);
0068 
0069 %Remove temporary folder, since testing is finished
0070 [~, ~]=system(['rm "' tmpDIR '" -r']);
0071 
0072 %%
0073 %Check 1a: Check if files for CD-HIT results are the same
0074 verifyEqual(testCase,actCdhitOutput,expCdhitMafftOutput);
0075 
0076 %Check 1b: Change actual CD-HIT results file and check if test fails
0077 actCdhitOutput='abc';
0078 verifyNotEqual(testCase,actCdhitOutput,expCdhitMafftOutput);
0079 end

Generated by m2html © 2005