Skip to content
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

Script to remove mnc file based on a query #172

Merged
merged 13 commits into from
Dec 19, 2016
94 changes: 94 additions & 0 deletions tools/deletemincandinsertfromtar.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'once';
use Data::Dumper;
use File::Basename;
use File::Copy;
use Term::ANSIColor qw(:constants);
use NeuroDB::DBI;

{ package Settings; do "$ENV{LORIS_CONFIG}/.loris_mri/prod" }
my $dbh = &NeuroDB::DBI::connect_to_db(@Settings::db);

# my $queryF = "SELECT f.SeriesUID, a.ArchiveLocation, SUBSTRING_INDEX(a.ArchiveLocation, '/', -1) as tarchive, ".
# "CASE WHEN t.SeriesDescription LIKE '%t1%' THEN 't1w' WHEN t.SeriesDescription LIKE '%t2%' THEN 't2w' END AS protocol FROM files AS f ".
# "LEFT JOIN tarchive_series AS t ON t.SeriesUID=f.SeriesUID LEFT JOIN tarchive AS a ON f.TarchiveSource=a.TarchiveID ".
# "where f.file LIKE '%dti%' AND (t.SeriesDescription LIKE '%t1%' OR t.SeriesDescription LIKE '%t2%') ".
# "AND f.SeriesUID NOT IN ('1.3.12.2.1107.5.2.32.35182.2008073113303686337017814.0.0.0','1.3.12.2.1107.5.2.43.67010.2015042819301841366299600.0.0.0') ".
# "ORDER BY f.FileID, t.SeriesDescription";

my $queryF = <<SQL;
SELECT DISTINCT
f.FileID, f.File, f.SeriesUID, t.ArchiveLocation, SUBSTRING_INDEX(t.ArchiveLocation, '/', -1) as tarchive
FROM files AS f
LEFT JOIN session s ON (f.SessionID=s.ID)
LEFT JOIN parameter_file AS pf USING (FileID)
LEFT JOIN files_qcstatus AS fq USING (FileID)
LEFT JOIN tarchive AS t ON f.TarchiveSource=t.TarchiveID
WHERE f.SeriesUID='1.3.12.2.1107.5.2.32.35177.2015072521545163128256406.0.0.0' or f.SeriesUID='1.3.12.2.1107.5.2.32.35177.2015072822492087585653675.0.0.0' and
((pf.ParameterTypeID=329 and pf.`VALUE` like '%acquisition:direction_x = 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gluneau

hardcoded ParameterTypeID and SeriesUID

or (pf.ParameterTypeID=329 and pf.`VALUE` like '%acquisition:direction_y = 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%')
or (pf.ParameterTypeID=329 and pf.`VALUE` like '%acquisition:direction_z = 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%')
or (pf.ParameterTypeID=333 and pf.`VALUE` like '%0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%')
or (pf.ParameterTypeID=334 and pf.`VALUE` like '%0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%')
or (pf.ParameterTypeID=343 and pf.`VALUE` like '%0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.%'))
ORDER BY f.FileID
SQL


my $sthF = $dbh->prepare($queryF);

my $keepgoing = 1;
my ($rF, $fF, $stdin, $i);

printf ("%-6s", '| L# ');
printf ("%-64s",'| SeriesUID');
printf ("%-36s",'| ArchiveLocation');
printf ("%-36s",'| CorrectLocation');

print "|\n";

$rF = $sthF->execute();

while ($fF = $sthF->fetchrow_hashref()) {

if ($sthF->rows > 0) {
$i++;

# copy("/data/not_backed_up/ibis_t1t2/backup/" . $fF->{'tarchive'}, "/data/not_backed_up/ibis_t1t2/");

my $minc_delete_cmd = "../uploadNeuroDB/minc_deletion.pl -profile prod -seriesuid " . $fF->{'SeriesUID'} . " confirm";
print $minc_delete_cmd . "\n";
my $minc_delete_log = `$minc_delete_cmd`;
print $minc_delete_log . "\n";

print "Press ENTER to continue:";
<STDIN>;

# -acquisition_protocol " . $fF->{'protocol'}
# -profile prod
# ../../../../" . $fF->{'ArchiveLocation'}
my $tar_loader_cmd = "../uploadNeuroDB/tarchiveLoader -profile null_grads -seriesuid " . $fF->{'SeriesUID'} .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gluneau

$profile instead of null_grads

" -verbose -globLocation " . $fF->{'ArchiveLocation'};

print $tar_loader_cmd . "\n";
my $tar_loader_log = `$tar_loader_cmd`;
print $tar_loader_log . "\n";

printf ("%-6s", '| '. $i);
printf ("%-64s",'| '. $fF->{'seriesuid'});
printf ("%-36s",'| '. $fF->{'ArchiveLocation'});
printf ("%-36s",'| '. $fF->{'tarchive'});
print "|\n";

if ($keepgoing) {
print "Press ENTER (or A and ENTER to do it all)\n";
$stdin = <STDIN>;
if ($stdin eq "A\n") {
print "Ok, I will keep going until it's done.\n";
$keepgoing = 0;
}
}
}
}
4 changes: 2 additions & 2 deletions uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ sub extract_tarchive {
$dcmdir =~ s/\.tar\.gz$//;

if (defined($seriesuid)) {
print "seriesuid: $seriesuid\n";
print "seriesuid: $seriesuid\n" if $this->{verbose};
my @alltarfiles = `cd $this->{TmpDir} ; tar -tzf $dcmtar`;
$tarnames = getFileNamesfromSeriesUID($seriesuid, @alltarfiles);
print "tarnames: $tarnames\n";
print "tarnames: $tarnames\n" if $this->{verbose};
}

`cd $this->{TmpDir} ; tar -xzf $dcmtar $tarnames`;
Expand Down
11 changes: 9 additions & 2 deletions uploadNeuroDB/minc_insertion.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
my $bypass_extra_file_checks=0;# If you need to bypass the extra_file_checks, set to 1.
my $acquisitionProtocol; # Specify the acquisition Protocol also bypasses the checks
my $acquisitionProtocolID; # acquisition Protocol id
my $seriesuid = undef; # if you are inserting a specific SeriesUID, the caveat flag will be set.
my @checks = (); # Initialise the array
my $create_minc_pics = 0; # Default is 0, set the option to overide.
my $globArchiveLocation = 0; # whether to use strict ArchiveLocation strings
Expand Down Expand Up @@ -100,7 +101,9 @@

["General options","section"],
["-verbose", "boolean", 1, \$verbose, "Be verbose."],


["-seriesuid", "boolean", 1, \$seriesuid, "Inserting by SeriesUID"],

["-acquisition_protocol","string", 1, \$acquisitionProtocol,
"Suggest the acquisition protocol to use."],

Expand Down Expand Up @@ -387,7 +390,11 @@
$file->setFileData('OutputType', 'native');
$file->setFileData('FileType', 'mnc');
$file->setFileData('TarchiveSource', $tarchiveInfo{'TarchiveID'});
$file->setFileData('Caveat', 0);
if (defined($seriesuid)) {
$file->setFileData('Caveat', 1);
} else {
$file->setFileData('Caveat', 0);
}

################################################################
## Get acquisition protocol (identify the volume) ##############
Expand Down
6 changes: 5 additions & 1 deletion uploadNeuroDB/tarchiveLoader
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ my $no_jiv = 0; # Should bet set to 1, if jivs should not be
# created
my $valid_study = 0;
my $newTarchiveLocation = undef;
my $seriesuid = ''; # if you want to insert a specific SeriesUID
my $seriesuid = undef; # if you want to insert a specific SeriesUID
my $bypass_extra_file_checks=0;# If you need to bypass the extra_file_checks, set to 1.
my $acquisitionProtocol; # Specify the acquisition Protocol also bypasses the checks
my @opt_table = (
Expand Down Expand Up @@ -452,6 +452,10 @@ foreach my $minc (@minc_files) {
$script .= " -verbose";
}

if ($seriesuid) {
$script .= " -seriesuid";
}

if ($acquisitionProtocol) {
$script .= " -acquisition_protocol " . $acquisitionProtocol;
}
Expand Down