473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the mismatches

1 New Member
i will write the complete problem i am facing. Here is the input file i am using.

Expand|Select|Wrap|Line Numbers
  1. sxoght: #query  hit     score   probability     qstart  qend    qorientation    tstart  tend    matches mismatches      gapOpening      gaps
  2. @SNPSTER4_104_308EFAAXX:1:1:1694:128
  3. GGGATAAGAGAGGTGCATGTTGGTATTTAAGGTAGT
  4. 1 alignment(s) -- reports limited to 10 alignment(s)
  5.  
  6. sxoght: SNPSTER4_104_308EFAAXX:1:1:1694:128     gi|122939163|ref|NM_000165.3|   -10     1.000000        1       36      +       1595    1630    35      1   00
  7. Score = -10, P(A|R) = 1.000000
  8. Query:          1 GGGATAAGAGAGGTGCATGTTGGTATTTAAGGTAGT 36
  9.                   |||||||||||||||||||||||||||||| |||||
  10. Sbjct:       1595 GGGATAAGAGAGGTGCATGTTGGTATTTAAAGTAGT 1630
  11.  
  12. @SNPSTER4_104_308EFAAXX:1:1:1608:94
  13. GCAGTTTTAAGTTATTAGTTTTTAAAATCAGTACTT
  14. 14 alignment(s) -- reports limited to 10 alignment(s)
  15.  
  16. sxoght: SNPSTER4_104_308EFAAXX:1:1:1608:94      gi|113412254|ref|XR_018775.1|   0       0.090884        1       36      +       1578    1613    36      0   00
  17. Score = 0, P(A|R) = 0.090884
  18. Query:          1 GCAGTTTTAAGTTATTAGTTTTTAAAATCAGTACTT 36
  19.                   ||||||||||||||||||||||||||||||||||||
  20. Sbjct:       1578 GCAGTTTTAAGTTATTAGTTTTTAAAATCAGTACTT 1613

this is a big file, though the whole file looks like this. What i am trying to do exactly is to grep the header (sxoght) for display in columns and also to display where there is a mismatch in the alignment between query and sbjct. for this input file, the expected results should look like:

Expand|Select|Wrap|Line Numbers
  1. >gi|122939163|ref|NM_000165.3| 1595 1630 SNPSTER4_104_308EFAA +XX:1:1:1694:128 1 36 36 -10 1 1.000000 35 mismatch : 1625.GA
  2.  
  3. >gi|113412254|ref|XR_018775.1| 1578 1613 SNPSTER4_104_308EFAA +XX:1:1:1608:94 1 36 36 0 1 0.090884 36 mismatch : 1581.GT 1612.TG

the code which i have written is :

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. open(FILE,"transalign.output") or die "can not open file";
  3. while($var=<FILE>){
  4.         $str1=();$str2=();
  5.         if($var=~/^sxoght:/){
  6.                 @ar=split(/\s+/,$var);
  7.         #print ">$ar[2]\t$ar[8]\t$ar[9]\t$ar[1]\t$ar[5]\t$ar[10]\t$ar[6]\t$ar[3]\t$ar[4]\t$ar[11]\n";
  8.         }
  9.         if($var=~/^Query:/){
  10.                 $str1=$var;
  11.                 $str1=~s/^Query:\s+//g;
  12.                 $str1=~s/\d+\s+//g;
  13.                 $str1=~s/\s+//g;
  14.         }
  15.         if($var=~/^Sbjct:/){
  16.                 $str2=$var;
  17.                 $str2=~s/^Sbjct:\s+//g;
  18.                 $str2=~s/\d+\s+//g;
  19.                 $str2=~s/\s+//g;
  20.         }
  21.         for($i=0;$i<=length($str1);$i++)
  22.         {
  23.         if(substr($str1,$i,1) ne substr($str2,$i,1)){
  24.                 print substr($str1,$i,1);
  25.                 print substr($str2,$i,1);
  26.                 print "$i\n";
  27.         }
  28.         }
  29. }

I am not able to use "strict and warning" because using it doesnt allow me to access the scalar variable outside the loop. In my code, i m trying to extract the positions first, so that i will subtract it from the already stored @arr values of beginning and start. I am having problems with the for loop. I know where i am going wrong, but dont know how to correct it. PLEASEEEE HELP !!!
Nov 17 '08 #1
2 1819
numberwhun
3,509 Recognized Expert Moderator Specialist
First, there are extremely few reasons where you cannot use warnings and strict. They help alleviate the little syntactical errors you will undoubtedly experience. If you need to access variables outside of a loop where they may get populated, then you need to declare them outside of that loop.

I always have a section near the top of my script, just after all the use statements that is specifically for all variable declarations. Try that and run your code and get rid of any syntactical errors. Then, please elaborate on what you mean by "trouble with the loop". You need to be much more specific, even siting any errors.

Regards,

Jeff
Nov 17 '08 #2
nithinpes
410 Recognized Expert Contributor
Declare $str1 and $str2 outside the while loop.
Expand|Select|Wrap|Line Numbers
  1. my ($str1,$str2);my @ar;
  2. while(my $line=<FILE>){ 
  3.  
Modify the relevant section as below:
Expand|Select|Wrap|Line Numbers
  1. if($var=~/^Query:/){ 
  2.                 $str1=$var; 
  3.                 $str1=~s/^Query:\s+//g; 
  4.                 $str1=~s/\d+\s+//g; 
  5.                 $str1=~s/\s+//g; 
  6.                 $str2="";
  7.         } 
  8.         if($var=~/^Sbjct:/){ 
  9.                 $str2=$var; 
  10.                 $str2=~s/^Sbjct:\s+//g; 
  11.                 $str2=~s/\d+\s+//g; 
  12.                 $str2=~s/\s+//g; 
  13.         } 
  14.         if(($str1 ne "") && ($str2 ne ""))  {
  15.               for($i=0;$i<=length($str1);$i++) 
  16.         { 
  17.         if(substr($str1,$i,1) ne substr($str2,$i,1)){ 
  18.                my $add=$i+$ar[8];
  19.                print " $add.";
  20.                print substr($str1,$i,1);
  21.                print substr($str2,$i,1);
  22.                                }           
  23.         } 
  24.         $str1=$str2="";    print "\n"; 
  25. }
  26.  
- Nithin
Nov 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2052
by: Tristan | last post by:
Im trying to expand a search util by uing regular expression to allow common search criteria such as +-* and phrases "". My understanding of ereg(string pattern, string string, ) is that the array register should collect all instances that match the pattern. Heres is an example of the code: $word4 = "+budgie +ferret dog."; //set phrase
11
2366
by: Fuzzyman | last post by:
What's the best, cross platform, way of finding out the directory a script is run from ? I've googled a bit, but can't get a clear answer. On sys.argv the docs say : argv is the script name (it is operating system dependent whether this is a full pathname or not). So this doesn't seem to be the answer.
1
6480
by: Phil Watkins | last post by:
I am a novice programer in Vb and I am having a major brain ache finding out which item has been selected within a list view and then either deleting that item or editing them. My searching so far seems to indicate the use of the "contains" command but I cannot find a helpfull reference. Any help greatly apreciated as I am workin on the...
0
2264
by: Helge Jensen | last post by:
Having posted in microsoft.public.dotnet.framework.sdk and microsoft.public.dotnet.framework.wmi without receiving any response, I posthere on the off-chance that someone who isn't following those groups knows a solution. I'm using code (roughly like): using System; using System.Management; public class Foo {
4
1579
by: Gary | last post by:
I recently joined a project with a mix of K&R C and ANSI C++. There are instances of prototype mismatches defined in one file and used in another that aren't being caught and result in run time errors (see example below). Is there a utility that can catch such mismatches (e.g. lint or something)? I'm constrained in that I'm not allowed to...
2
2837
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. The SELECT query is built as follows: $itemtype = stripslashes(trim($_POST));
0
1873
by: NSF12345 | last post by:
Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\oldpc\main share\Folder\file.txt") Then" way of finding if the file exists, but i want to make it so that it tries to look for the computer, not the file. At the moment this is how i am finding and...
4
8080
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code involving lot of matrices. At one point I need to calculate the square root of a matrix e.g. A which contains non-zero off-diagonal elements. I...
5
1876
by: Ramdas | last post by:
I am doing some HTML scrapping for a side project. I need a method using sgmllib or HTMLParser to parse an HTML file and get line nos of all the tags I tried a few things, but I am just not able to work with either if the parsers.
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.