hulketa has asked for the wisdom of the Perl Monks concerning the following question:
and I'd would like to parse each block and, if my position (in this case = 1200) is included in the block (that means that the position have to be < PEND and > PSTART)print the PDB_ID. In this case the script should print 2XB7. It'd be something like this. But it doesn't work and I think the problem is dereferencing arrays.[ { "PDBS": [ { "BLOCKS": [ { "PSTART": "1571", "PEND": "1589" } ], "PDB_CHAIN": "B", "PDB_TITLE": "Solution Structure of the Complex of the + PTB Domain of SNT-2 and 19-Residue Peptide (Aa 1571-1589) of HALK", "PDB_ID": "2KUP" }, { "BLOCKS": [ { "PSTART":"1095", "PEND":"1136" }, { "PSTART":"1144", "PEND":"1274" }, { "PSTART":"1289", "PEND":"1401" } ], "PDB_CHAIN":"A", "PDB_TITLE":"Structure of Human Anaplastic Lymphoma Ki +nase in Complex with Nvp-tae684", "PDB_ID":"2XB7" } ], "PROT_NAME": "ALK" } ]
Thank you so much!!my $json; { local $/; open my $fh, "<", "struc_cover_edu.json"; $json = <$fh>; close $fh; } my $data = JSON->new->decode($json); my $position = 1200; for my $s (@$data) { next unless $s->{PROT_NAME} eq 'ALK'; foreach my $p (0 .. $#{$s->{PDBS}}) { foreach my $b (0 .. $#{$s->{BLOCKS}}) { my @blocks = @{ $s->{BLOCKS}}; if ($position >= $blocks[$p][$b]{PSTART} && $position <= $ +blocks[$p][$b]{PEND} ){ print ($b->{PDB_ID},"\n");} } }}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: json data: dereferencing arrays
by hdb (Monsignor) on May 14, 2013 at 11:01 UTC | |
by hulketa (Initiate) on May 14, 2013 at 12:46 UTC | |
by hdb (Monsignor) on May 14, 2013 at 13:25 UTC | |
|
Re: json data: dereferencing arrays
by locked_user sundialsvc4 (Abbot) on May 14, 2013 at 13:31 UTC |