Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 5e0f836

Browse files
committed
perl cleint
1 parent d514829 commit 5e0f836

37 files changed

+10671
-0
lines changed

client/perl/HFCuS-client.pl

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
use lib 'lib';
5+
6+
use Getopt::Long;
7+
use File::Basename;
8+
9+
# load the API package
10+
use WWW::SwaggerClient::ApiFactory;
11+
12+
# load the models used
13+
use WWW::SwaggerClient::Object::HFCurationResponse;
14+
use WWW::SwaggerClient::Object::HFCurationRequest;
15+
use WWW::SwaggerClient::Object::License;
16+
17+
# for displaying the API response data
18+
use Data::Dumper;
19+
20+
#--- options and arguments:
21+
22+
my $opt_help;
23+
my $opt_verbose = 0;
24+
my $action = "";
25+
my $submission_id;
26+
27+
my $prg = basename($0);
28+
29+
if (
30+
!&GetOptions(
31+
"help" => \$opt_help,
32+
"verbose!" => \$opt_verbose, # -verbose, -noverbose
33+
"action=s" => \$action,
34+
"sub=s" => \$submission_id,
35+
)
36+
)
37+
{
38+
print "\n$prg: wrong option\n";
39+
exit 1;
40+
}
41+
42+
if ($opt_help) {
43+
&help;
44+
exit 0;
45+
}
46+
47+
print "$prg: $action\n" if $opt_verbose;
48+
49+
if ( $action !~ /(get_sub|get_all|push)/i ) {
50+
print "\n$prg: wrong action $action\n";
51+
exit 1;
52+
}
53+
54+
if ( $action =~ /get_sub/i && !$submission_id ) {
55+
print "\n$prg: Submission ID missing for action $action\n";
56+
exit 1;
57+
}
58+
my $base = "http://hfcus.b12x.org:8080";
59+
60+
my $api_instance = WWW::SwaggerClient::DefaultApi->new();
61+
$api_instance->{api_client}->{base_url} = $base;
62+
$api_instance->{api_client}->{ua}->env_proxy;
63+
print Dumper($api_instance) if $opt_verbose;
64+
65+
if ( $action eq "get_sub" ) {
66+
&get_haplotypes( $api_instance, $submission_id );
67+
}
68+
elsif ( $action eq "push" ) {
69+
my $file;
70+
if ( @ARGV == 1 ) {
71+
$file = $ARGV[0];
72+
}
73+
else {
74+
print "\n$prg: hfr file missing for action $action\n";
75+
exit 1;
76+
}
77+
&push_haplotypes( $api_instance, $file );
78+
}
79+
elsif ( $action eq "get_all" ) {
80+
&get_all_submissions($api_instance);
81+
}
82+
else {
83+
print "\n$prg: wrong action $action\n";
84+
exit 1;
85+
}
86+
exit 0;
87+
88+
# end of main
89+
90+
sub push_haplotypes {
91+
92+
my ( $api_instance, $file ) = @_;
93+
94+
my $HFCurReq = WWW::SwaggerClient::Object::HFCurationRequest->new();
95+
my $HapFreqData =
96+
WWW::SwaggerClient::Object::HaplotypeFrequencyData->new();
97+
my $PopData = WWW::SwaggerClient::Object::PopulationData->new();
98+
my $Lic = WWW::SwaggerClient::Object::License->new();
99+
my $ResInfo = WWW::SwaggerClient::Object::ResolutionInfo->new();
100+
101+
print Dumper($HapFreqData) if $opt_verbose;
102+
# $PopData->{id} = "1";
103+
$PopData->{name} = "US-CAU";
104+
$Lic->{type_of_license} = "CC0";
105+
$ResInfo->{resolution} = "4-Field";
106+
$HapFreqData->{license} = $Lic;
107+
$HapFreqData->{resolution_data}->[0] = $ResInfo;
108+
109+
open( HFR, $file ) || die "$prg: Cannot open file $file: $!";
110+
my $i = 0;
111+
while (<HFR>) {
112+
chomp;
113+
my ( $hap, $hf ) = split /,/;
114+
my $HapFreq = WWW::SwaggerClient::Object::HaplotypeFrequency->new();
115+
$HapFreq->{haplotype_string} = $hap;
116+
$HapFreq->{frequency} = $hf;
117+
$HapFreqData->{haplotype_frequency_list}->[$i] = $HapFreq;
118+
$i++;
119+
}
120+
121+
close HFR;
122+
123+
$HFCurReq->{population_id} = "1";
124+
# $HFCurReq->{population_data} = $PopData;
125+
$HFCurReq->{haplotype_frequency_data} = $HapFreqData;
126+
my $response = $api_instance->hfc_post( hf_curation_request => $HFCurReq );
127+
128+
print "$0: Submission $response->{submission_id}\n";
129+
130+
}
131+
132+
sub get_haplotypes {
133+
my ( $api_instance, $submission_id ) = @_;
134+
eval {
135+
my $haplotypes = $api_instance->hfc_submission_id_haplotypes_get(
136+
submission_id => $submission_id );
137+
print Dumper($haplotypes);
138+
};
139+
140+
if ($@) {
141+
warn
142+
"Exception when calling DefaultApi->hfc_submission_id_haplotypes_get: $@\n";
143+
}
144+
} # end sub get_haplotypes
145+
146+
sub get_all_submissions {
147+
148+
my ($api_instance) = @_;
149+
150+
eval {
151+
my $result = $api_instance->hfc_get();
152+
print Dumper($result);
153+
};
154+
if ($@) {
155+
warn "Exception when calling DefaultApi->hfc_get: $@\n";
156+
}
157+
} # end of get_all_submissions
158+
159+
#=============================================================================
160+
sub help {
161+
#-----------------------------------------------------------------------------
162+
# Called by: MAIN
163+
# Purpose: show help
164+
# Arguments: none
165+
# Returns: nothing
166+
# ToDo:
167+
# Remarks:
168+
#-----------------------------------------------------------------------------
169+
170+
my $def_v = $opt_verbose ? "-- verbose" : "-- noverbose";
171+
172+
print << "__END_OF_HELP__";
173+
174+
Name
175+
$prg
176+
Purpose
177+
Client for HFCuS
178+
Syntax
179+
$prg [--help]
180+
$prg [--verbose] action=[get|push]
181+
Options and arguments
182+
--help show this help
183+
--[no]verbose set verbose mode; default: $def_v
184+
--action get_sub: getting HF set by submission ID -sub <submission_id>
185+
push: push HF set <file>
186+
get_all: get all submissions
187+
The action push requires a file with HF data as argument.
188+
__END_OF_HELP__
189+
190+
return;
191+
192+
} # end sub help()
193+
#=============================================================================
194+
195+
# end of file
196+

client/perl/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ```HFCuS-client.pl```
2+
3+
Haplotype Frequency Curation Service
4+
Perl Client
5+
6+
7+
8+
# Requirements
9+
- Module::Find
10+
- URI::Query
11+
- Log::Any
12+
- Module::Runtime
13+
- Class::Singleton
14+
- Date::Parse
15+
- DateTime
16+
- Moose::Role

0 commit comments

Comments
 (0)