#!/usr/bin/perl # Copyright 2019 O. Sotolongo # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # use strict; use warnings; use File::Find::Rule; use NEURO4 qw(print_help load_project shit_done cut_shit check_subj check_or_make); use Data::Dump qw(dump); use File::Remove 'remove'; use File::Basename qw(basename); use File::Copy::Recursive qw(dircopy); my $fslic = '/nas/usr/local/opt/freesurfer/.license'; my $fmriprep_version = '1.5.6'; my $cfile=""; #my $fs = 0; my $st = 0; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile);} # if (/^-fs/) { $fs = 1}; if (/^-st/) {$st = 1}; if (/^-h$/) { print_help $ENV{'PIPEDIR'}.'/doc/dfmriprep.hlp'; exit;} } my $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/dfmriprep.hlp'; exit;} my %std = load_project($study); my $w_dir = $std{'WORKING'}; my $data_dir = $std{'DATA'}; my $bids_dir = $std{'BIDS'}; my $fsdir = $ENV{'SUBJECTS_DIR'}; my $db = $std{'DATA'}.'/'.$study.'_mri.csv'; my $fmriout_dir = $data_dir.'/fmriprep_out'; my $fssubsdir = $fmriout_dir.'/freesurfer'; my $noslicetiming; if($st){ $noslicetiming = ""; }else{ $noslicetiming = "--ignore slicetiming"; } check_or_make($fmriout_dir); check_or_make($fssubsdir); my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); my @subjects = cut_shit($db, $data_dir."/".$cfile); foreach my $subject (@subjects) { my %nifti = check_subj($std{'DATA'},$subject); if($nifti{'func'}){ my $fssd = $fssubsdir.'/sub-'.$subject; my $rfssd = $fsdir.'/'.$study.'_'.$subject; check_or_make($fssd); dircopy($rfssd,$fssd); 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 -t -d --rm -v '.$fslic.':/opt/freesurfer/license.txt:ro -v '.$bids_dir.'/sub-'.$subject.':/data:ro -v '.$fmriout_dir.':/out poldracklab/fmriprep:'.$fmriprep_version.' /data /out participant --participant-label '.$subject.' '.$noslicetiming.' --skip_bids_validation --fs-subjects-dir out/freesurfer'; 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);