#!/usr/bin/perl use strict; use warnings; use File::Find::Rule; use NEURO qw(print_help get_pair load_study achtung shit_done); use Data::Dump qw(dump); use File::Basename qw(basename); my $attach = 1; my $with_sd = 0; my $threshold = 0.25; #my $atlas; my $net_path; #my $netwstr; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-l/) { $attach = 0;} #if (/^-uofm/) {$atlas="uofm"; $network = shift; chomp($network); $netwstr = $network; $network =~ s/\_/\//g;} if (/^-thr/) {$threshold = shift;} if (/^-path/) {$net_path = shift;} if (/^-sd/) { $with_sd = 1;} if (/^-h/) { print_help $ENV{'PIPEDIR'}.'/doc/dti_metrics.hlp'; exit;} } my $study = shift; $net_path = "out" unless $net_path; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/dti_metrics.hlp'; exit;} my %std = load_study($study); my $w_dir=$std{'WORKING'}; my $data_dir=$std{'DATA'}; my @dti_fas = find(file => 'name' => "*_dti_FA.nii.gz", in => $w_dir); my %csv; my $ofile = $data_dir."/".$study."_dti_".$net_path.".csv"; open OF, ">$ofile"; print OF "Subject"; if($with_sd){ print OF ";$net_path","_FA_Mean;","$net_path","_FA_STD",";$net_path","_MD_Mean;","$net_path","_MD_STD"; }else{ print OF ";$net_path","_FA",";$net_path","_MD"; } print OF "\n"; foreach my $dti (sort @dti_fas){ (my $a,my $subject) = $dti =~ /(\w{1,4})(\d{1,6})_dti_FA/; my $tmpmd = $w_dir.'/'.$a.$subject."_dti_MD"; if($subject){ print OF "$subject"; my $img_path = $w_dir.'/'.$a.$subject.'_probtrack_'.$net_path.'/fdt_paths.nii.gz'; my $order = $ENV{'PIPEDIR'}.'/bin/track2mask.sh '.$img_path.' '.$threshold; print "$order\n"; system($order); my $mask_path = $w_dir.'/'.$a.$subject.'_probtrack_'.$net_path.'/fdt_paths_mask.nii.gz'; $order = "fslstats ".$dti." -k ".$mask_path." -M -S"; print "$order\n"; (my $mean, my $std) = map{/(\d+\.\d*)\s*(\d+\.\d*)/} qx/$order/; if($with_sd){ print OF ";$mean",";$std"; }else{ print OF ";$mean"; } $order = "fslstats ".$tmpmd." -k ".$mask_path." -M -S"; print "$order\n"; ($mean, $std) = map{/(\d+\.\d*)\s*(\d+\.\d*)/} qx/$order/; if($with_sd){ print OF ";$mean",";$std"; }else{ print OF ";$mean"; } } print OF "\n"; } close OF; my $zfile = $ofile.'.gz'; system("gzip -c $ofile > $zfile"); if ($attach){ shit_done basename($ENV{_}), $study, $zfile; }else{ achtung basename($ENV{_}), $ofile, $study; }