blib/lib/MS/Search/DB/Source/uniprot.pm

filter: Statementstmt 32.0% 16 / 50 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 1 totaltotal 24.1% 21 / 87 CC 14 SCAR 47.3
CC
14
Cov
21%
_fetch_fh
182.0
__ANON__
6.0
new
2.0
CRAP 113.6
« blib/script/cv2storable.pl ↑ Summary blib/lib/MS/Spectrum.pm »
1 package MS::Search::DB::Source::uniprot;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11  
12 0 ▶ my ($class, %args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 0 my $self = bless {%args} => $class;
15  
16 0 return $self;
17  
18 }
19  
20 sub _fetch_fh {
21  
22 0 ▶ my ($self) = @_;
Subroutine _fetch_fh: not called CC=13 SCAR=52.0
23  
24  
25 0 my ($rdr, $wtr) = FileHandle::pipe;
26 0 my $pid = fork;
27  
28 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
29  
30 0 close $wtr;
31 0 return($rdr, $pid);
32  
33 }
34 else {
35  
36 0 close $rdr;
37  
38 0 my @proteomes;
39  
40 0 ▶ if (defined $self->{proteome}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'proteome'}) { } 0 0 0
elsif (defined $self->{'taxid'} and not defined $self->{'proteome'}) { } 0 0 0
41 0 @proteomes = ($self->{proteome});
42 }
43 ▶ elsif (defined $self->{taxid} && ! defined $self->{proteome}) {
Condition0%0/3
defined $self->{"taxid"} and not defined $self->{"proteome"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"taxid"} and not defined $self->{"proteome"}
defined $self->{"taxid"} not defined $self->{"proteome"}
Truth table0%0/3
A and not(B)
A= defined $self->{"taxid"}B= not defined $self->{"proteome"}
ABresult
0X0
100
111
44 0 ▶ my $ref_only = $self->{ref_only} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ref_only'} ? : 0 0 0
45 0 ▶ my $top_node = $self->{taxid} // die "No taxon specified\n";
Condition0%0/2
$self->{"taxid"} // die("No taxon specified\n")
l!l
00
MC/DC0%0/1
$self->{"taxid"} // die("No taxon specified\n")
$self->{"taxid"}
Truth table0%0/2
A
A= $self->{"taxid"}
Aresult
11
00
46 0 ▶ die "Taxon must be NCBI integer ID\n" if ($top_node =~ /\D/);
Branch: 1 branch
BranchTrueFalseTotal
if $top_node =~ /\D/ 0 0 0
47  
48 #my $list_url = "http://www.uniprot.org/proteomes/?query=reference:$ref_only+taxonomy:$top_node&format=list";
49 0 my $list_url = "https://rest.uniprot.org/proteomes/stream?query=reference:$ref_only+taxonomy_id:$top_node&format=list";
50  
51 0 my $resp = HTTP::Tiny->new->get($list_url);
52 die "Failed to fetch proteome list: $resp->{status} $resp->{reason}\n"
53 0 ▶ if (! $resp->{success});
Branch: 1 branch
BranchTrueFalseTotal
unless $resp->{"success"} 0 0 0
54 0 @proteomes = split /\r?\n/, $resp->{content};
55 }
56 else {
57 0 die "No taxonomy ID or proteome ID given!\n";
58 }
59  
60 0 my $fasta;
61 my $want;
62 my $reviewed = $self->{reviewed_only}
63 0 ▶ ? '+AND+reviewed:true'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'reviewed_only'} ? : 0 0 0
64 : '';
65 my $include = $self->{include_isoforms}
66 0 ▶ ? 'yes'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'include_isoforms'} ? : 0 0 0
67 : 'no';
68 0 for (@proteomes) {
69 0 my $id = uri_escape($_);
70 0 warn "Fetching $id\n";
71 #my $fetch_url = "http://www.uniprot.org/uniprot/?query=proteome:$id$reviewed&include=$include&format=fasta";
72 0 my $fetch_url = "https://rest.uniprot.org/uniprotkb/stream?query=proteome:$id$reviewed&include=$include&format=fasta";
73 my $resp = HTTP::Tiny->new->get( $fetch_url, { data_callback
74 0 ▶ => sub { print {$wtr} $_[0] if ($_[1]->{status} < 300 ) } } );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]{"status"} < 300 0 0 0
75 die "Failed to fetch sequences for $_: $resp->{status} $resp->{reason}\n"
76 0 ▶ if (! $resp->{success});
Branch: 1 branch
BranchTrueFalseTotal
unless $resp->{"success"} 0 0 0
77 }
78 0 close $wtr;
79 0 exit;
80  
81 }
82  
83 }
84  
85 1 1;
86
87 __END__
« blib/script/cv2storable.pl ↑ Summary blib/lib/MS/Spectrum.pm »