I am writing a fairly simple script that is supposed to print out lines from a txt file and group them based on where I want them. The general format of the files I am using the script on is as follows:
662376 [S] |GCGG | | |
662375 [S] |CGCC | | |
662374 [S] |GCGG | | |
662373 [H] |CATC | | |
662371 [Y] |TCCC | | |
662369 [M] |CACCC| | |
662367 [Y] |TCTTT| | |
662365 [S] |GCGGG| | |
662364 [R] |AGAAA| | |
662360 [M] |CACCC| | |
662359 [W] |ATAAA| | |
662358 [S] |CGCCC| | |
662357 [M] |ACAAA| | |
662356 [R] |GAAAG| | |
662354 [S] |GCGGG| | |
662353 [R] |AGAAA| | |
662352 [R] |GAGGG| | |
662350 [K] |TGTTT| | |
662349 [Y] |CTCCC| | |
662348 [M] |ACAAA| | |
662347 [R] |GAGGG| | |
662376 [S] |GCGG | | |
662375 [S] |CGCC | | |
662374 [S] |GCGG | | |
662373 [H] |CATC | | |
662371 [Y] |TCCC | | |
662369 [M] |CACCC| | |
662367 [Y] |TCTTT| | |
662365 [S] |GCGGG| | |
662364 [R] |AGAAA| | |
662360 [M] |CACCC| | |
662359 [W] |ATAAA| | |
662358 [S] |CGCCC| | |
662357 [M] |ACAAA| | |
662356 [R] |GAAAG| | |
662354 [S] |GCGGG| | |
662353 [R] |AGAAA| | |
662352 [R] |GAGGG| | |
662350 [K] |TGTTT| | |
662349 [Y] |CTCCC| | |
662348 [M] |ACAAA| | |
662347 [R] |GAGGG| | |
and here is the code: -
print "What is the start of the ORF?\n";
-
$orf_beg = <STDIN>;
-
-
open (IN, '/home/asession/pracperl/bin/SNPYNR+-1kb.txt') || die "nope\n";
-
-
while (<IN>) {
-
-
chomp;
-
-
$position = substr $_, 1, 11; # extract the position
-
$type_of_polymorphism = substr $_, 13, 3; # extract the polymorphism type, same as ref if no polymorphism
-
$ref_seq = substr $_, 17, 1; # extract the cerevisiae ref sequence
-
$para_seq = substr $_, 18, 1; # extract the paradoxus sequence
-
$mika_seq = substr $_, 19, 1; # extract the mika sequence
-
$kudr_seq = substr $_, 20, 1; # extract the kudr sequence
-
$baya_seq = substr $_, 21, 1; # extract the bayanus sequence
-
-
-
$baya_seq =~ s/\s+/x/g;
-
#$position =~ tr/ //d;
-
-
foreach ($position) {
-
while ($postion > $orf_beg) {
-
print "$position $ref_seq $para_seq $baya_seq\n";
-
}}
-
-
}
-
close (IN);
-
-
print "\n";
-
Basically the problem I am having is that the while loop withing the foreach loop is not recognizing the position variable as a number, I tried to remove the white space, thinking that was an issue, but it did not work. Any suggestions?
16 2287
If this is supposed to be input to the perl program, remove the newline from the end: - print "What is the start of the ORF?\n";
should be: - print "Enter the start of the ORF: ";
-
chomp($orf_beg = <STDIN>);
Thats not the variable that perl isnt recognizing, the $position is the problem, I defined orf beg before opening the file handle so that during the loop it wouldnt ask me to input the start of the ORF before every iteration.
Are you certain that $position has a number in it? Have you checked the value of $position?
--Kevin
Are you certain that $position has a number in it? Have you checked the value of $position?
--Kevin
To find out, you could run your script in the Perl debugger and check all the values to make sure. To start the debugger, use:
THe debugger is a little daunting at first, but its not bad once you read a tutorial, even the one at Perldoc is doable.
Regards,
Jeff
Are you certain that $position has a number in it? Have you checked the value of $position?
--Kevin
sessmurda,
I was wondering about the logic in this loop: -
foreach ($position) {
-
while ($postion > $orf_beg) {
-
print "$position $ref_seq $para_seq $baya_seq\n";
-
}}
-
-
Inside while ($postion > $orf_beg) {} loop, you are not modifying the value of $position. So, if the condition returns true, this will result in an infinite loop.
You should be using if() loop instead of while(). However, check if $position has indeed a number in it by printing out the value.
- Nithin
this line: - $position = substr $_, 1, 11;
with this input fromthe file:
will result in:
62376 [S] |
Is that really what you want?
sessmurda,
I was wondering about the logic in this loop: -
foreach ($position) {
-
while ($postion > $orf_beg) {
-
print "$position $ref_seq $para_seq $baya_seq\n";
-
}}
-
-
Inside while ($postion > $orf_beg) {} loop, you are not modifying the value of $position. So, if the condition returns true, this will result in an infinite loop.
You should be using if() loop instead of while(). However, check if $position has indeed a number in it by printing out the value.
- Nithin
Also, correct me if I am wrong, but I don't see that $position was defined as an array, so doing a foreach will result in one time through.
Regards,
Jeff
Also, correct me if I am wrong, but I don't see that $position was defined as an array, so doing a foreach will result in one time through.
Regards,
Jeff
Thanks for the addition, Jeff. I missed it totally :)
The foreach loop will be of no specific purpose in that section of script.
I am currently working on the foreach and while/if suggestions you guys provided, thanks! To answer some questions: the position is a number, it doesnt show when I copy and pasted the text, but there is a lot of white space between the last number of the position and the sequence character to allow for the fact that on occasion there will need to be decimals due to the format of the file. I checked all of the substring column numbers before posting, they are all correct. I originally had the if statement inside the loop but it kept asking me for the polymorphism on every iteration, I incorrectly thought while was what I should be using. Also when I tried pushing the $position variable into an array it would not move past the first position, even when I tried the shift function. When I use the script I posted without the while/if line, and have the $position being acted on by the foreach loop, it works, its just that I want to catalogue the positions based on where I specify it, then output those to each their own file, which I will work on after I get the script working.
Thanks again for the help.
use the code tags around your data to preserve the spacing.
Sorry for the late response, had a conference away in LA, but after playing with the script and using warnings I have figured out that even though when I print out only the $position, do not use STDIN for orf_beg, or redefine $position not to include decimals, the script tells me this..
Use of uninitialized value in string gt at gamma.pl line 25, <IN> line 1.
Use of uninitialized value in string gt at gamma.pl line 25, <IN> line 2.
etc etc. So I figure that even though I see only numbers whenever I print out the position variable, that it is not reading the position as a number because of the way I created the substr maybe. That is my only guess, and I was wondering how would I go about making sure that the gt statement works. I tried reformatting $position with sprint f so that all of the values turn to numbers that are rounded to nearest thousandth, but that did not work out. I also took out the foreach statement as suggested, the new script is below: -
#!/usr/bin/perl -w
-
-
-
print "What is the start of the ORF?";
-
$orf_beg = <STDIN>;
-
-
open (IN, '/home/asession/pracperl/bin/SNPYNR+-1kb.txt') || die "nope\n";
-
-
while (<IN>) {
-
-
chomp;
-
-
$position = substr $_, 1, 10; # extract the position
-
$type_of_polymorphism = substr $_, 13, 3; # extract the polymorphism type, same as ref if no polymorphism
-
$ref_seq = substr $_, 17, 1; # extract the cerevisiae ref sequence
-
$para_seq = substr $_, 18, 1; # extract the paradoxus sequence
-
$mika_seq = substr $_, 19, 1; # extract the mika sequence
-
$kudr_seq = substr $_, 20, 1; # extract the kudr sequence
-
$baya_seq = substr $_, 21, 1; # extract the bayanus sequence
-
-
-
$baya_seq =~ s/\s+/x/g; # replace all blanks with 'x'
-
$position =~ tr/ //d; # remove white space
-
-
if ($postion gt $orf_beg) {
-
print "$position $ref_seq $para_seq $baya_seq\n";
-
#print "$position\n";
-
-
}}
-
close (IN);
-
-
print "\n";
-
need to see your data, the formatted data. Post it and put code tags around it.
My bad, here is the data: -
662376 [S] |GCGG | | |
-
662375 [S] |CGCC | | |
-
662374 [S] |GCGG | | |
-
662373 [H] |CATC | | |
-
662371 [Y] |TCCC | | |
-
662369 [M] |CACCC| | |
-
662367 [Y] |TCTTT| | |
-
662365 [S] |GCGGG| | |
-
662364 [R] |AGAAA| | |
-
662360 [M] |CACCC| | |
-
662359 [W] |ATAAA| | |
-
662358 [S] |CGCCC| | |
-
662357 [M] |ACAAA| | |
-
662356 [R] |GAAAG| | |
-
662354 [S] |GCGGG| | |
-
662353 [R] |AGAAA| | |
-
662352 [R] |GAGGG| | |
-
662350 [K] |TGTTT| | |
-
662349 [Y] |CTCCC| | |
-
662348 [M] |ACAAA| | |
-
662347 [R] |GAGGG| | |
-
662346 [b] |GCCTC| | |
-
662345 [M] |CACCC| | |
-
662344 [b] |CGTCC| | |
-
662343.002 [c] |---C-| | |
-
662343.001 [a] |---A-| | |
-
662343 [K] |GTTGG| | |
-
Sorry for the late response, had a conference away in LA, but after playing with the script and using warnings I have figured out that even though when I print out only the $position, do not use STDIN for orf_beg, or redefine $position not to include decimals, the script tells me this..
Use of uninitialized value in string gt at gamma.pl line 25, <IN> line 1.
Use of uninitialized value in string gt at gamma.pl line 25, <IN> line 2.
The error you are getting is because of a typo in this line: -
if ($postion gt $orf_beg) {
-
Look out for the missing 'i' in $position.
The error you are getting is because of a typo in this line: -
if ($postion gt $orf_beg) {
-
Look out for the missing 'i' in $position.
Good catch and it reminds me of why I don't like to look over peoples code that does not use "strict".
Ah, now I feel like an idiot, but thanks for all the suggestions guys, and especially thanks for your patience kevinadc
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dariusz |
last post by:
I have a database where I use the while() command to iterate through each
row and their resultant arrays to populate a table as the while() command
is executed.
I would like to have in the...
|
by: muser |
last post by:
I have a logical error in my program, I have submitted the program and
my tutor hasn't listed the other problems with the code, but said that
the program won't run because of a while statement....
|
by: Jim |
last post by:
Im getting way too many rows retured..what its trying to do is insert
a 0 for revenue for months 7 - 12 (aka July through December) for each
of these cost centers for each payor type..Im getting a...
|
by: Michael B Allen |
last post by:
Should there be any preference between the following logically equivalent
statements?
while (1) {
vs.
for ( ;; ) {
I suspect the answer is "no" but I'd like to know what the consensus is
|
by: Howard |
last post by:
Hello everyone (total VB.NET beginner here),
I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came
across an exercise that I can't get to work. The exercise asks that
you create...
|
by: pantagruel |
last post by:
Hi,
I have an array like the following:
for(x=0;x<results.length;x++){
alert(results.length);
extracted=results.shift();
alert(results.length);
if(results.indexOf(extracted)== -1){
|
by: devilsangels287 |
last post by:
Hey guys I have a problem with this while loop, its not working properly and I think that I might be typing it wrong but I don't how. please help me! Thanks... Anyways this is a calculator which is...
|
by: Shawn Minisall |
last post by:
I just learned about while statements and get why you place them around
inputs for validation, but I'm a little lost on exactly where to place
it with what condition in this program where the...
|
by: Shawn Minisall |
last post by:
I've been having some problems with using a while statement for one menu
within another while statement for the main menu, first time I've done
it. It's with choice number two from the menu. When...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |