error when using segment function

3 ビュー (過去 30 日間)
Emily
Emily 2025 年 1 月 19 日
回答済み: Gayathri 2025 年 5 月 6 日
I get these errors when running this snippet of code that references another script (script attached as a matlab file)
[filt_in, data_in_segs_corrected, segment_params]=segment_filt_v2(data_to_segment,[],[],params.genome_build);
params.segment_params=segment_params;
Warning: The data contains more columns (number of channels) than rows (number of samples). Check that the data is not transposed inadvertently.
> In ctrlMsgUtils.warning (line 25)
In segment (line 76)
In segment_filt_v2>seg_fun (line 145)
In segment_filt_v2 (line 101)
Unrecognized function or variable 'jmax'.
Error in segment (line 236)
hh=hist(:,jmax);
Error in segment_filt_v2>seg_fun (line 145)
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
Error in segment_filt_v2 (line 101)
data_in_segs_corrected{Chr}(in,c-4)=seg_fun(Data{Chr}(in,c), R2);
  5 件のコメント
Emily
Emily 2025 年 1 月 19 日
I had to subset this to be able to upload it, but it still gives the same error.
Mathieu NOE
Mathieu NOE 2025 年 1 月 21 日
with the provided code and files I have this error message :
Unrecognized function or variable 'last_autosome'.
Error in segment_filt_v2 (line 70)
s=cell2mat(Data(1:last_autosome(genome_build)));

サインインしてコメントする。

回答 (1 件)

Gayathri
Gayathri 2025 年 5 月 6 日
Hi @Emily,
I spent some time looking into the code, and I was able to face the same error as mentioned in your query.
The error is happening because for a certain case the data that goes into the "segment" function is a scalar. And when we try to retrieve the "size" of a scalar we get it as follows
And the function expects number of rows to be greater than columns, hence you receive the error mentioned.
I had modified the "seg_fun" function to identify the cause of the issue as shown below. You can also troubleshoot the issue by placing breakpoints in the "disp" command.
function data_out=seg_fun(data_in,R2)
% segment data
[tr1,tr2]=size([data_in,ones(length(data_in),1)]);
if tr1<=tr2
disp("error condition");
end
thm=segment([data_in,ones(length(data_in),1)],[0 1 1],R2); % function segment requires the System Identification Toolbox
thm=thm([1 1:end-1]); % correction: segment always results in a shift of 1 in the coordinates
% failed segmentation resulting in all NaNs: iteratively remove 5 data points at a time until resolved
nan=length(find(isnan(thm)));
iter=1;
while nan>length(thm)*0.9 % if most windows per region between gaps = NaN, remove additional 5 data points from beginning of region for each iteration
idx=5*iter;
% segment
[tr1,tr2]=size(data_in(idx+1:end));
if tr1<=tr2
disp("error condition");
end
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
thm=thm([1 1:end-1]); % correction: segment always results in a shift of 1 in the coordinates
thm=[NaN(idx,1); thm]; % add NaNs in the beginning
nan=length(find(isnan(thm))); % recount number of NaNs
iter=iter+1;
end
Pleaserefer to the screenshot below to get a better understand the cause of the issue.
For resolving the issue please refrain from calling the "segment" function when the data input is not in the required format.
And I also noticed that the data might be taken in different orders. Initially I faced the error around "sample 19, Chromosome 11", and next as shown in the screenshot.
I hope this helps in resolving the query. Please feel free to reach out in case of any queries. Thanks!

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by