Commit aae5ea8d authored by Aaron Petkau's avatar Aaron Petkau

Added support for multiple project identifiers

parent 3275684e
......@@ -12,7 +12,7 @@ use Time::Piece;
my $usage = <<"HELP";
Usage:
$0 [--help] --username USERNAME [--password PASSWORD] [--api-url URL] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--report FILENAME]
$0 [--help] --username USERNAME --project-id [PROJECT_ID] --reference-size [REFERENCE_SIZE] [--password PASSWORD] [--api-url URL] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--report FILENAME]
--help Print this message
--username Your IRIDA/NGS Archive username
......@@ -20,9 +20,19 @@ Usage:
--api-url The IRIDA API that you want to connect to (default: NML IRIDA)
--client-id The Client ID you were issued (default: NML IRIDA)
--client-secret The Client secret you were issued (default: NML IRIDA)
--project-id The particular project ID to check.
--project-id The particular project ID to check (can specify more than one).
--reference-size The reference genome size (in bp).
--report The filename you'd like to use for writing out the report (default: irida-report.tsv)
Example:
$0 --username user --reference-size 4000000 --project-id 1
Exports coverage values for the project with identifier 1 to the default file "irida-report.tsv", calculating minimum coverage using a reference genome size of 4,000,000 bp.
$0 --username user --reference-size 3500000 --project-id 3 --project-id 4 --report my-report.tsv
Exports coverage values for the projects 3 and 4 to the file "my-report.tsv", calculating minimum coverage using a reference genome size of 3,500,000 bp.
HELP
my $api = 'default';
......@@ -32,7 +42,7 @@ my $client_id = 'default';
my $client_secret = 'default';
my $report_name = "irida-report.tsv";
my $reference_size;
my $project_id;
my @project_ids;
my $help;
GetOptions(
......@@ -42,15 +52,15 @@ GetOptions(
'password=s' => \$password,
'client-id=s' => \$client_id,
'client-secret=s' => \$client_secret,
'project-id=i' => \$project_id,
'project-id=i' => \@project_ids,
'reference-size=i' => \$reference_size,
'report=s' => \$report_name );
my $oauth_token_url = "$api/oauth/token";
if ($help or not $username or not $project_id or not $reference_size) {
if ($help or not $username or not $reference_size or (@project_ids == 0)) {
print color('bold red');
print "--username is a required option.\n" if (not $username);
print "--project-id is a required option.\n" if (not $project_id);
print "--project-id is a required option.\n" if (@project_ids == 0);
print "--reference-size is a required option.\n" if (not $reference_size);
print color('reset');
print $usage;
......@@ -92,13 +102,11 @@ unless ($oauth_access_token) {
my $client = HTTP::Tiny->new( default_headers => {
'Authorization' => "Bearer $oauth_access_token" },
agent => "IRIDA Sample Searcher v1.0 ");
my @projects = ($project_id);
open my $report, '>', $report_name;
print $report "Project Name\tSample Name\tFile Pair\tMean Coverage\tTotal Bases\tReference Size\tProject ID\tSample ID\tFile Pair ID\n";
foreach my $project (@projects) {
my $project_url = "$api/projects/$project";
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'}};
......@@ -118,7 +126,7 @@ foreach my $project (@projects) {
$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]\n";
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) {
......
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