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

Icasso #294

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Icasso #294

wants to merge 21 commits into from

Conversation

bqrosen
Copy link

@bqrosen bqrosen commented Jun 6, 2024

I added icasso as a non-default optional method for estimating ICs in the IcaFix pipeline. After icasso is run, melodic is used for mixture modeling only and then FIX proceeds unchanged. It is currently only implemented for interpreted matlab mode. If hcp_fix_multi_run is called with --ica-method=ICASSO and {FSL_FIX_MATLAB_MODE} != 1, it will throw an error before starting the analysis.

Burke Rosen added 7 commits June 5, 2024 19:10
@bqrosen bqrosen requested review from coalsont and glasserm June 6, 2024 17:00
ICAFIX/hcp_fix_multi_run Outdated Show resolved Hide resolved
ICAFIX/hcp_fix_multi_run Outdated Show resolved Hide resolved
ICAFIX/hcp_fix_multi_run Outdated Show resolved Hide resolved
@bqrosen
Copy link
Author

bqrosen commented Jun 7, 2024 via email

ICAFIX/hcp_fix_multi_run Outdated Show resolved Hide resolved
[~,~] = unix(['mkdir -p ' outDir]);

%% load data, reshape to 2d, and apply brain mask
vnts = double(niftiread(vntsFile));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niftiread is not a function I am familiar with. I typically use FSL's read_avw and save_avw to avoid adding dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, read_avw comes from fsl, so it was a dependency we added. niftiread is apparently part of matlab's image toolbox, starting in 2017b. Octave-forge doesn't seem to have integrated it yet, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that. Perhaps could check if the function is present and fall back to read_avw/save_avw if not?

ts_spectra = nets_spectra_sp(ts);

% save A_final and spectra as tab-delimited text
dlmwrite([outDir '/melodic_Tmodes'], ts.ts, 'delimiter', '\t');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is melodic_Tmodes really the same as melodic_mix?


fid = fopen([outDir '/components.txt'],'w');
fprintf(fid,'%i: Signal\n',1:size(S_final,2));fclose(fid);
[~,~] = unix(['wb_command -cifti-create-scalar-series ' ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to do the same for the timeseries, right? PostFix may also already take care of both of these.

%% Mixture modeling
% follows recipe from https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=fsl;6e85d498.1607
fprintf('performing melodic mixture modeling ...\n')
[~,~] = unix(sprintf('melodic -i %s/melodic_IC --ICs=%s/melodic_IC --mix=%s/melodic_mix -o %s --Oall --report -v --mmthresh=0.5',...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming the contents of --mix doesn't matter, but this was my implementation to do mixture modelling on CIFTI data (perhaps that now works natively though?):

/media/myelin/brainmappers/HardDrives/2TBB/Connectome_Project/Pipelines/MixtureModelingRSN.sh

I also used a different --mmthresh=0.

Copy link
Contributor

@glasserm glasserm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my notes above. Also, I am not a bit fan of aggressive line continuations. They make code harder for me to read. Screens are not tiny any more...

@bqrosen
Copy link
Author

bqrosen commented Jun 10, 2024 via email

@bqrosen
Copy link
Author

bqrosen commented Jun 10, 2024 via email

@bqrosen
Copy link
Author

bqrosen commented Jun 11, 2024 via email

@bqrosen
Copy link
Author

bqrosen commented Jun 11, 2024 via email

@glasserm
Copy link
Contributor

Does that threshold the data?

Burke Rosen added 4 commits June 11, 2024 14:49
…D] line above last fastica call, improved comments
…into its own utility. Added the previously omitted fslmerge of mixture modeled component images. Removed zscore thresholding.
@@ -0,0 +1,92 @@
function mixtureModel(inFile,outFile,wbcmd,melocmd)
Copy link
Member

@coalsont coalsont Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be a bash script, I don't see any matrix math being done internally. Perhaps the only reason it is a matlab script is because the place you currently want to call it from is matlab code? Let's not use proprietary languages when there is a more obvious choice for the task.

Copy link
Author

@bqrosen bqrosen Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, though I would argue that it also makes it more easy to debug 🐛. It is designed to be called from matlab scripts because in most use cases (It is supposed to be a more general utility, not just a helper function for this run_icasso) its inputs will be created by a matlab script. Also, in the future an option could be added to feed it a matrix directly rather than a file path, which bash couldn't do. That said, a bash version would be good, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by "feed it a matrix" you mean "write that matrix to a file, run melodic, etc on it, and maybe read it back in later", I would still argue that the command sequence should be in a bash script, for more legibility, and potentially to be able to run the command sequence from a different script without having matlab/octave in the way. If you wanted it to look more matlabby, you could write a secondary matlab wrapper that writes a matrix to a file and runs the bash script. Unless a process actually uses matlab to do the math, I don't want its implementation to depend on matlab. The less matlab we use in the pipelines, the easier they are to maintain and use (compiled matlab, MCR version, etc).

log_Err_Abort "--ica-method=${ICAmethod} must be MELODIC or ICASSO"
;;
esac
if [[ ${FSL_FIX_MATLAB_MODE} == 0 ]] && [[ ${ICAmethod} == ICASSO ]];then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't think we want this type of check in the committed version. We can compile it as a final step before merging.

…un_icasso sub-functions, for mixtureModel made outFile argument mandatory
if nargin < 3 || isempty(wbcmd); wbcmd = 'wb_command'; end
if nargin < 4 || isempty(melocmd); melocmd = 'melodic'; end
[wbStat,~] = unix(wbcmd);
[meloStat,~] = unix(['which ' melocmd]);
[wbStat,~] = system(wbcmd);
Copy link
Member

@coalsont coalsont Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using which is probably a better idea than trusting that wb_command will never treat "no arguments, so print the help info" as an error condition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose -version would be fairly safe, and would also work on windows. But, as long as the melodic check uses which, might as well use the same approach for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants