-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_up_output_dirs.pl~
97 lines (50 loc) · 2.25 KB
/
clean_up_output_dirs.pl~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl
## because of the way mcverter works... I can only specific the output directory... not the name of the output files
## which makes sense as its designed to work on the output directories... so because of this I am going to iterate through
# the created output directories and clean things up
## basically just move the files contained in a directory
use File::Basename;
require 'braintumor_project_cleanup_functions.pl';
$DICOM_IMAGE_ROOT_DIR = "/IMAGING_SCRATCH/TCGA_DICOM_CACHE/TCGA_DATA/NIFTI_FILES/RAW_NIFTI_FILES/AXIAL-T1-PRE-GD/";
$DICOM_IMAGE_QA_DIR = $DICOM_IMAGE_ROOT_DIR . "MANUAL_QA/";
my @DIRS_TO_PROCESS = glob("${DICOM_IMAGE_ROOT_DIR}/*.nii.gz/*");
my %DIRECTORIES_SEEN; ## for some goofy reasons... sometimes a directory contains more than one nifti file... I need to mark these
my %DIRECTORIES_TO_MOVE_AND_ANALYZE ; ## These directories contain one or more files in it and need to be investigated
my %UNIQUE_SUBJECTS ;
check_directory_for_duplicate_patients( $DICOM_IMAGE_ROOT_DIR);
exit;
for($i=0;$i<=$#DIRS_TO_PROCESS;$i++)
{
#print $DIRS_TO_PROCESS[$i] ."\n";
my($filename,$directory) = fileparse($DIRS_TO_PROCESS[$i]);
if($DIRECTORIES_SEEN{$directory} ) {
print "this dir has two files... $directory \n";
$DIRECTORIES_TO_MOVE_AND_ANALYZE{$directory}++;
}
else { $DIRECTORIES_SEEN{$directory}++; }
}
foreach $dir_keys ( keys %DIRECTORIES_TO_MOVE_AND_ANALYZE )
{
print $DIRECTORIES_TO_MOVE_AND_ANALYZE{$dir_keys} . ";$dir_keys;\n";
$statement = "mv $dir_keys $DICOM_IMAGE_QA_DIR";
print $statement . "\n";
`$statement`;
}
### so if there are no duplicatels
my @FILES_TO_MOVE = glob("${DICOM_IMAGE_ROOT_DIR}*.nii.gz/*");
for($i=0;$i<=$#FILES_TO_MOVE;$i++)
{
print "I am going to move the file $FILES_TO_MOVE[$i] ... \n";
my($filename,$directory) = fileparse($FILES_TO_MOVE[$i]);
## the new filename is the actual directory name with .nii.gz on it.
@DIR_SPLIT = split(/\//,$directory);
$NEW_FILE_NAME = $DIR_SPLIT[($#DIR_SPLIT)];
$NEW_FILE_NAME =~ s/\.gz//;
print "New file name is $NEW_FILE_NAME \n";
$statement = "mv $FILES_TO_MOVE[$i] $DICOM_IMAGE_ROOT_DIR/$NEW_FILE_NAME";
print $statement."\n";
`$statement`;
$statement_two = "rmdir $directory";
print $statement_two . "\n";
`$statement_two`;
}