#!/usr/bin/perl use strict; use warnings; use File::Basename qw(basename); use Data::Dump qw(dump); use NEURO qw(populate check_subj load_study print_help achtung shit_done get_pair check_or_make); my $attach = 0; my $cfile; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-a/) { $attach = 1;} if (/^-cut/) { $cfile = shift; chomp($cfile);} if (/^-h/) { print_help $ENV{'PIPEDIR'}.'/doc/recon.hlp'; exit;} } my $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/recon.hlp'; exit;} my $debug = 1; my $max_processes = 24; my $max_gpu = 12; my $nodes = 3; my $stage = "-autorecon-all"; y %std = load_study($study); my $db = $std{'DATABASE'}; my $data_dir=$std{'DATA'}; #open debug file my $logfile = "$std{'DATA'}/.debug.controlled.log"; $debug ? open DBG, ">$logfile" :0; #open slurm file my $orderfile = "$std{'DATA'}/mri_orders.sh"; my $conffile = "$std{'DATA'}/mri_orders.conf"; my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); #get subjects from database or file my %plist; my %iplist = populate($db); if ($cfile){ my %cuts = get_pair($data_dir."/".$cfile); foreach my $cut (keys %cuts){ if(grep {/$cut/} %iplist){ $plist{$cut} = $iplist{$cut}; } } }else{ %plist = %iplist; } my @jobs_list; foreach my $pkey (sort keys %plist){ my $subj = $study."_".$plist{$pkey}.$pkey; my $care; my $gpu; if(check_subj($subj)){ $gpu = ""; #because it dont use gpu, YET! my $order = "recon-all ".$stage." -subjid ".$subj." ".$gpu; my $orderfile = $outdir.'/'.$subj.'fs_orders.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fs_recon_'.$subj."\n"; print ORD '#SBATCH --time=72: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.'/fs_recon-slurm-'.$subj.'-%j'."\n"; print ORD "srun $order\n"; close ORD; my $jobid = `sbatch $orderfile`; $jobid = ( split ' ', $jobid )[ -1 ]; push @jobs_list, $jobid; $debug ? print DBG "$order\n" :0; } } $debug ? close DBG:0; my $sjobs = join(',',@jobs_list); my $orderfile = $outdir.'/fs_recon_end.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fs_recon_end'."\n"; print ORD '#SBATCH -o '.$outdir.'/fs_recon_end-%j'."\n"; print ORD 'srun -w detritus '.$ENV{'PIPEDIR'}.'/bin/emailme.pl '.$study.' '.basename($ENV{_})."\n"; close ORD; my $order = 'sbatch --depend=afterany:'.$sjobs.' '.$orderfile; exec($order);