Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I run a Perl program from a Windows platform?

  1. Jan 27, 2005 #1

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    How do I run a Perl program from a Windows platform? I installed Collie Perl Shell for the text editing, and I installed ActivePerl for Windows... but.. what part of ActivePerl should I use to give command lines to run a program? :uhh:

    I've been going through the user guide, but it's not making me any wiser :grumpy:
     
  2. jcsd
  3. Jan 27, 2005 #2
    Whatever directory Perl is installed into (I think C:\Perl is the default) should contain a bin directory with a perl.exe program inside. You use it to run perl scripts; just pass it the name of the script as a parameter on the command line.
     
  4. Jan 27, 2005 #3

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    ah thanks, but that still does not work for me.

    This is what it says in the documentation:
    I launched the perl.exe and typed
    perl -h
    but nothing is happening :zzz:

    I uninstalled and reinstalled the ActivePerl, but that didn't help anything. Suggestions?

    Also:
    1) what is a console window
    2) how do I make /eg my working directory? using Unix commands like pwd and cd?
     
  5. Jan 27, 2005 #4
    The console is just a command-line interface; basically, a DOS prompt. Yes, in order to change the current working directory you have to use the "cd" command.

    To bring up a console, just go to Start > Run, type in "cmd" and hit OK. This should bring up a black window with a command line. Type in "cd C:\Perl\eg" and hit enter to go to the /eg directory, and then type in "perl example.pl" and hit enter to run the example script.

    Other scripts can be run in a similar way. Just cd to the directory with the script and type "perl scriptname" to run the script.
     
  6. Jan 27, 2005 #5

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    :eek: ahhhhhhhh, great :biggrin:

    why don't they say that in their documentation? :grumpy:
    it's working now, thanks
     
  7. Jan 27, 2005 #6
    lol.
    its all understood monique...
    those are the basic commands of DOS ...
     
  8. Jan 27, 2005 #7

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    they should have said to open dos promt :rolleyes: :shy:
     
  9. Jan 27, 2005 #8

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    :biggrin: :biggrin: Just wrote my own program and it's working on a small text file... but my text file is 35 million letters long and my computer can't handle it.. or I'd have to run it for half an hour or so :cry:

    Code (Text):
    !C:\Perl\bin\perl -w
    use strict;

    open IN, "fuse.txt";
    #open OUT, ">output.txt";

    my $sequence="";
    my @intron_array;
    my $intron;
    my $counter=0;

    [b]This part is easy, I remove lines with ">" in the file and compile
    the rest into a single long string so that I have one long text file.[/b]
    while (<IN>){
        if ($_!~/>/){
            chomp;
            $sequence=$sequence.$_;
    #        print OUT $sequence;
        }
    }

    [b]Here I do a pattern match, where I print the first pattern
    found and want to know how many other patterns are found.[/b]
    @intron_array= ($sequence=~m/(GTA[A|T]GT\w{25,35}[A|G]CTAA[C|T]\w{5,10}[C|T]AG)/g);

    foreach $intron(@intron_array){
        #print $intron."\n";
        $counter++;
    }
    print "Eerste intron = ".$intron_array[0]."\nAantal introns= ".$counter;
    Is there any way that I can make the script more efficient or do I just have to let my computer crunch the numbers? Thanks.
     
  10. Jan 27, 2005 #9

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Ok, took 40 minutes to run it twice so :approve:
     
  11. Jan 27, 2005 #10
    I'm impress Monique. Before I know it you'll be a tech guru :approve:
     
    Last edited: Jan 27, 2005
  12. Jan 28, 2005 #11
    he he ...
    not bad ....

    thats the only prob with PERL...
    very good for string handling, but very poor for handling bulk files ...
     
  13. Jan 28, 2005 #12

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Question:

    I have the following file with hard returns
    Code (Text):
    >organism 1.1 (build 1)
    [b]TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT
    ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG[/b]
    >organism 1.1 (build 2)
    [b]CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT
    GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA[/b]
    How do I capture the data that is bolded, into 2 seperate variables? I can't get it to work :cry: :cry:
     
  14. Jan 28, 2005 #13
    simple
    just search for those strings and continue ....

    may b u had the prob with those '\n' (new lines)...
    is that so ???
     
  15. Jan 28, 2005 #14

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Yes, I tried the following regular expression that searches for this pattern

    chomp;
    @contig_array=($_=~/\)(.*)>/g);
    print @contig_array;

    but I don't get anything returned :(
     
  16. Jan 28, 2005 #15

    dduardo

    User Avatar
    Staff Emeritus

    Is this what your looking for?

    Code (Text):
    #!/usr/bin/python

    list = []
    str = ""

    for line in open('infile'):
      if line[0] != '>':
        str += line.rstrip()
      elif str != "":
        list.append(str)
        str = ""
    list.append(str)

    print list
    As you can probably tell the code above is in Python. I find Python much easier to read and program in than Perl.

    The result is:

    ["TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG", "CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGTGCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA"]

    If you need to count how many instances a regex pattern appears Python has a function called findall() which will return a list of all the pattern instances. You can then use the len() function to find out how many instances where found.

    [edit] Hmm, must be a bug with the forum. There shouldn't be a space inside the output string.
     
    Last edited: Jan 28, 2005
  17. Jan 30, 2005 #16

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    "just search for those strings anc continue"
    :rofl: you know how large my document is?

    dduardo, I think I did something like that but I don't like the solution.. I think I can best solve it with an associative array that is defined like this %file=($header,$sequence) .. now I just need to think of a right way to code that..
     
  18. Jan 30, 2005 #17

    dduardo

    User Avatar
    Staff Emeritus

    I still don't understand what your after.

    You basically have a very large file with many lines of this:

    Code (Text):

    >organism 1.1 (build 1)
    TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT
    ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG
    >organism 1.1 (build 2)
    CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT
    GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA
     
    You want to ignore all the lines that begin with ">", but concatenate all the content within each build into seperate variables.

    Now how does the regex fit into this? Do you want to search a variable for a specific pattern and then look through all the other variables to see if it can find that same pattern?

    With a dictionary (aka associative array) you need to know the key name to access the data. With a list you can just loop through it with a counter.

    If for each build you want each line to be stored seperately you can do a list within a list. Something like this:

    Code (Text):

    [["TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT","ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG"],["CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT","GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA"]]
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: How do I run a Perl program from a Windows platform?
  1. PERL Programming (Replies: 5)

Loading...