Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

pdb spliting

by abhi4.amity
on Feb 02, 2013 at 10:12 UTC ( #1016692=perlquestion: print w/replies, xml ) Need Help??
abhi4.amity has asked for the wisdom of the Perl Monks concerning the following question:

How can i split pdb file into two parts.plz give me some hints or code.

#!/usr/bin/perl -w use strict; use warnings; my $line; my @pdb; my @arr; my $count=0; open(FH,"2FGI(1).pdb"); @pdb=<FH>; foreach $line (@pdb){ $count++; } @arr= splice(@pdb,$count/2); print @arr,"\n"; open(WRITE,">out.pdb"); print WRITE "@arr"; @arr= splice(@pdb,$count/10); print @arr,"\n"; open(WRITE,">out1.pdb"); print WRITE "@arr";
IS THIS code is correct for pdb spliting.

Replies are listed 'Best First'.
Re: pdb spliting
by ww (Archbishop) on Feb 02, 2013 at 13:22 UTC
    This response directs itself to your second question.

    Your code passes a syntax check... that is to say, my Perl (5.016) detects no syntax errors.

    However, your code suffers from several shortcomings:

    • The "-w" and "use warnings:" are effectively duplicative, in this particular code (ie, where you are not using an external package or module and, thus, where -w's additional effect does NOT propagate to that other code).
    • You are not checking the outcome of your open(...)s. That's a practice that's almost certain to bite you (and, "HARD!").
      1. Instead, you should include a or die "Can't open... $!;" clause that will alert you if your open fails for some reason.
      2. Better yet, use three-argument opens: adopt the above, the use of "<" for read or ">" for writes (BTW, there are other options) and use of a lexical filehandle
        execute perldoc -f open from your OS' command line for details and examples
    • Your "close" commands seems to have fallen out of your code. This, too, can BITE!

    Turning to your post, itself:

    I know -- off the top of my head -- of at least three diffent ways that the file extension ".pdb" is used -- Palm dbs, C++ debugging, and "Protein Data Bank" data. You really should specify as it's unreasonable to expect the Monks will be able, magicly, to infer which you mean.

    And, returning to your second question ("(i)s THIS code is correct...." (sic)) that's easy enough to determine pragmatically: Try it to see. Somehow, I suspect that's not your real question, but, again, you can't expect magic inferences about your actual intent.

Re: pdb spliting
by 2teez (Vicar) on Feb 02, 2013 at 12:09 UTC

    Hi abhi4.amity,
    ..plz give me some hints or code.

    People are really willing and ready to help you achieve your desired aim, if only you will show what you have done and how you are having problems making your program work.
    Asking people to come up with scripts to solve a problem for you is not it.
    Please check How do I post a question effectively?

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: pdb spliting
by baxy77bax (Deacon) on Feb 02, 2013 at 12:56 UTC
    Well it would be nice if you could use code tags when posting your code. Also since here programmers with various backgrounds are posting and reading, a bit more elaboration on pdb file format would be nice, maybe even an example.
    Q: When you say pdb are you referring to protein data bank format, or a program database file?
    In any case splitting the file depends on entry format. For example if you want to split a fasta formated file that contains several entries, then you will not be splitting it by rows but by entries. Also if the number of entries is odd then you have to decide how will you deal with that.


Re: pdb spliting (search)
by Anonymous Monk on Feb 02, 2013 at 10:18 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1016692]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-03-18 18:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.