-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch upload and insertion of scans for projects not using the front-end imaging uploader #133
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
083daa8
Batch upload of scans for projects not using the front-end imaging up…
MounaSafiHarab b1c9db0
added the missing file
MounaSafiHarab 4844e0c
prod not hard coded
MounaSafiHarab 868970e
fixed exit 4 error message
MounaSafiHarab 2753762
Feedback from Greg, Cecile to reorganize the order of the text file e…
MounaSafiHarab c141a08
removed debugging print statements
MounaSafiHarab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/perl -w | ||
use strict; | ||
use warnings; | ||
use File::Basename; | ||
use Getopt::Tabular; | ||
|
||
my $profile = undef; | ||
my ($debug, $verbose) = (0,1); | ||
my $stdout = ''; | ||
my $stderr = ''; | ||
|
||
my @opt_table = ( | ||
[ "Basic options", "section" ], | ||
[ | ||
"-profile", "string", 1, \$profile, | ||
"name of config file in ../dicom-archive/.loris_mri" | ||
], | ||
["-verbose", "boolean", 1, \$verbose, "Be verbose."] | ||
); | ||
|
||
&Getopt::Tabular::GetOptions( \@opt_table, \@ARGV ) || exit 1; | ||
|
||
#####Get config setting####################################################### | ||
{ package Settings; do "$ENV{LORIS_CONFIG}/.loris_mri/$profile" } | ||
############################################################################## | ||
|
||
my ($stdoutbase, $stderrbase) = ("$Settings::data_dir/batch_output/imuploadstdout.log", "$Settings::data_dir/batch_output/imuploadstderr.log"); | ||
|
||
|
||
|
||
while($_ = $ARGV[0], /^-/) { | ||
shift; | ||
last if /^--$/; ## -- ends argument processing | ||
if (/^-D/) { $debug++ } ## debug level | ||
if (/^-v/) { $verbose++ } ## verbosity | ||
} | ||
|
||
|
||
## read input from STDIN, store into array @inputs (`find ....... | this_script`) | ||
my @linearray = (); | ||
my @resultsarray = (); | ||
my @patientname = (); | ||
my @patientnamearray = (); | ||
my @fullpath = (); | ||
my @fullpatharray = (); | ||
my @phantom = (); | ||
my @phantomarray = (); | ||
my @submitted = (); | ||
|
||
my $counter = 0; | ||
|
||
while(my $line = <STDIN>) | ||
{ | ||
chomp $line; | ||
my @linearray = split(" " , $line); | ||
push (@resultsarray, @linearray); | ||
@patientname = $linearray[0]; | ||
@fullpath = $linearray[1]; | ||
@phantom = $linearray[2]; | ||
push (@patientnamearray, @patientname); | ||
push (@fullpatharray, @fullpath); | ||
push (@phantomarray, @phantom); | ||
} | ||
close STDIN; | ||
|
||
## foreach series, batch magic | ||
foreach my $input (@resultsarray) | ||
{ | ||
$counter++; | ||
$stdout = $stdoutbase.$counter; | ||
$stderr = $stderrbase.$counter; | ||
|
||
#$stdout = '/dev/null'; | ||
#$stderr = '/dev/null'; | ||
|
||
my $patientname = $patientnamearray[$counter-1]; | ||
my $fullpath = $fullpatharray[$counter-1]; | ||
my $phantom = $phantomarray[$counter-1]; | ||
|
||
## Ensure that | ||
## 1) the uploaded file is of type .tgz or .tar.gz or .zip | ||
## 2) the patient name and path entries are identical; this mimics the imaging uploader in the front-end | ||
## 3) check that input file provides phantom details (Y for phantom, N for real candidates) | ||
my ($base,$path,$type) = fileparse($fullpath, qr{\..*}); | ||
if (($type ne '.tgz') && ($type ne '.tar.gz') && ($type ne '.zip')) { | ||
print "The file on line $counter is not of type .tgz, tar.gz, or .zip and will not be processed\n"; | ||
exit(1); | ||
} | ||
if ($base ne $patientname) { | ||
print "Make sure the patient name $patientname " . | ||
"matches the file name $base in $path\n"; | ||
exit(2); | ||
} | ||
if (($phantom eq '') || ($phantom ne 'N') || ($phantom eq 'Y')) { | ||
print "Make sure the Phantom entry is filled out " . | ||
"with Y if the scan if for a phantom, and N otherwise\n"; | ||
exit(3); | ||
} | ||
|
||
## this is where the subprocesses are created... should basically run processor script with study directory as argument. | ||
## processor will do all the real magic | ||
|
||
my $command = "$Settings::bin_dir/uploadNeuroDB/imaging_upload_file.pl " | ||
. "-profile $profile -phantom $phantom -patient_name $patientname $fullpath"; | ||
if ($verbose) { | ||
$command .= " -verbose"; | ||
} | ||
|
||
##if qsub is enabled use it | ||
if ($Settings::is_qsub) { | ||
open QSUB, "| qsub -V -e $stderr -o $stdout -N process_imageuploader_${counter}"; | ||
print QSUB $command; | ||
close QSUB; | ||
} | ||
##if qsub is not enabled | ||
else { | ||
system($command); | ||
} | ||
|
||
push @submitted, $input; | ||
} | ||
open MAIL, "|mail $Settings::mail_user"; | ||
print MAIL "Subject: BATCH_UPLOADS_IMAGEUPLOADER: ".scalar(@submitted)." studies submitted.\n"; | ||
print MAIL join("\n", @submitted)."\n"; | ||
close MAIL; | ||
|
||
## exit 0 for find to consider this -cmd true (in case we ever run it that way...) | ||
exit(0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MounaSafiHarab If you modify your logic for this line to:
if (($phantom eq '') || (($phantom ne 'N') && ($phantom ne 'Y')))
the phantoms will get inserted.