#!/usr/bin/perl # Copyright 2019 O. Sotolongo use strict; use warnings; use File::Find::Rule; use NEURO qw(print_help get_pair load_study achtung shit_done get_lut check_or_make centiloid_fbb); use Data::Dump qw(dump); use File::Remove 'remove'; use File::Basename qw(basename); my $ref_roi = "voi_WhlCbl_2mm.nii"; my $ctx_roi = "voi_ctx_2mm.nii"; my $roi_paths = $ENV{'PIPEDIR'}.'/lib/Centiloid_Std_VOI/nifti/2mm/'; my $withstd = 0; my $cfile; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile);} } my $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/pet_metrics.hlp'; exit;} my %std = load_study($study); my $w_dir=$std{'WORKING'}; my $data_dir=$std{'DATA'}; our %subjects; my @plist = find(file => 'name' => "*_fbb.nii.gz", '!name' => "*tmp*", in => $w_dir); my $ofile = $data_dir."/".$study."_fbb_cl.csv"; my $patt = '([A-Z,a-z]{1,4})(\d{1,6})_fbb'; my @pets; if ($cfile){ my %cuts = get_pair($data_dir."/".$cfile); foreach my $cut (keys %cuts){ if(grep {/$cut/} @plist){ $pets[$cut] = $plist[$cut]; } } }else{ @pets = @plist; } foreach my $pet (sort @pets){ (my $dg,my $subject) = $pet =~ /$patt/; if($subject){ $subjects{$subject}{'dg'} = $dg; $subjects{$subject}{'pet'} = $pet; } } my %sdata; foreach my $subject (sort keys %subjects){ my $care; my $norm; my $dg = $subjects{$subject}{'dg'}; # Apply masks to FBB my $roi_mask = $roi_paths.$ctx_roi; my $order = "fslstats ".$w_dir."/".$dg.$subject."_fbb_mni -k ".$roi_mask." -M"; my $ctx = qx/$order/; my $roi_mask = $roi_paths.$ctx_roi; $order = "fslstats ".$w_dir."/".$dg.$subject."_fbb_mni -k ".$roi_mask." -M"; print "$order\n"; my $norm = qx/$order/; $subjects{$subject}{$npf.'mean'} = $ctx/$norm; } open OF, ">$ofile"; print OF "Subject; SUVR; Centilod"; print OF "\n"; foreach my $subject (sort keys %subjects){ print OF "$subject"; my $mean = $subjects{$subject}{$npf.'mean'}; print OF ";$mean"; print OF ";", centiloid_fbb($mean); print OF "\n"; } close OF;