473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Finding the mismatches

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 1812
numberwhun
3,509 Expert Mod 2GB
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 Expert 256MB
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
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...
11
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...
1
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...
0
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...
4
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...
2
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. ...
0
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...
4
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.