#!/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 $cpac_img = '/nas/software/cpac-latest.simg'; my $pipe_conf = 'cpac_pipeline_config.yml'; my $lib_conf = $ENV{'PIPEDIR'}.'/lib/'.$pipe_conf; my $cfile; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile);} if (/^-h$/) { print_help $ENV{'PIPEDIR'}.'/doc/cpac.hlp'; exit;} } my $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/cpac.hlp'; exit;} my %std = load_study($study); my $w_dir = $std{'WORKING'}; my $data_dir = $std{'DATA'}; my $bids_dir = $data_dir.'/bids'; my $fmriout_dir = $data_dir.'/cpac_out'; check_or_make($fmriout_dir); my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); my $tmpdir = "$std{'DATA'}/ctmp"; check_or_make($tmpdir); my $proj_conf = $data_dir.'/'.$pipe_conf; system("cp $lib_conf $proj_conf") unless (-e $proj_conf); my @subjects; if($cfile){ open DBF, $cfile or die "No such file\n"; while() { chomp; push @subjects, $_; } close DBF; }else{ opendir DBD, $bids_dir or die "Cold not open dir\n"; while (my $thing = readdir DBD){ if ($thing eq '.' or $thing eq '..') { next; } if ($thing =~ /sub-*/) { push @subjects, $thing; } } closedir DBD; } foreach my $subject (@subjects) { my $orderfile = $outdir.'/'.$subject.'_cpac.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J cpac_'.$study."\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 -o '.$outdir.'/cpac-%j'."\n"; print ORD '#SBATCH -c 20'."\n"; print ORD '#SBATCH -p fast'."\n"; print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; print ORD 'srun singularity run --cleanenv -B '.$data_dir.':/project -B '.$bids_dir.':/bids_dataset -B '.$fmriout_dir.':/outputs -B '.$tmpdir.':/scratch '.$cpac_img.' --pipeline_file /project/'.$pipe_conf.' /bids_dataset /outputs participant --participant_label '.$subject."\n"; close ORD; system("sbatch $orderfile"); sleep(20); } my $orderfile = $outdir.'/cpac_end.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J cpac_'.$study."\n"; print ORD '#SBATCH --mail-type=END'."\n"; #email cuando termine print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; print ORD '#SBATCH -p fast'."\n"; print ORD '#SBATCH -o '.$outdir.'/cpac_end-%j'."\n"; print ORD ":\n"; close ORD; my $order = 'sbatch --dependency=singleton '.$orderfile; exec($order);