i will write the complete problem i am facing. Here is the input file i am using. - sxoght: #query hit score probability qstart qend qorientation tstart tend matches mismatches gapOpening gaps
-
@SNPSTER4_104_308EFAAXX:1:1:1694:128
-
GGGATAAGAGAGGTGCATGTTGGTATTTAAGGTAGT
-
1 alignment(s) -- reports limited to 10 alignment(s)
-
-
sxoght: SNPSTER4_104_308EFAAXX:1:1:1694:128 gi|122939163|ref|NM_000165.3| -10 1.000000 1 36 + 1595 1630 35 1 00
-
Score = -10, P(A|R) = 1.000000
-
Query: 1 GGGATAAGAGAGGTGCATGTTGGTATTTAAGGTAGT 36
-
|||||||||||||||||||||||||||||| |||||
-
Sbjct: 1595 GGGATAAGAGAGGTGCATGTTGGTATTTAAAGTAGT 1630
-
-
@SNPSTER4_104_308EFAAXX:1:1:1608:94
-
GCAGTTTTAAGTTATTAGTTTTTAAAATCAGTACTT
-
14 alignment(s) -- reports limited to 10 alignment(s)
-
-
sxoght: SNPSTER4_104_308EFAAXX:1:1:1608:94 gi|113412254|ref|XR_018775.1| 0 0.090884 1 36 + 1578 1613 36 0 00
-
Score = 0, P(A|R) = 0.090884
-
Query: 1 GCAGTTTTAAGTTATTAGTTTTTAAAATCAGTACTT 36
-
||||||||||||||||||||||||||||||||||||
-
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: - >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
-
-
>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 : - #!/usr/bin/perl
-
open(FILE,"transalign.output") or die "can not open file";
-
while($var=<FILE>){
-
$str1=();$str2=();
-
if($var=~/^sxoght:/){
-
@ar=split(/\s+/,$var);
-
#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";
-
}
-
if($var=~/^Query:/){
-
$str1=$var;
-
$str1=~s/^Query:\s+//g;
-
$str1=~s/\d+\s+//g;
-
$str1=~s/\s+//g;
-
}
-
if($var=~/^Sbjct:/){
-
$str2=$var;
-
$str2=~s/^Sbjct:\s+//g;
-
$str2=~s/\d+\s+//g;
-
$str2=~s/\s+//g;
-
}
-
for($i=0;$i<=length($str1);$i++)
-
{
-
if(substr($str1,$i,1) ne substr($str2,$i,1)){
-
print substr($str1,$i,1);
-
print substr($str2,$i,1);
-
print "$i\n";
-
}
-
}
-
}
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 !!!
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
Declare $str1 and $str2 outside the while loop. -
my ($str1,$str2);my @ar;
-
while(my $line=<FILE>){
-
Modify the relevant section as below: -
if($var=~/^Query:/){
-
$str1=$var;
-
$str1=~s/^Query:\s+//g;
-
$str1=~s/\d+\s+//g;
-
$str1=~s/\s+//g;
-
$str2="";
-
}
-
if($var=~/^Sbjct:/){
-
$str2=$var;
-
$str2=~s/^Sbjct:\s+//g;
-
$str2=~s/\d+\s+//g;
-
$str2=~s/\s+//g;
-
}
-
if(($str1 ne "") && ($str2 ne "")) {
-
for($i=0;$i<=length($str1);$i++)
-
{
-
if(substr($str1,$i,1) ne substr($str2,$i,1)){
-
my $add=$i+$ar[8];
-
print " $add.";
-
print substr($str1,$i,1);
-
print substr($str2,$i,1);
-
}
-
}
-
$str1=$str2=""; print "\n";
-
}
-
}
-
- Nithin
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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.
|
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...
|
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 {
|
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...
| |
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));
|
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...
|
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...
|
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.
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |