Commit 90f68d8a authored by Aaron Petkau's avatar Aaron Petkau

Stopped from producing incomplete file on error.

parent 0898e9c2
......@@ -115,69 +115,77 @@ $report_worksheet->set_column('A:A',30);
$report_worksheet->set_column('B:H',15);
$report_worksheet->set_column('I:I',60);
my $row = 1;
foreach my $project_id (@project_ids) {
my $project_url = "$api/projects/$project_id";
my $project_info = Parse::CPAN::Meta->load_json_string(
$client->get($project_url)->{'content'})->{'resource'};
my ($samples_link) = grep { $_->{'rel'} eq 'project/samples' } @{$project_info->{'links'}};
my $samples = Parse::CPAN::Meta->load_json_string(
$client->get($samples_link->{'href'})->{'content'})->{'resource'}->{'resources'};
foreach my $sample (@{$samples}) {
my ($files_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles' } @{$sample->{'links'}};
my $files = Parse::CPAN::Meta->load_json_string(
$client->get($files_link->{'href'})->{'content'})->{'resource'};
my ($pairs_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles/pairs' } @{$files->{'links'}};
my ($unpaired_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles/unpaired' } @{$files->{'links'}};
my $pairs = Parse::CPAN::Meta->load_json_string(
$client->get($pairs_link->{'href'})->{'content'})->{'resource'}->{'resources'};
my $unpaired_list = Parse::CPAN::Meta->load_json_string(
$client->get($unpaired_link->{'href'})->{'content'})->{'resource'}->{'resources'};
for my $unpaired (@$unpaired_list) {
print STDERR "Skipping unpaired sequence file [id=$unpaired->{'identifier'}, label=$unpaired->{'label'}] in sample [id=$sample->{'identifier'}, name=$sample->{'sampleName'}], project [id=$project_id]\n";
}
foreach my $sequence_file_pair (@$pairs) {
my ($forward_link) = grep { $_->{'rel'} eq 'pair/forward' } @{$sequence_file_pair->{'links'}};
my ($reverse_link) = grep { $_->{'rel'} eq 'pair/reverse' } @{$sequence_file_pair->{'links'}};
try {
my $row = 1;
foreach my $project_id (@project_ids) {
my $project_url = "$api/projects/$project_id";
my $project_info = Parse::CPAN::Meta->load_json_string(
$client->get($project_url)->{'content'})->{'resource'};
my ($samples_link) = grep { $_->{'rel'} eq 'project/samples' } @{$project_info->{'links'}};
my $samples = Parse::CPAN::Meta->load_json_string(
$client->get($samples_link->{'href'})->{'content'})->{'resource'}->{'resources'};
my $forward = Parse::CPAN::Meta->load_json_string(
$client->get($forward_link->{'href'})->{'content'})->{'resource'};
my $reverse = Parse::CPAN::Meta->load_json_string(
$client->get($reverse_link->{'href'})->{'content'})->{'resource'};
foreach my $sample (@{$samples}) {
my ($files_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles' } @{$sample->{'links'}};
my $files = Parse::CPAN::Meta->load_json_string(
$client->get($files_link->{'href'})->{'content'})->{'resource'};
my ($pairs_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles/pairs' } @{$files->{'links'}};
my ($unpaired_link) = grep { $_->{'rel'} eq 'sample/sequenceFiles/unpaired' } @{$files->{'links'}};
my $pairs = Parse::CPAN::Meta->load_json_string(
$client->get($pairs_link->{'href'})->{'content'})->{'resource'}->{'resources'};
my ($forward_qc_link) = grep { $_->{'rel'} eq 'sequencefile/qc' } @{$forward->{'links'}};
my ($reverse_qc_link) = grep { $_->{'rel'} eq 'sequencefile/qc' } @{$reverse->{'links'}};
my $unpaired_list = Parse::CPAN::Meta->load_json_string(
$client->get($unpaired_link->{'href'})->{'content'})->{'resource'}->{'resources'};
my $forward_qc;
my $reverse_qc;
my $skip = 0;
try {
$forward_qc = Parse::CPAN::Meta->load_json_string(
$client->get($forward_qc_link->{'href'})->{'content'})->{'resource'};
$reverse_qc = Parse::CPAN::Meta->load_json_string(
$client->get($reverse_qc_link->{'href'})->{'content'})->{'resource'};
} catch {
warn "invalid fastqc results for sample=$sample->{'sampleName'}, sequence_file_id=$sequence_file_pair->{'identifier'}, sequence_file_label=$sequence_file_pair->{'label'}. Will skip these files.";
$skip=1;
};
if (not $skip) {
my $total_bases = $forward_qc->{'totalBases'} + $reverse_qc->{'totalBases'};
my $coverage = sprintf "%0.0f",($total_bases/$reference_size);
for my $unpaired (@$unpaired_list) {
print STDERR "Skipping unpaired sequence file [id=$unpaired->{'identifier'}, label=$unpaired->{'label'}] in sample [id=$sample->{'identifier'}, name=$sample->{'sampleName'}], project [id=$project_id]\n";
}
my $project_date = localtime($project_info->{'createdDate'}/1000)->strftime('%F %T');
my $sample_date = localtime($sample->{'createdDate'}/1000)->strftime('%F %T');
my $sample_updated_date = localtime($sample->{'modifiedDate'}/1000)->strftime('%F %T');
my $file_pair_label = $sequence_file_pair->{'label'};
$report_worksheet->write_row($row,0,[$project_info->{'name'},$sample->{'sampleName'},$coverage,$total_bases,$reference_size,$project_info->{'identifier'},$sample->{'identifier'},$sequence_file_pair->{'identifier'},$file_pair_label]);
$row++;
foreach my $sequence_file_pair (@$pairs) {
my ($forward_link) = grep { $_->{'rel'} eq 'pair/forward' } @{$sequence_file_pair->{'links'}};
my ($reverse_link) = grep { $_->{'rel'} eq 'pair/reverse' } @{$sequence_file_pair->{'links'}};
my $forward = Parse::CPAN::Meta->load_json_string(
$client->get($forward_link->{'href'})->{'content'})->{'resource'};
my $reverse = Parse::CPAN::Meta->load_json_string(
$client->get($reverse_link->{'href'})->{'content'})->{'resource'};
my ($forward_qc_link) = grep { $_->{'rel'} eq 'sequencefile/qc' } @{$forward->{'links'}};
my ($reverse_qc_link) = grep { $_->{'rel'} eq 'sequencefile/qc' } @{$reverse->{'links'}};
my $forward_qc;
my $reverse_qc;
my $skip = 0;
try {
$forward_qc = Parse::CPAN::Meta->load_json_string(
$client->get($forward_qc_link->{'href'})->{'content'})->{'resource'};
$reverse_qc = Parse::CPAN::Meta->load_json_string(
$client->get($reverse_qc_link->{'href'})->{'content'})->{'resource'};
} catch {
warn "invalid fastqc results for sample=$sample->{'sampleName'}, sequence_file_id=$sequence_file_pair->{'identifier'}, sequence_file_label=$sequence_file_pair->{'label'}. Will skip these files.";
$skip=1;
};
if (not $skip) {
my $total_bases = $forward_qc->{'totalBases'} + $reverse_qc->{'totalBases'};
my $coverage = sprintf "%0.0f",($total_bases/$reference_size);
my $project_date = localtime($project_info->{'createdDate'}/1000)->strftime('%F %T');
my $sample_date = localtime($sample->{'createdDate'}/1000)->strftime('%F %T');
my $sample_updated_date = localtime($sample->{'modifiedDate'}/1000)->strftime('%F %T');
my $file_pair_label = $sequence_file_pair->{'label'};
$report_worksheet->write_row($row,0,[$project_info->{'name'},$sample->{'sampleName'},$coverage,$total_bases,$reference_size,$project_info->{'identifier'},$sample->{'identifier'},$sequence_file_pair->{'identifier'},$file_pair_label]);
$row++;
}
}
}
}
}
} catch {
unlink($report_name);
die "Error occured: $_";
};
$report_workbook->close();
print "Finished writing report to $report_name\n";
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment