#!/usr/bin/perl use strict; use warnings; use File::Slurp qw(read_file); use File::Find::Rule; use File::Basename qw(basename); use Data::Dump qw(dump); use File::Copy::Recursive qw(dirmove); use NEURO qw(populate check_subj load_study print_help get_pair check_or_make); my $study; my $cfile; my $debug=1; my $corr=1; my $legacy=0; my $cuda=1; my $atlas=0; my $mode=0; my $s2t=0; my $network; @ARGV = ("-h") unless @ARGV; while (@ARGV and $ARGV[0] =~ /^-/) { $_ = shift; last if /^--$/; if (/^-cut/) { $cfile = shift; chomp($cfile);} if (/^-slow/) {$cuda=0;} if (/^-single/) {$mode=1;} if (/^-s2t/) {$s2t=1;} if (/^-uofm/) {$atlas="uofm"; $network = shift; chomp($network); $network =~ s/\_/\//g;} if (/^-h/) { print_help $ENV{'PIPEDIR'}.'/doc/dti_reg.hlp'; exit;} } $study = shift; unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/dti_reg.hlp'; exit;} my %std = load_study($study); my $subj_dir = $ENV{'SUBJECTS_DIR'}; my $pipe_dir = $ENV{'PIPEDIR'}; # Redirect ouput to logfile (do it only when everything is fine) my $logfile = "$std{'DATA'}/.debug_dti_tracks.log"; open STDOUT, ">$logfile" or die "Can't redirect stdout"; open STDERR, ">&STDOUT" or die "Can't dup stdout"; $debug ? open DBG, ">$logfile" :0; #Run this script ONLY on "Detritus" #or change the paths to the correct ones my $w_dir=$std{'WORKING'}; my $dti_dir=$std{'DTI'}; my $mri_dir=$std{'MRI'}; my $db = $std{'DATABASE'}; my $data_dir=$std{'DATA'}; #open slurm file #my $orderfile = "$std{'DATA'}/dti_track_orders.sh"; #my $conffile = "$std{'DATA'}/dti_track_orders.conf"; my $outdir = "$std{'DATA'}/slurm"; check_or_make($outdir); #my $jobname = "track_$study"; my %plist = populate($db); my @ok_dtis; print "Collecting needed files\n"; my %dtis; if ($cfile){ my %cuts = get_pair($data_dir."/".$cfile); foreach my $cut (keys %cuts){ if(grep {/$cut/} %plist){ $dtis{$cut} = $plist{$cut}; } } }else{ %dtis = %plist; } #open CNF, ">$conffile"; #my $count = 0; foreach my $subject (sort keys %dtis){ #Compulsory: el DTI debe haber pasado el preproc my $dti_fa = $w_dir.'/'.$dtis{$subject}.$subject.'_dti_FA.nii.gz'; print "$dti_fa\n"; #Compulsory: Necesito tambien la segmentacion de freesurfer de este pollo my $aseg = $subj_dir.'/'.$study.'_'.$dtis{$subject}.$subject.'/mri/aseg.mgz'; print "$aseg\n"; if((-e $dti_fa) && (-e $aseg)){ my $order; unless($atlas){ if($cuda){ if($s2t){ $order = $pipe_dir."/bin/dti_bedtrack_seek.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir; }else{ #$order = $count."\t".$pipe_dir."/bin/dti_bedtrack_cuda.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir; $order = $pipe_dir."/bin/dti_bedtrack_cuda.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir." ".$mode; }else{ #$order = $count."\t".$pipe_dir."/bin/dti_bedtrack.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir; $order = $pipe_dir."/bin/dti_bedtrack.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir." ".$mode; } } }else{ if($s2t){ $order = $pipe_dir."/bin/dti_bedtrack_seek.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir." ".$pipe_dir."/lib/".$atlas; }else{ $order = $pipe_dir."/bin/dti_bedtrack_nodes.sh ".$study." ".$dtis{$subject}.$subject." ".$w_dir." ".$pipe_dir."/lib/".$atlas."/".$network." ".$mode; } } #$count++; #print CNF "$order\n"; my $orderfile = $outdir.'/'.$subject.'dti_orders.sh'; open ORD, ">$orderfile"; print ORD '#!/bin/bash'."\n"; print ORD '#SBATCH -J dti_track_'.$subject."\n"; print ORD '#SBATCH --time=1: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.'/dti_track-slurm-%j'."\n"; if($cuda){ print ORD '#SBATCH -p cuda'."\n";} print ORD "srun $order\n"; close ORD; my $pid = fork(); if ($pid == 0){ exec("sbatch $orderfile"); } elsif (!defined($pid)){ die "could not fork"; } $debug ? print DBG "$order\n" :0; } } #close CNF; #open ORD, ">$orderfile"; #print ORD '#!/bin/bash'."\n"; #print ORD '#SBATCH --time=0'."\n"; #print ORD '#SBATCH -J '.$track_study."\n"; #print ORD '#SBATCH -n '.$count."\n"; #print ORD '#SBATCH -o '.$outdir.'/dti_track-slurm-%j'."\n"; #print ORD '#SBATCH --mail-type=ALL'."\n"; #print ORD '#SBATCH --mail-user='."$ENV{'USER'}\n"; #if($cuda){print ORD '#SBATCH -p cuda'."\n";} #print ORD "srun --exclusive --multi-prog ".$conffile."\n"; #close ORD; $debug ? close DBG:0; #exec("sbatch -o $w_dir/dti_track.out $orderfile");