Reading a protein sequence from file

Discussion in 'Perl' started by tejaminnu, May 30, 2011.

  1. tejaminnu

    tejaminnu New Member

    Joined:
    May 30, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have been trying to execute this program and i am getting an error. Kindly help me.

    #!usr/bin/perl -w

    # The filename of the file which contains the protein sequence
    $proteinfilename = '/users/sukeerthiteja/desktop/perl/NM_021964fragment.pep';

    # First open the file and associate a filehandle with it. for readability purpose lets use the filehandle PROTEINFILE.
    open(PROTEINFILE, $proteinfilename);

    # Now we do the actual reading of the protein sequence data from the file,by using < > to get
    # input from the filehandle. We store the data into variable $protein
    $protein = <PROTEINFILE>;

    #now that we got our data we can close the file
    close PROTEINFILE;

    #Print the protein onto the screen
    print "Here is the protein:\n\n";

    print $protein;

    exit;



    ERROR:

    sukeerthi-tejas-macbook-pro:desktop sukeerthiteja$ perl 1.pl
    Here is the protein:

    {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350


    I am not able to print the protein content on the screen.
    Is this a problem with me of first properly putting things in my directory.

    Email: tejaminnu@gmail.com

    Thank you
    Regards
    Teja
     
  2. sreek

    sreek New Member

    Joined:
    Nov 15, 2010
    Messages:
    11
    Likes Received:
    2
    Trophy Points:
    0
    Hi,

    Your file "/users/sukeerthiteja/desktop/perl/NM_021964fragment.pep" contains only one value or line? Because if it contains more than one line of information , your assigning of

    "$protein = <PROTEINFILE>;"

    will not work. It will only he last line of your file. IF thats the case you have to read the filehandle through a while loop.
     
  3. sreek

    sreek New Member

    Joined:
    Nov 15, 2010
    Messages:
    11
    Likes Received:
    2
    Trophy Points:
    0
    Sorry for a spelling mistake. My last sentence should be read like this :

    It will only print the last line of your file. If that is the case you have to read the filehandle through a while loop.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice