hi,
I am a baby at perl so pls be gentle.
I am tring to read and write to a file at the same time. for now I have separated them (read from TEMPFILE and write to DBFILE).
what I need to do is add to the end of each line in the temp file the value $sequenceValue.
another problem Im having is althogh I use "seek" when reding the file I get the second line and not the first.
thanks.
print "what length?\n";
$sequenceLength = getc;
$fileName = $sequenceLength . "temp.txt";
open(TEMPFILE,"+>".$fileName) or die "Can't open output.txt: $!";
sub builed_list{
my($length, $seq)=@_;
if($length == 1)
{
print TEMPFILE $seq;
print TEMPFILE "\n";
return;
}
$length--;
$sequenceA = $seq ."A";
builed_list($length, $sequenceA);
$sequenceC = $seq ."C";
builed_list($length, $sequenceC);
$sequenceG = $seq ."G";
builed_list($length, $sequenceG);
$sequenceT = $seq ."T";
builed_list($length, $sequenceT);
}
$sequence = "A";
&builed_list($sequenceLength,$sequence);
$sequence = "C";
&builed_list($sequenceLength,$sequence);
$sequence = "G";
&builed_list($sequenceLength,$sequence);
$sequence = "T";
&builed_list($sequenceLength,$sequence);
$seekGood = seek TEMPFILE, 0, 0; #go to the begining of the file
if($seekGood == 0)
{
die "can't seek\n";
}
$fileName = $sequenceLength . "DB.txt";
open(DBFILE,"+>".$fileName) or die "Can't open output.txt: $!";
while(<TEMPFILE>)
{
read TEMPFILE, $sequence, $sequenceLength;
$sequenceValue = 0;
for ($i=0; $i<$sequenceLength; $i++)
{
$base = substr $sequence, $i, 1;
$addValue = 0;
if($base eq "C")
{
$addValue += 1;
}
elsif($base eq "G")
{
$addValue += 2;
}
elsif($base eq "T")
{
$addValue += 3;
}
for($j=$i+1; $j<$sequenceLength; $j++)
{
$addValue *= 10;
}
$sequenceValue += $addValue;
}
print DBFILE "$sequence $sequenceValue";
print DBFILE "\n";
printf("%s %d\n",$sequence, $sequenceValue);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.