#!/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 $fslic = '/nas/usr/local/opt/freesurfer/.license'; my $cfile; my $fs = 1; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile);} if (/^-nofs/) { $fs = 0}; if (/^-h$/) { print_help $ENV{'PIPEDIR'}.'/doc/cfmriprep.hlp'; exit;} } my $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/cfmriprep.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; my $nofscall; if($fs){ $fmriout_dir = $data_dir.'/fmriprep_out'; $nofscall = "\n"; }else{ $fmriout_dir = $data_dir.'/fmriprep_nofs_out'; $nofscall = " --fs-no-reconall\n"; } check_or_make($fmriout_dir); my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); 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-*/ && (-e "$bids_dir/$thing/func" && -d "$bids_dir/$thing/func")) { push @subjects, $thing; } } closedir DBD; } foreach my $subject (@subjects) { my $orderfile = $outdir.'/'.$subject.'_fmriprep.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fmriprep_'.$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.'/fmriprep-%j'."\n"; print ORD '#SBATCH -c 20'."\n"; print ORD '#SBATCH -p fast'."\n"; print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; #docker run --rm -it -e DOCKER_VERSION_8395080871=19.03.5 -v /nas/usr/local/opt/freesurfer/.license:/opt/freesurfer/license.txt:ro -v /nas/data/mopead/bids:/data:ro -v /nas/data/mopead/fmriprep_out:/out poldracklab/fmriprep:1.5.0 /data /out participant --participant-label sub-0001 --ignore slicetiming --skip_bids_validation print ORD 'srun docker run --rm -v '.$fslic.':/opt/freesurfer/license.txt:ro -v '.$bids_dir.':/data:ro -v '.$fmriout_dir.':/out poldracklab/fmriprep:1.5.0 /data /out participant --participant-label '.$subject.' --ignore slicetiming --skip_bids_validation'.$nofscall; close ORD; system("sbatch $orderfile"); sleep(2); } my $orderfile = $outdir.'/fmriprep_end.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J fmriprep_'.$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.'/fmriprep_end-%j'."\n"; print ORD ":\n"; close ORD; my $order = 'sbatch --dependency=singleton '.$orderfile; exec($order);