-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload_QC_data_for_pending_miseq_runs.pl
More file actions
executable file
·163 lines (142 loc) · 5.1 KB
/
upload_QC_data_for_pending_miseq_runs.pl
File metadata and controls
executable file
·163 lines (142 loc) · 5.1 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env perl
# Looks for runs ready to be processed and upload their interop QC data into the Oracle database.
use strict;
use warnings;
use File::Basename;
use File::Path qw(make_path remove_tree);
use FindBin 1.51 qw( $RealBin );
use lib $RealBin;
use Settings;
use lib 'modules';
use ExtractConanDateFromSamplesheet;
use UploadCorrectedIntensityMetrics;
use UploadErrorMetrics;
use UploadExtractionMetrics;
use UploadQualityMetrics;
use UploadRunParameters;
use UploadSummaryValues;
use UploadTileMetrics;
my $settings = new Settings();
my $miseq_data = $settings->{'raw_data_path'}; # Where to check MiSeq runs
my $write_folder = "upload_working"; # Local storage
my ( $needs_processing, $qc_complete, $qc_failure ) =
( 'needsprocessing', 'qc_uploaded', 'qc_failed_to_upload' );
# Write message to failure file, and complain to stdout.
sub failRun($$) {
my ($error_message, $error_file_name) = @_;
open( my $error_file, '>', $error_file_name )
or die "Could not open error file '$error_file_name'.";
print $error_file "$error_message\n";
my ($package, $filename, $line) = caller;
my $details = "Error occurred in $package:$filename line $line.";
print $error_file "$details\n";
close $error_file;
print "$error_message\n";
print "$details\n";
}
# Run several commands, and return 1 if they all succeed. If one fails,
# mark the run as failed and return 0.
sub runCommands($@) {
my ($qc_failure_file, @commands) = @_;
foreach my $command (@commands) {
if (system($command) != 0) {
die "Couldn't run '$command'.";
}
}
}
sub verifyInputFiles($$@) {
my ($qc_failure_file, $working_folder, @paths) = @_;
foreach my $subpath (@paths) {
if ( ! (-e "$working_folder/$subpath")) {
die "Input file '$working_folder/$subpath' not found.";
}
}
}
# Process all the data files for a run, die if anything goes wrong.
sub processRun($$$) {
my ($path, $write_folder, $dbh) = @_;
if ( !( -d "$path/InterOp" ) ) {
die "$path/InterOp not found."
}
my $new_folder = "$write_folder/" . basename($path);
make_path($new_folder);
remove_tree( $new_folder, { keep_root => 1 } );
# Copy the necessary files
runCommands(
"$path/$qc_failure",
"cp -r $path/InterOp $new_folder/",
"cp $path/SampleSheet.csv $new_folder/",
"cp $path/[rR]unParameters.xml $new_folder/runParameters.xml",
"cp $path/RunInfo.xml $new_folder/");
verifyInputFiles(
"$path/$qc_failure",
$new_folder,
"InterOp/CorrectedIntMetricsOut.bin",
"InterOp/ErrorMetricsOut.bin",
"InterOp/ExtractionMetricsOut.bin",
"InterOp/QMetricsOut.bin",
"InterOp/TileMetricsOut.bin");
# Get Conan's SampleSheet creator date, upload the QC data, link them to that date
my $samplesheet_date = getSampleSheetDate($new_folder);
my $RunID = uploadRunParameters(
"$new_folder/runParameters.xml",
$samplesheet_date,
$dbh );
uploadCorrectedIntensityMetrics(
$RunID,
"$new_folder/InterOp/CorrectedIntMetricsOut.bin",
$dbh);
uploadErrorMetrics(
$RunID,
"$new_folder/InterOp/ErrorMetricsOut.bin",
$dbh);
uploadExtractionMetrics(
$RunID,
"$new_folder/InterOp/ExtractionMetricsOut.bin",
$dbh);
uploadQualityMetrics($RunID, "$new_folder/InterOp/QMetricsOut.bin", $dbh);
uploadTileMetrics($RunID, "$new_folder/InterOp/TileMetricsOut.bin", $dbh);
uploadSummaryValues($RunID, $dbh);
}
my $success_count = 0;
my $failure_count = 0;
$ENV{ORACLE_HOME} = $settings->{'env_oracle_home'};
my $dbh=DBI->connect(
"dbi:Oracle:host=$settings->{'host'};service_name=$settings->{'sid'};port=$settings->{'port'}",
$settings->{'user'},
$settings->{'password'},
{RaiseError => 1, PrintError => 0, PrintWarn => 1, AutoCommit => 0});
my @glob = <$miseq_data/*>;
foreach my $path (@glob) {
if ( !( -d $path ) ) { next; } # For folders in macdatafile
if ( !( -e "$path/$needs_processing" ) ) {
next;
} # Which are marked for processing
if ( ( -e "$path/$qc_complete" ) || ( -e "$path/$qc_failure" ) ) {
next;
} # And has not already had QC uploaded
eval {
processRun($path, $write_folder, $dbh);
# If the upload was successful, write a qc_complete file flag on macdatafile
open( QC_PASSED, ">$path/$qc_complete" );
close(QC_PASSED);
$success_count += 1;
};
if ($@) {
my $error_message = $@;
print "Run $path failed: $error_message";
$failure_count += 1;
$dbh->rollback();
my $error_file_name = "$path/$qc_failure";
open( my $error_file, '>', $error_file_name )
or die "Could not open error file '$error_file_name'.";
print $error_file "$error_message\n";
close $error_file;
}
}
$dbh->disconnect();
my $summary = "Finished with $success_count successes and $failure_count failures.";
if ( $failure_count > 0 ) {
die $summary;
}
print $summary, "\n";