#!/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; @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/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 = $data_dir.'/fmriprep_out'; 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-*/) { 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"; 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'."\n"; #print ORD 'srun fmriprep-docker '.$bids_dir.' '.$fmriout_dir.' --participant-label "'.$subject.'" --ignore slicetiming --skip_bids_validation --fs-license-file '.$fslic."\n"; close ORD; system("sbatch $orderfile"); sleep(20); } 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);