#!/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 $wcut = 0; my $cfile; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile); $wcut = 1;} if (/^-h$/) { print_help $ENV{'PIPEDIR'}.'/doc/pet_metrics.hlp'; exit;} } 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'}; my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); 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; } } foreach my $subject (sort keys %subjects){ my $norm; my $dg = $subjects{$subject}{'dg'}; my $subj = $dg.$subject; #Making sbatch scripts # Get FBB image into MNI space my $order = $ENV{'PIPEDIR'}."/bin/fbb2std.sh ".$subj." ".$w_dir; my $orderfile = $outdir.'/'.$subj.'_fbb_reg.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fbb2std_'.$study."\n"; print ORD '#SBATCH --time=4:0:0'."\n"; #si no ha terminado en X horas matalo print ORD '#SBATCH --mail-type=FAIL,TIME_LIMIT,STAGE_OUT'."\n"; #no quieres que te mande email de todo print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; print ORD '#SBATCH -o '.$outdir.'/fbb2std-'.$subj.'-%j'."\n"; print ORD "srun $order\n"; close ORD; system("sbatch $orderfile"); } my $order = $ENV{'PIPEDIR'}."/bin/fbb_cl_masks.pl ".$study." ".($wcut?"-cut $cfile":""); my $orderfile = $outdir.'/fbb_masks.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fbb2std_'.$study."\n"; print ORD '#SBATCH --time=24:0:0'."\n"; #si no ha terminado en X horas matalo print ORD '#SBATCH --mail-type=FAIL,END'."\n"; #email cuando termine o falle print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; print ORD '#SBATCH -o '.$outdir.'/fbbmasks-%j'."\n"; print ORD "srun $order\n"; close ORD; my $xorder = 'sbatch --dependency=singleton'.' '.$orderfile; exec($xorder);