Need help with a slight modification to my PERL script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with a slight modification to my PERL script
# 1  
Old 05-24-2009
Need help with a slight modification to my PERL script

Hi all,

So I have a script that reads a file called FILEA.txt and in that file there are several columns. The ones that are most important are the $name $start and $stop. So currently the script takes values between the start and stop (inside) by using a program called fastamd. But what I want it to do is take values flanking the start and stop (outside). So lets say I want to take the first 200 values flanking the start and stop. What modifications do I have to make to my current script. Right now I made it very detailed to show what I've done.


Here it is:

Code:
use strict;
use warnings;

### open the FILEA
(open my $FILEA,"<","FILEA.txt") || die "could not open FILEA file";

### open an output file
(open my $OUT,">","FILEB.txt") || die "could not open output file";


### go through the file, line by line
while(<$FILEA>)
{
   chomp;    ### to get rid of carriage returns at the end of each line
   
   #### contents of each line are stored in a variable called $_ , which does not need to be indicated for many of the function calls below
   next if(/^#/);     #### skips any lines that being with #
   my @f=split /\t/;  #### splits the line on the tab characters, storing each part in an array called @f with n elements numbered 0 to n-1 
   
   my $chrom=$f[0];   #### Type is the 0th element
   my $start=$f[3];   #### start is the 3rd element
   my $stop=$f[4];    #### stop is the 4th element
   my $strand=$f[6];  #### strand is the 6th element
   my $name=$f[8];    #### names 
   
   print "$name\n";   ### print the name to the terminal window (STDOUT)
   
   #### will use the program "fastacmd" to extract values from the database "NMR_DATA" stored in a subdirectory here
   #### the program fastacmd should be in the same directory as this script
   
   ### fastacmd refers to strand as either 1 or 2 (+ or -).  
   ### this line checks if strand is "+".  if it is then strandnum is set to 1.  if it is not then strandnum is set to 2
   my $strandnum=($strand eq "+") ? 1 : 2;  
   
   #### prepare the command
   #### arguments to fastacmd
   #### -d database
   #### -p Type, F=nucleotide
   #### -s search string in header, here we use the chromosome in the form chrX
   #### -L start,stop positions
   #### -S strandnum
   
   my $command="fastacmd.exe -d NMR_DATA/NMR_DATA -p F -s $chrom -L $start,$stop -S $strandnum";
   
   ### remove the comment character from this line and it will show the command that is being run in the terminal window
   print "$command\n";
   
   ### run the command and capture the results, which should be a fasta sequence record
   my $seqrec=`$command`;
   
   my @seqreclines=split /\n/,$seqrec;   #### split the sequence record into lines, store in array @seqreclines
   my $defline=shift @seqreclines;       #### the 0th element is the defline, remove it using shift and capture in a variable $defline
   my $seq = join("",@seqreclines);      #### the remaining elements are sequence, join them all together into a single line
   
   
   
   #### print out to the file
   
   
   print $OUT "$name\t$chrom\t$start\t$stop\t$strand\t$defline\t$seq\n";
   
   
   
   


}


Last edited by vidyadhar85; 05-25-2009 at 02:29 AM.. Reason: code tags added
# 2  
Old 05-24-2009
Quote:
But what I want it to do is take values flanking the start and stop (outside). So lets say I want to take the first 200 values flanking the start and stop
I have no idea what that means and can't figure it out by looking at your code. Keep in mind, 99%+ of the people here are programmers, not biologists. Explain it in pure programming terms and supply sample data.
# 3  
Old 05-24-2009
ooops sorry

So the gene has a start and stop. Currently it is reading the values between the start and stop (the gene). But what I want instead is to read outside of the gene (flanking).
# 4  
Old 05-24-2009
OK. Maybe someone else can help you. I'm not into teeth pulling sessions.
# 5  
Old 05-25-2009
Quote:
Originally Posted by phil_heath
So the gene has a start and stop.
Awesome !

Quote:
... Currently it is reading the values between the start and stop (the gene)...
Who or what is "it" ??
(a) Your perl script that you posted earlier ?
(b) Or that "fastacmd.exe" program ?

Quote:
...But what I want instead is to read outside of the gene (flanking)...
Again, who will actually read the outside of the gene ?
(a) Your perl script that you posted earlier ?
(b) The "fastacmd.exe" program ?

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies

2. Shell Programming and Scripting

Slight error with my perl script that I could use some help on

So I have a perl script that prompts the user to enter either q or Q to exit the program or c to continue said program. If the user inputs anything other than those three keys they will be prompted again and again for an appropriate input. My script works for the most part except for one small... (6 Replies)
Discussion started by: Eric1
6 Replies

3. Shell Programming and Scripting

Perl command modification

below is a snippet of code from a larger perl code: my $uname = ( -e '/usr/bin/uname' ) ? '/usr/bin/uname' : '/bin/uname'; my $os = ( `$uname 2>/dev/null` ); when i run this code, it seems to be complaining about the backticks. is there any efficient way i can get rid of the backticks... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Modification in script

Hi, I have below script, i want to monitor that that ntp server listed in setting is under sync or not. I wrote below script but it is not working properly. Here are problems, first it should server under sync if "*" shows and rest if shows "+" it means it is next server in waiting list.... (4 Replies)
Discussion started by: learnbash
4 Replies

5. Programming

Excel sheet modification using perl module

Hi , can any one tell me,"How to extract the same format from existing excel file to new excel file " using Spreadsheet::WriteExcel or Spreadsheet::ParseExcel module ??? Example_pgm: Below program is used to read existing excel file..In this program "my $cell = $_;" line is used to... (0 Replies)
Discussion started by: kavi.mogu
0 Replies

6. Shell Programming and Scripting

Excel sheet modification using perl module

Hi , Is there any possibility to read excel sheet in column by column order ?...Thanks in advance,........ :confused: (1 Reply)
Discussion started by: kavi.mogu
1 Replies

7. Shell Programming and Scripting

Excel sheet modification using perl module

I need to insert new column to already existing file ..can any one help me..?? (6 Replies)
Discussion started by: kavi.mogu
6 Replies

8. Shell Programming and Scripting

Excel sheet modification using perl module

Is there any possibility to move the content from one cell to another cell (Excel sheet) using perl module? (3 Replies)
Discussion started by: kavi.mogu
3 Replies

9. Shell Programming and Scripting

Need a modification on this script

Hi All I have files contains rows which look like this: 2 20090721_16:58:47.173 JSUD2 JD1M1 20 IAM 966591835270 249918113182 b 3610 ACM b 3614 ACM b 3713 CPG b 3717 CPG f 5799 REL b 5815 RLC b 5817 RLC :COMMA: NCI=00,FCI=6101,CPC=0A,TMR=00,OFI=00,USI: :COMMB: BCI=1234: :RELCAUSE:10: ... (1 Reply)
Discussion started by: zanetti321
1 Replies

10. Shell Programming and Scripting

help in script modification

i have the following perl script.but it searches for a given filename. i want to run the same script in my directoy which has subdirectories too and it has to display the file if sreach satisfies along with directory name. can anyone help me: perl script: my $FILE = $ARGV; for zf in... (4 Replies)
Discussion started by: a.suryakumar
4 Replies
Login or Register to Ask a Question