Sponsored Content
Top Forums Shell Programming and Scripting Need help comparing Base Pairs within PERL Post 302655119 by ddreggors on Tuesday 12th of June 2012 09:48:30 PM
Old 06-12-2012
Try this:

Code:
--- test5-old.pl	2012-06-12 21:38:13.986606410 -0400
+++ test5-new.pl	2012-06-12 21:43:51.468953185 -0400
@@ -2,36 +2,24 @@
 #
 use strict;
 use warnings;
-my (@data, $row, @dataline);
+my (@data, $row, @dataline, $dnafile);
+$dnafile = "coutbase.log";
 open(FILE1,"<","UDP3866.pseudo-vs.large.txt") or die $!; @data = <FILE1>; close(FILE1);
 foreach $row (@data) {
 		next unless $row =~ /^\d/;
 		@dataline = split(/\s+/,$row);
 		next unless $dataline[9] ne "NA";
 		next unless $dataline[9] =~ /$dataline[6]/i;
-		print $dataline[0] . "\t" . $dataline[1] . "\t" . $dataline[6] . "\t" .  $dataline[7] . "\t" . $dataline [9] .  "\n";
+		open(COUNTBASE, ">>", \$dnafile) or die $!;
+		print COUNTBASE $dataline[0] . "\t" . $dataline[1] . "\t" . $dataline[6] . "\t" .  $dataline[7] . "\t" . $dataline [9] .  "\n";
+		close COUNTBASE;
 }
-my $outputfile = "COUNTBASE";
-unless (open(COUNTBASE, ">$outputfile")) {print "cant open file\n\n";
-exit;}
-print COUNTBASE "$dataline[7]";
-close (COUNTBASE);
-my $dnafile = <COUNTBASE>;
-#Remove the newline from the dna file name
-chomp $dnafile;
 #Open this file or exit
-unless (open(COUNTBASE, $dnafile)){
-		 print  "can't open file \"$dnafile\"\n\n";
-		exit;
-}
+open(COUNTBASE, "<", \$dnafile) or die $!;
 #store dna information
 my @dna = <COUNTBASE>;
 #close now read file
 close COUNTBASE;
-#turn array into single string
-my $dna = join('', @dna);
-#get rid of blank spaces
-$dna =~ s/\s//g;
 #initialize mutation counts
 my $countExonic = 0;
 my $countIntergenic = 0;

I have attached the file, but this also will give you a quick look at the changes. Everything with a "+" is a change I added, everything with a "-" are lines I removed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl search and replace pairs

Hello all im facing some kind of problem i have this string : functionA() $" "$ functionB("arg1") $" = "$ i will like to replace all the pairs of opening and closing "$" to be something like that functionA() <#" "#> functionB("arg1") <#" = "#> i cant of course do is with simple ... (1 Reply)
Discussion started by: umen
1 Replies

2. Shell Programming and Scripting

Comparing Variables in Perl

Hi. I have three arrays. @a=('AB','CD','EF'); @b=('AB,'DG',HK'); @c=('DD','TT','MM'); I want to compare the elements of the first two array and if they match then so some substition. I tried using the if statement using the scalar value of the array but its not giving me any output. ... (7 Replies)
Discussion started by: kamitsin
7 Replies

3. Shell Programming and Scripting

Comparing arrays in perl

Hi all, I am trying to compare two arrays in perl using the following code. foreach $item (@arrayA){ push(@arrayC, $item) unless grep(/$item/, @arrayB); ... (1 Reply)
Discussion started by: chriss_58
1 Replies

4. Shell Programming and Scripting

PERL name value pairs substituions

I have a main file with variable tokens like this: name: File1 =========== Destination/Company=@deploy.company@ Destination/Environment=@deploy.env@ Destination/Location=@deploy.location@ Destination/Domain=@deploy.location@ MIG_GatewayAddresses=@deploy.gwaddress@ MIG_URL=@deploy.mig_url@... (1 Reply)
Discussion started by: uandme2k2
1 Replies

5. Shell Programming and Scripting

comparing list values in Perl

Hi, I have tab separated list: KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 508 S ENIISGVSY 0.507 cdc2 YES KB0005 511 S ... (1 Reply)
Discussion started by: karla
1 Replies

6. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

7. Shell Programming and Scripting

Perl: Comparing to two files and displaying the differences

Hi, I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm. So far i've across a code like this: use strict; use warnings; my $list1;... (2 Replies)
Discussion started by: dont_be_hasty
2 Replies

8. Shell Programming and Scripting

Perl: Need help comparing huge files

What do i need to do have the below perl program load 205 million record files into the hash. It currently works on smaller files, but not working on huge files. Any idea what i need to do to modify to make it work with huge files: #!/usr/bin/perl $ot1=$ARGV; $ot2=$ARGV; open(mfileot1,... (12 Replies)
Discussion started by: mrn6430
12 Replies

9. Shell Programming and Scripting

Need help in comparing two files using shell or Perl

I have these two file that I am trying to compare using shell arrays. I need to find out the changed or the missing enteries from File2. For example. The line "f nsd1" in file2 is different from file1 and the line "g nsd6" is missing from file2. I dont want to use "for loop" because my files... (2 Replies)
Discussion started by: sags007_99
2 Replies

10. Shell Programming and Scripting

Perl for comparing numbers from previous lines in a file?

Hi everyone I have a question for you, as I am trying to learn more about Perl and work with some weather data. I have an ascii file (shown below) that has 10 lines with different columns. What I would like is have Perl find an "anomalous" value by comparing a field with the values from the last... (2 Replies)
Discussion started by: lucshi09
2 Replies
IO::AtomicFile(3)					User Contributed Perl Documentation					 IO::AtomicFile(3)

NAME
IO::AtomicFile - write a file which is updated atomically SYNOPSIS
use IO::AtomicFile; ### Write a temp file, and have it install itself when closed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->close || die "couldn't install atomic file: $!"; ### Write a temp file, but delete it before it gets installed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->delete; ### Write a temp file, but neither install it nor delete it: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->detach; DESCRIPTION
This module is intended for people who need to update files reliably in the face of unexpected program termination. For example, you generally don't want to be halfway in the middle of writing /etc/passwd and have your program terminate! Even the act of writing a single scalar to a filehandle is not atomic. But this module gives you true atomic updates, via rename(). When you open a file /foo/bar.dat via this module, you are actually opening a temporary file /foo/bar.dat..TMP, and writing your output there. The act of closing this file (either explicitly via close(), or implicitly via the destruction of the object) will cause rename() to be called... therefore, from the point of view of the outside world, the file's contents are updated in a single time quantum. To ensure that problems do not go undetected, the "close" method done by the destructor will raise a fatal exception if the rename() fails. The explicit close() just returns undef. You can also decide at any point to trash the file you've been building. AUTHOR
Primary Maintainer David F. Skoll (dfs@roaringpenguin.com). Original Author Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com). REVISION
$Revision: 1.2 $ perl v5.16.3 2005-02-10 IO::AtomicFile(3)
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy