954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

perl script to create name_directory.

i NEED A PERL SCRIPT TO CREATE NAME_DIRECTORY FOR ALL TRAJECTORIES.

i've trajectory files like this,

rep2.tra3M.bz2
rep2.tra4M.bz2
rep2.tra5M.bz2
rep2.tra6M.bz2
rep2.tra7M.bz2

i want a scipt to list all replicas,copy zipped replicas and unzip all replicas and create a file with list of replicas and call make_pdb.pl for all trajectories.

bioinfo90
Newbie Poster
4 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

Do you have a specific question on how to do this, or are you just asking someone to write the script for you?

roswell1329
Junior Poster in Training
71 posts since May 2006
Reputation Points: 21
Solved Threads: 2
 

im asking how to do this, as im new to perl if anyone can help me with the script i would be very thankful.

bioinfo90
Newbie Poster
4 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

i NEED A PERL SCRIPT TO CREATE NAME_DIRECTORY FOR ALL TRAJECTORIES.

i've trajectory files like this,

rep2.tra3M.bz2 rep2.tra4M.bz2 rep2.tra5M.bz2 rep2.tra6M.bz2 rep2.tra7M.bz2

i want a scipt to list all replicas,copy zipped replicas and unzip all replicas and create a file with list of replicas and call make_pdb.pl for all trajectories.


What do you mean by 'replica'? Assuming that replicas are files whose names start with 'rep' and you know in what directory they are located, you could list all the replicas like this:

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

my @replicas = glob('/home/david/data/rep*.*');
say "List of replicas:";
say join("\n", @replicas);
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

If you're new to Perl but familiar with UNIX, sometimes it's easier to use Perl like a shell language until you learn the internal functions and available modules more. This is how I started with Perl.

For example, there is a Perl module available to manipulate bzipped files, but you might be more comfortable with using the system binary. Using d5e5's code above, you could complete one of your requirements using a system call to bzip itself:

foreach my $rep (@replicas) {
     system("bunzip2", "$rep");
}


If you need more help, give us some more details about what 'replica' files are, what filenames to expect in the bzipped files, and what you want to have happen to the files.

roswell1329
Junior Poster in Training
71 posts since May 2006
Reputation Points: 21
Solved Threads: 2
 

Thanks a lot for the information. i meant replicas as my trajectory files which has coordinate files inside. im trying to upzip the files and chang them to pdb files.

bioinfo90
Newbie Poster
4 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 
Thanks a lot for the information. i meant replicas as my trajectory files which has coordinate files inside. im trying to upzip the files and chang them to pdb files.


I don't know bioinformatics so am not familiar with the terminology you use when referring to the different kinds of files.

What I think you want to do is start by making an array (a variable containing a list of trajectory file names) using the glob command like in my example script. Then you want to make a new directory for each of the trajectory files (a trajectory file is a zipped archive of coordinate files, right?) and then unzip the trajectory file into the new directory. (Make a new directory named 'rep2.tra3M.bz2' and unzip the rep2.tra3M.bz2 file so that all its coordinate files go into the rep2.tra3M.bz2 directory.)

After unzipping all the trajectory files into new directories you want to write a script that uses the glob command to build an array of the coordinate file names in each directory. Then you can loop through this array and perform a subroutine or whatever for each file name in the array to transform the data in the coordinate file into data that you want to write to a pdb file.

d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You