Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't have any sample data to work with, and I might be wrong, but even if I am, perhaps you will get some new ideas...

I think the problem starts with how the CSA_hash is built. You have 3 values: $pdb,$chain,$res that are concatenated together to form one key and the value of that key is always 1. That is all well and good if the main thing is that this combination of things is only counted once. Maybe you need to do that, I don't know. BUT later on in the most performance critical part of the code, what you really want to know is what $res's correspond to the $pdb,$chain combination. So another idea for CSA_hash, would be like this:

die "some usage error msg" if (@ARGV !=2); my ($domFile,$csafile)= @ARGV; open(CSAFILE, "$csafile") or die "unable to open $csafile: $!"; my %csa_hash; my %dom_hash; my $domain_dir = "<my directory>"; while(<CSAFILE>) { chomp; s/\s+//g; #keep things simple, delete spaces my ($pdb,$chain,$res) = (split(/,/, $_))[0,3,4]; push (@{$csa_hash{"$pdb;$chain"}},$res}); }
This is a HoL, Hash of List. Maybe there can be duplicate $res values for each "$pdb;$chain" combo? I don't know. If there are, then it is not hard to fix that.

Where all of this is headed is to the 3rd loop level:

while ((my $key, my $value) = each(%csa_hash)) {....}
note that $value here is irrelevant (it is always 1). %csa_hash is being used like a list NOT a hash! This is actually the worst possible case of a search: it is linear and it always access all N items in the list. If there are a lot of keys in %csa_hash, this will bog things down quite a bit! I think this is a very key statement:

if("$domchain" eq "$pdbchain"){....}
This $domchain is a function of just the stuff that was used to create the csa_hash! Or actually the modified version above. A hash is a horrible thing to waste...or so the saying goes... So I recommend created the csa_hash with keys that are easy for the inner most loop to access. This routine is going to get "hit a lot", but you want fast answer, not a N*keys(csa_hash) answer.

One thing that I think is noteworthy is that if a string can work in a print statement, it will work as a hash key, eg. $somehash{"$pdb;$chain"}= $res; If the ";" is not a valid value inside of the $parm vars, then this works great. If you have a multi-value key, you can do a split on ";".

hope this helps.


In reply to Re: Why is my program so slow even though I've used hashes? by Marshall
in thread Why is my program so slow even though I've used hashes? by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-29 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found