diff --git a/docs/scripts_md/batch_run_pipeline_qc_face_script.md b/docs/scripts_md/batch_run_pipeline_qc_face_script.md new file mode 100644 index 000000000..2019aa2ed --- /dev/null +++ b/docs/scripts_md/batch_run_pipeline_qc_face_script.md @@ -0,0 +1,33 @@ +# NAME + +batch\_run\_pipeline\_qc\_face\_script.pl -- Run `pipeline_qc_deface.pl` in batch mode + +# SYNOPSIS + +perl batch\_run\_pipeline\_qc\_face\_script.pl \[-profile file\] \[-out\_basedir directory\] < list\_of\_files.txt + +Available options are: + +\-profile: name of config file in ../dicom-archive/.loris\_mri (typically called prod) + +\-out\_basedir: path to the output base directory where the jpg will be created + +# DESCRIPTION + +This script creates the 3D rendering QC images on multiple MINC files. +The list of MINC files to use to generate those 3D JPEG images are provided +through a text file (e.g. `list_of_files.txt` with one file path per line). + +An example of what a `list_of_files.txt` might contain for 3 files to use to +create a 3D JPEG rendering of a scan to be defaced: + /data/project/data/assembly/123456/V01/mri/processed/MINC\_deface/project\_123456\_V01\_t1w\_001\_t1w-defaced\_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC\_deface/project\_123456\_V01\_t1w\_002\_t1w-defaced\_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC\_deface/project\_123456\_V01\_t2w\_001\_t2w-defaced\_001.mnc + +# LICENSING + +License: GPLv3 + +# AUTHORS + +LORIS community and McGill Centre for Integrative Neuroscience diff --git a/tools/batch_run_pipeline_qc_face_script.pl b/tools/batch_run_pipeline_qc_face_script.pl new file mode 100755 index 000000000..e444128ac --- /dev/null +++ b/tools/batch_run_pipeline_qc_face_script.pl @@ -0,0 +1,191 @@ +#!/usr/bin/perl -w + +=pod + +=head1 NAME + +batch_run_pipeline_qc_face_script.pl -- Run C in batch mode + +=head1 SYNOPSIS + +perl batch_run_pipeline_qc_face_script.pl [-profile file] [-out_basedir directory] < list_of_files.txt + +Available options are: + +-profile: name of config file in ../dicom-archive/.loris_mri (typically called prod) + +-out_basedir: path to the output base directory where the jpg will be created + +=head1 DESCRIPTION + +This script creates the 3D rendering QC images on multiple MINC files. +The list of MINC files to use to generate those 3D JPEG images are provided +through a text file (e.g. C with one file path per line). + +An example of what a C might contain for 3 files to use to +create a 3D JPEG rendering of a scan to be defaced: + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t1w_001_t1w-defaced_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t1w_002_t1w-defaced_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t2w_001_t2w-defaced_001.mnc + + +=head1 LICENSING + +License: GPLv3 + +=head1 AUTHORS + +LORIS community and McGill Centre for Integrative Neuroscience + +=cut + + +use strict; +use warnings; +no warnings 'once'; +use Getopt::Tabular; +use File::Basename; +use NeuroDB::DBI; +use NeuroDB::ExitCodes; + + + + +############################################################# +## Create the GetOpt table +############################################################# + +my $profile; +my $out_basedir; + +my @opt_table = ( + [ '-profile', 'string', 1, \$profile, 'name of config file in ../dicom-archive/.loris_mri' ], + [ '-out_basedir', 'string', 1, \$out_basedir, 'path to the output base directory where the jpg will be created' ] +); + +my $Help = < with one file path per line. + +An example of what a C might contain for 3 files to use to +create a 3D JPEG rendering of a scan to be defaced: + + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t1w_001_t1w-defaced_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t1w_002_t1w-defaced_001.mnc + /data/project/data/assembly/123456/V01/mri/processed/MINC_deface/project_123456_V01_t2w_001_t2w-defaced_001.mnc + +Documentation: perldoc batch_run_pipeline_qc_face_script.pl + +HELP + +my $Usage = <; + + + + +################################################################# +## Loop through all files to batch magic +################################################################# + +my $counter = 0; +my $stdoutbase = "$data_dir/batch_output/defaceqcstdout.log"; +my $stderrbase = "$data_dir/batch_output/defaceqcstderr.log"; + +foreach my $file_in (@files_list) { + chomp ($file_in); + + $counter++; + my $stdout = $stdoutbase.$counter; + my $stderr = $stderrbase.$counter; + my $file_out = $out_basedir . "/" . basename($file_in, ".mnc") . ".jpg"; + + my $command = sprintf( + "pipeline_qc_face.pl %s %s", + quotemeta($file_in), + quotemeta($file_out) + ); + + if ($is_qsub) { + open QSUB, " | qsub -V -S /bin/sh -e " . quotemeta($stderr) . " -o " . quotemeta($stdout) . " -N process_qc_deface_${counter}"; + print QSUB $command; + close QSUB; + } else { + system($command); + } +} + + +exit $NeuroDB::ExitCodes::SUCCESS; + + + + diff --git a/tools/mass_perldoc_md_creation.pl b/tools/mass_perldoc_md_creation.pl index 1deb11142..d9afa0f82 100644 --- a/tools/mass_perldoc_md_creation.pl +++ b/tools/mass_perldoc_md_creation.pl @@ -66,6 +66,7 @@ =head1 AUTHORS 'dicom-archive/updateMRI_Upload.pl', 'tools/BackPopulateSNRAndAcquisitionOrder.pl', 'tools/batch_run_defacing_script.pl', + 'tools/batch_run_pipeline_qc_face_script.pl', 'tools/create_nifti_bval_bvec.pl', 'tools/cleanupTarchives.pl', 'tools/cleanup_paths_of_violation_tables.pl', diff --git a/uploadNeuroDB/bin/pipeline_qc_face.pl b/uploadNeuroDB/bin/pipeline_qc_face.pl new file mode 100755 index 000000000..1c5eb0cc0 --- /dev/null +++ b/uploadNeuroDB/bin/pipeline_qc_face.pl @@ -0,0 +1,83 @@ +#!/usr/bin/env perl + +############################# MNI Header ##################################### +#@NAME : pipeline_qc_face.pl +#@DESCRIPTION: Create a QC image showing face of the subject +#@COPYRIGHT : +# Vladimir S. Fonov Dec, 2009 +# Montreal Neurological Institute, McGill University. +# Permission to use, copy, modify, and distribute this +# software and its documentation for any purpose and without +# fee is hereby granted, provided that the above copyright +# notice appear in all copies. The author and McGill University +# make no representations about the suitability of this +# software for any purpose. It is provided "as is" without +# express or implied warranty. +############################################################################### + +use strict; +use File::Basename; +use File::Temp qw/ tempfile tempdir /; +use File::Path; +use Getopt::Long; +use pipeline_functions; + +my $me = basename($0); +my $verbose = 0; +my $fake = 0; +my $clobber = 0; +my $keep_tmp=0; +my $stx_xfm; + +GetOptions( + 'verbose' => \$verbose, + 'fake' => \$fake, + 'clobber' => \$clobber, + 'stx=s' => \$stx_xfm +); + +die "Program usage: ${me} [--stx ]\n" unless $#ARGV == 1 ; + +my ($in,$out) = @ARGV; +my @files_to_add_to_db; + +check_file($out) unless $clobber; + +my $tmpdir = &tempdir( "$me-XXXXXXXX", TMPDIR => 1, CLEANUP => !$keep_tmp ); + +if($stx_xfm) +{ + do_cmd('make_face.pl',$in,"$tmpdir/face_1.miff",'--threshold',0.8,'--rotate',-10,'--stx',$stx_xfm); + do_cmd('make_face.pl',$in,"$tmpdir/face_2.miff",'--threshold',0.8,'--stx',$stx_xfm); + do_cmd('make_face.pl',$in,"$tmpdir/face_3.miff",'--threshold',0.8,'--rotate',10,'--stx',$stx_xfm); +} else { + do_cmd('make_face.pl',$in,"$tmpdir/face_1.miff",'--threshold',0.8,'--rotate',-10); + do_cmd('make_face.pl',$in,"$tmpdir/face_2.miff",'--threshold',0.8); + do_cmd('make_face.pl',$in,"$tmpdir/face_3.miff",'--threshold',0.8,'--rotate',10); +} + +my $geo=`identify -format "%wx%h" $tmpdir/face_2.miff`; +chomp($geo); +do_cmd('montage','-geometry',$geo,"$tmpdir/face_1.miff","$tmpdir/face_2.miff","$tmpdir/face_3.miff",$out); + + +@files_to_add_to_db = (@files_to_add_to_db, $out); +print("Files created:@files_to_add_to_db\n"); + + +#################################################################### +# do_cmd( arg1,argv2,.... ) +# +# execute given command +# +##################################################################### +sub do_cmd { + print STDOUT "@_\n" if $verbose; + if(!$fake){ + system(@_) == 0 or die "DIED: @_\n"; + } +} + +sub check_file { + die("${_[0]} exists!\n") if -e $_[0]; +}