Hi all,
I'm writing a program to replace A's and G's in a text file I have. This is the code I have:
#!usr/bin/perl
open(FILE, "whatshappenin") or die $!;
#QUICKEST WAY OF READING A LINE BY LINE INTO AN ARRAY
foreach $line (<FILE>)
{
chomp($line);
my @array_of_chars = split(//,$line);
my $array_of_charsSize = $#array_of_chars + 1;
if($array_of_charsSize < 1480)
{
#THIS PRINTS THE SEQUENCE TITLES
print"$line\n";
}else{
#LOOP THROUGH SEQUENCE DATA ONE CHARACTER AT A TIME
for($i=0;$i<$array_of_charsSize;$i++)
{
#ONLY EDIT ONCE YOU REACH GAP PARTITION (1416 FOR TRN)
if($i>1416)
{
#CHANGE PRESENCE OF DATA 'A' TO 1
if($array_of_chars[$i] == "A" || $array_of_chars[$i] == "a")
{
$array_of_chars[$i] = 0;
#CHANCE PRESENCE OF GAP 'G' TO 0
}elsif($array_of_chars[$i] == "G" || $array_of_chars[$i] == "g")
{
$array_of_chars[$i] = 1;
}
}
}
#PRINT EDITED SEQUENCE
$str = "@array_of_chars";
$str =~ s/(.)\s/$1/seg;
print"$str\n";
}
}
Unfortunately it does not recognize any G's and just changes all the characters to 0's once $i>1416. I have a feeling it has to do with the equality statement inside my ifelseif statements, but I can't figure it out. Do I need to use ASCII values or something?
Any help is much appreciated!
I'm writing a program to replace A's and G's in a text file I have. This is the code I have:
#!usr/bin/perl
open(FILE, "whatshappenin") or die $!;
#QUICKEST WAY OF READING A LINE BY LINE INTO AN ARRAY
foreach $line (<FILE>)
{
chomp($line);
my @array_of_chars = split(//,$line);
my $array_of_charsSize = $#array_of_chars + 1;
if($array_of_charsSize < 1480)
{
#THIS PRINTS THE SEQUENCE TITLES
print"$line\n";
}else{
#LOOP THROUGH SEQUENCE DATA ONE CHARACTER AT A TIME
for($i=0;$i<$array_of_charsSize;$i++)
{
#ONLY EDIT ONCE YOU REACH GAP PARTITION (1416 FOR TRN)
if($i>1416)
{
#CHANGE PRESENCE OF DATA 'A' TO 1
if($array_of_chars[$i] == "A" || $array_of_chars[$i] == "a")
{
$array_of_chars[$i] = 0;
#CHANCE PRESENCE OF GAP 'G' TO 0
}elsif($array_of_chars[$i] == "G" || $array_of_chars[$i] == "g")
{
$array_of_chars[$i] = 1;
}
}
}
#PRINT EDITED SEQUENCE
$str = "@array_of_chars";
$str =~ s/(.)\s/$1/seg;
print"$str\n";
}
}
Unfortunately it does not recognize any G's and just changes all the characters to 0's once $i>1416. I have a feeling it has to do with the equality statement inside my ifelseif statements, but I can't figure it out. Do I need to use ASCII values or something?
Any help is much appreciated!