Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^7: string value assignment

by abidq (Initiate)
on May 14, 2011 at 16:29 UTC ( #904847=note: print w/replies, xml ) Need Help??


in reply to Re^6: string value assignment
in thread string value assignment

sorry i got asleep while solving now listen:
#!/usr/bin/perl $line=$ARGV[0]; #input file1 containing string list $name=$ARGV[1]; #output file, given at linux command chomp($line); chomp($name); $amino="ABC"; @cc=split(//,$amino); $line=~ s/[\s]//g; @prot=split(//,$line); $len=@prot; open(NAS,">>$name"); print NAS"0"; close NAS; open(MAJ,"valfile"); #input file 2 containing values while($li=<MAJ>){ chomp($li); $val=""; @value=split(/ +/,$li); for($p=0;$p<@prot;$p++){ for($a=0;$a<@cc;$a++){ if($prot[$p] eq "$cc[$a]"){ $val +=$value[$a]; } } $val1=$val/$len; $val1=sprintf "%5.3f",$val1; } $number++; open(MAL,">>$name"); print MAL" $number:$val1"; close MAL; } close MAJ; open(MAL1,">>$name"); print MAL1"\n"; close MAL1;

this code finely processes the string but only line 1 ;your job is to make it take all lines of string LIKE THE WAY IT TAKES ALL LINES FROM VALUES (input file 2 ) FILE. also go through my original question where instructions/pseudo code is given

Replies are listed 'Best First'.
Re^8: string value assignment
by marinersk (Priest) on May 14, 2011 at 20:20 UTC

    edit: Okay, I'm an idiot. One of the filenames is hard-coded in the script. But we're still stumbling over the idea that there are two input files, and the script only opens one. So I'll leave the rest of this message intact, to show what an idiot I was in making up two new filenames instead of just the one which is actually missing.

    Okay, so I've entered your data into two input files just like it says in the first message:

    -----( Begin file1.txt )-----
    BCA 
    
    CA 
    
    ACBAA 
    
    -----( End file1.txt )-----
    -----( Begin file2.txt )-----
    1 2 3 
    
    11 22 33 
    
    -----( End file2.txt )-----
    

    I don't know why you have the extra blank lines in the files, but you showed them that way in the original message, so that's how I've entered them.

    Now I run your script:

    C:\Steve\Projects\PerlMonks\AminoSplit>perl amino.pl file1.txt outfile.txt
    
    C:\Steve\Projects\PerlMonks\AminoSplit>dir
    
     Volume in drive C is CBoot
     Volume Serial Number is B4AB-1A65
    
     Directory of C:\Steve\Projects\PerlMonks\AminoSplit
    
    05/14/2011  02:12 PM    <DIR>          .
    05/14/2011  02:12 PM    <DIR>          ..
    05/14/2011  02:10 PM                 0 $Notes.txt
    05/14/2011  02:08 PM               870 amino.pl
    04/15/2010  11:16 AM               107 ci.cfg
    05/14/2011  06:29 AM                39 doit.bat
    05/14/2011  02:09 PM                25 file1.txt
    05/14/2011  02:10 PM                23 file2.txt
    05/14/2011  02:08 PM    <DIR>          new
    05/14/2011  02:08 PM    <DIR>          old
    05/14/2011  02:12 PM                 3 outfile.txt
                   7 File(s)          1,067 bytes
                   4 Dir(s)   3,317,903,360 bytes free
    

    And I notice it's written outfile.txt just like we would expect. Its contents do not look anything like your original message suggested it would look like.

    -----( Begin outfile.txt )-----
    0
    -----( End outfile.txt )-----
    

    You claim this works for one line.

    This does not look like what I would expect.

    I say again, I do not see anywhere in your Perl script where you are attempting to read the input file. In fact, all you seem to be doing is reading the input filename and acting on its name.

    I presume you'd actually like to process its contents. I can help you with that, but I need to know where in your script you are expecting to do so.

      Dear marinersk

      I am a new bioinformatics fellow and have little programming skills. All I want to say is that the problem is perfectly explained in my original question.It would be very encouraging if you write the code from scratch keeping in view my original question.

      Note (Optional):In reality the strings are 'peptides' and the alphabets are 'amino acids' and the values are their different 'physico-chemical properties'.

      The output file in the format i have requested is actually the format for SVM(Support Vector Machine) which takes the output file as input for training.i then train the SVM so that it can differentiate between different classes of peptides.

        I can't even run YOUR code based on your first message. I wouldn't know where to begin writing something from scratch, as I have no understanding of what you are trying to accomplish.

        And, as has been previously noted, PerlMonks is not a code-writing service. You may not be a software engineer, but you seem pretty bright in your field and apparently you need to use Perl to get something done.

        I'm glad to help you, but I can't do your job for you. I lack the knowledge of your profession.

        Please help me understand and I will be glad to help you.

        Perhaps we need to take a different approach. You seem to think you've told me everything you need in the first message. Using that information, I can't even get the same results you do in your Perl script.

        So let's take a different approach. Please post your exact command line when you run your Perl script so I can see what you're doing. Also please post results. Just like I did in my previous message.

        Show me what you typed and what results you got, and maybe we can bridge this gap in our understanding.

        Unfortunately, my wife is demanding I come to bed now, so I will be unable to respond for many hours.

        Looking forward to your reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://904847]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-07-23 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (461 votes). Check out past polls.

    Notices?