CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
XPath expressions

 



clinton
Novice

Feb 17, 2006, 4:05 PM

Post #1 of 5 (836 views)
XPath expressions Can't Post

Hi everyone,

I need help forming an XPath expression.

Here's my XML document:

<!DOCTYPE BlastOutput PUBLIC "-//NCBI//NCBI BlastOutput/EN" "NCBI_BlastOutput.dtd">
<BlastOutput>
<BlastOutput_program>blastx</BlastOutput_program>
<BlastOutput_version>blastx 2.2.12 [Aug-07-2005]</BlastOutput_version>
<BlastOutput_db>allMicrobes</BlastOutput_db>
<BlastOutput_query-ID>lcl|QUERY</BlastOutput_query-ID>
<BlastOutput_query-def>558_5_589_5</BlastOutput_query-def>
<BlastOutput_query-len>4009</BlastOutput_query-len>
<BlastOutput_iterations>
<Iteration>
<Iteration_iter-num>1</Iteration_iter-num>
<Iteration_hits>
<Hit>
<Hit_num>1</Hit_num>
<Hit_id>gi|16079139|ref|NP_389962.1|</Hit_id>
<Hit_def>hypothetical protein BSU20800 [Bacillus subtilis subsp. subtilis str. 168]</Hit_def>
<Hit_accession>NP_389962</Hit_accession>
<Hit_len>460</Hit_len>
<Hit_hsps>
<Hsp>
<Hsp_num>1</Hsp_num>
<Hsp_bit-score>197.978</Hsp_bit-score>
<Hsp_score>502</Hsp_score>
<Hsp_evalue>5.29415e-49</Hsp_evalue>
<Hsp_query-from>1952</Hsp_query-from>
<Hsp_query-to>4008</Hsp_query-to>
<Hsp_hit-from>130</Hsp_hit-from>
<Hsp_hit-to>460</Hsp_hit-to>
<Hsp_query-frame>-2</Hsp_query-frame>
<Hsp_identity>116</Hsp_identity>
<Hsp_positive>195</Hsp_positive>
<Hsp_gaps>15</Hsp_gaps>
<Hsp_align-len>334</Hsp_align-len>
</Hsp>
</Hit_hsps>
</Hit>
<Hit>
<Hit_num>2</Hit_num>
<Hit_id>gi|57867511|ref|YP_189165.1|</Hit_id>
<Hit_def>hypothetical protein SERP1600 [Staphylococcus epidermidis RP62A]</Hit_def>
<Hit_accession>YP_189165</Hit_accession>
<Hit_len>426</Hit_len>
<Hit_hsps>
<Hsp>
<Hsp_num>1</Hsp_num>
<Hsp_bit-score>114.39</Hsp_bit-score>
<Hsp_score>285</Hsp_score>
<Hsp_evalue>7.69811e-24</Hsp_evalue>
<Hsp_query-from>3217</Hsp_query-from>
<Hsp_query-to>3999</Hsp_query-to>
<Hsp_hit-from>128</Hsp_hit-from>
<Hsp_hit-to>378</Hsp_hit-to>
<Hsp_query-frame>-2</Hsp_query-frame>
<Hsp_identity>83</Hsp_identity>
<Hsp_positive>140</Hsp_positive>
<Hsp_gaps>3</Hsp_gaps>
<Hsp_align-len>264</Hsp_align-len>
</Hsp>
</Hit_hsps>
</Hit>
</Iteration_hits>
</Iteration>
</BlastOutput_iterations>
</BlastOutput>

What I need is an expression that will return Hit_num's where Hsp_query-from <= 2000 AND Hsp_query-to >= 2000

I've read several tutorials but none of them offer such a complex situation. All my attempts have proven unsuccessful.

As you can see, Hit_num 1 should be returned.

Thanks for your help!


KevinR
Veteran


Feb 17, 2006, 5:03 PM

Post #2 of 5 (835 views)
Re: [clinton] XPath expressions [In reply to] Can't Post

what have you tried so far?
-------------------------------------------------


clinton
Novice

Feb 17, 2006, 5:09 PM

Post #3 of 5 (833 views)
Re: [KevinR] XPath expressions [In reply to] Can't Post

Ummm, quite a few things. Here's some examples:


Code
my $nodeset = $xpath->find("//Hit_num[Hit_hsps/Hsp/Hsp_query-from<=2000][Hit_hsps/Hsp/Hsp_query-from>=2000]");



Code
my $nodeset = $xpath->find("//Hit_num[Hsp_query-from<=2000 and following-sibling::*/text()>=2100]");



Code
my $nodeset = $xpath->find("//Hit_num[Hsp_query-from<=2000] | //Hit_num[Hsp_query-to>=2100]");


Although I have found that even


Code
my $nodeset = $xpath->find("//Hit_num[Hit_hsps/Hsp/Hsp_query-from<=2000]");


will return Hit_num 2 when it shouldn't (Hsp_query-from = 3217)


KevinR
Veteran


Feb 17, 2006, 10:06 PM

Post #4 of 5 (830 views)
Re: [clinton] XPath expressions [In reply to] Can't Post

sorry if I seem a bit lame, does Xpath have something to do with Perl?
-------------------------------------------------


clinton
Novice

Feb 22, 2006, 2:13 PM

Post #5 of 5 (799 views)
Re: [KevinR] XPath expressions [In reply to] Can't Post

Yes.

Well, sort of.

XPath is an XML... extension(?) that allows you to traverse XML documents.

Perl has a module that implements XPath.

My question strictly speaking, isn't a Perl question; it's an XPath question. But, since I'm using it in Perl i thought some Perlites may have some suggestions.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives