Skip to content

Commit

Permalink
hypcomp new parameter for alignment/cut off until sleep onset
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik-D-Weber committed Mar 19, 2017
1 parent 1682488 commit 524ddad
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
3 changes: 2 additions & 1 deletion input/test_lindev/HypCompParam_lindev.txt
Expand Up @@ -17,4 +17,5 @@ GenerateHypnogramFiguresFormatHeight,4, choose format dimensions in n units stat
GenerateHypnogramFiguresFormatResolution,300, choose resolution in pixesl per inches (1 in=2.54 cm) of hypnograms. default 300
GenerateHypnogramFiguresFormatFontSize,0.2, Font size in units stated in Parameter GenerateHypnogramFiguresUnit. default 0.2
SleepOnsetDefinition,S1_XREM,either S1 or S1_NonREM or S1_XREM or NonREM or XREM. S1: starting with first S1 is sleep onset, nothing else. S1_NonREM: starting with first S1 if directly followed by either S2, S3 or S4, otherwise with first S2 or S3 or S4. S1_XREM: starting with first S1 if directly followed by either S2, S3, S4, or REM, otherwise with first S2 or S3 or S4 or REM. NonREM: starting with first one of S2, S3 or S4. XREM, starting with first one of S2, S3 or S4 or REM. default S1_XREM
HypnogramTimeTicks,20,the time ticks in minutes the hypnograms shall have in the Figure output
HypnogramTimeTicks,20,the time ticks in minutes the hypnograms shall have in the Figure output
AlignToSleepOnset,no,choose if the hypnograms should be aligned (cut) to the sleep onset either yes or no default no
73 changes: 72 additions & 1 deletion mainfunctions/spisop_hypcomp_l1.m
Expand Up @@ -69,6 +69,12 @@
referenceOption = getParam('referenceOption',listOfParameters);%which hypnogram should be chosen as a reference for comparison. either firstInList or consensushypnogram default firstInList
statisticsAlphaLevel = str2num(getParam('statisticsAlphaLevel',listOfParameters));%the alpha level for the statistics default 0.05

AlignToSleepOnset = 'no';
try
AlignToSleepOnset = getParam('AlignToSleepOnset',listOfParameters);%choose if the hypnograms should be aligned (cut) to the sleep onset either yes or no default no
catch e

end

core_cfg = [];
core_cfg.feedback = getParam('ft_cfg_feedback',listOfCoreParameters);
Expand Down Expand Up @@ -105,11 +111,76 @@
hypnogramPath = hypnogramListPaths{iHyp};

[hypn hypnStages hypnEpochs hypnEpochsBeginsSamples hypnEpochsEndsSamples] = readInSleepHypnogram(hypnogramPath,epochLengthSamples);


if strcmp(AlignToSleepOnset,'yes')


if strcmp(SleepOnsetDefinition,'NonREM')
onsetCandidate = -1;

for iOnset = 1:(size(hypnStages,1))
if strcmp(hypnStages(iOnset,3),'NonREM') && (hypnEpochsBeginsSamples(iOnset) >= lightsOffSample)
onsetCandidate = iOnset;
break;
end
end

elseif strcmp(SleepOnsetDefinition,'XREM')
onsetCandidate = -1;

for iOnset = 1:(size(hypnStages,1))
if (strcmp(hypnStages(iOnset,3),'NonREM') || strcmp(hypnStages(iOnset,3),'REM')) && (hypnEpochsBeginsSamples(iOnset) >= lightsOffSample)
onsetCandidate = iOnset;
break;
end
end

elseif strcmp(SleepOnsetDefinition,'S1') || strcmp(SleepOnsetDefinition,'S1_NonREM') || strcmp(SleepOnsetDefinition,'S1_XREM')

onsetCandidate = -1;
consecS1 = 0;
hasS1 = logical(0);
for iOnset = 1:(size(hypnStages,1))
if strcmp(hypnStages(iOnset,1),'S1') && (hypnEpochsBeginsSamples(iOnset) >= lightsOffSample)
hasS1 = logical(1);
consecS1 = consecS1 + 1;
if ((onsetCandidate+consecS1) ~= iOnset)
onsetCandidate = iOnset;
consecS1 = 0;
end
if strcmp(SleepOnsetDefinition,'S1')
break;
end
elseif ( strcmp(SleepOnsetDefinition,'S1_XREM') && (strcmp(hypnStages(iOnset,3),'NonREM') || strcmp(hypnStages(iOnset,3),'REM')) ) ...
|| ( strcmp(SleepOnsetDefinition,'S1_NonREM') && (strcmp(hypnStages(iOnset,3),'NonREM')) ) ...
&& (hypnEpochsBeginsSamples(iOnset) >= lightsOffSample)
if ~hasS1
onsetCandidate = iOnset;
end
break;
else
consecS1 = 0;
hasS1 = logical(0);
end
end

end



hypn = hypn(onsetCandidate:end,:);
hypnStages = hypnStages(onsetCandidate:end,:);
hypnEpochsBeginsSamples = hypnEpochsBeginsSamples(onsetCandidate:end,:);


end

hypnList{iHyp} = hypn;


if strcmp(GenerateHypnogramFigures,'yes')
fprintf('dataset %i: generat hypnogram figure of hypfile %d\n',iData,iHyp);
fprintf('dataset %i: generate hypnogram figure of hypfile %d\n',iData,iHyp);

titleName = sprintf('Hypnogram_datasetnum_%d_hypfile_%d',iData,iHyp);

Expand Down
3 changes: 2 additions & 1 deletion standard/infiles/FunctionParameters/HypCompParam.txt
Expand Up @@ -17,4 +17,5 @@ GenerateHypnogramFiguresFormatHeight,4, choose format dimensions in n units stat
GenerateHypnogramFiguresFormatResolution,300, choose resolution in pixesl per inches (1 in=2.54 cm) of hypnograms. default 300
GenerateHypnogramFiguresFormatFontSize,0.2, Font size in units stated in Parameter GenerateHypnogramFiguresUnit. default 0.2
SleepOnsetDefinition,S1_XREM,either S1 or S1_NonREM or S1_XREM or NonREM or XREM. S1: starting with first S1 is sleep onset, nothing else. S1_NonREM: starting with first S1 if directly followed by either S2, S3 or S4, otherwise with first S2 or S3 or S4. S1_XREM: starting with first S1 if directly followed by either S2, S3, S4, or REM, otherwise with first S2 or S3 or S4 or REM. NonREM: starting with first one of S2, S3 or S4. XREM, starting with first one of S2, S3 or S4 or REM. default S1_XREM
HypnogramTimeTicks,20,the time ticks in minutes the hypnograms shall have in the Figure output
HypnogramTimeTicks,20,the time ticks in minutes the hypnograms shall have in the Figure output
AlignToSleepOnset,no,choose if the hypnograms should be aligned (cut) to the sleep onset either yes or no default no

0 comments on commit 524ddad

Please sign in to comment.