filehandle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freshpetals
    New Member
    • Sep 2008
    • 7

    filehandle

    Hello people..I just wanted to know that can we store number of files in a filehandle ..if yes how could we do that???I did write a program but its just parsing result from the file which I'm giving at first position.
    Thanx in advance !!
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Post some code, your question is confusing.

    Comment

    • freshpetals
      New Member
      • Sep 2008
      • 7

      #3
      I have written this code.The output of this code should be total number of individual bases in both the files.
      But the output is showing only total number of bases in first file i.e, pdb.txt.
      I hope I made my question clear this time??Let me knw if u want some other information.Tha nx in advance!!
      Code:
      #!usr/bin/perl
      $/=undef;
      	$file1='C:\Users\documents\pdb.txt';
      	$file2='C:\Users\documents\pdb1.txt';
      	@files=($file1,$file2);
      	foreach $file(@files)
      	{
      	open(IN,$file) or "die error opening $file";
      	$data=<IN>;
      	$data1=reverse $data;
      	$data2=length $data1;
      	print"\nlength of sequence is $data2\n"; 
      	print"\nlength of sequence is $data1\n";
      	$a=($data=~tr/a/A/);
      	$t=($data=~tr/t/T/);
      	$g=($data=~tr/g/G/);
      	$c=($data=~tr/c/C/);
      	
      	$total=($a+$t+$g+$c);
      	}
      
      print"The total number of adenine   are : $a\n";
      print"The total number of Thymine  are : $t\n";
      print"The total number of Guanine  are : $g\n";
      print"The total number of Cytosine are : $c\n";
      print"The total bases are $total";
      Last edited by numberwhun; Sep 26 '08, 10:07 PM. Reason: Please use code tags!

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        probably you need to change this line:

        Code:
        $total=($a+$t+$g+$c);
        that overwrites the value of $total instead of summing all the values across all files:

        try using "+=" instead of "=":

        Code:
        $total += ($a+$t+$g+$c);
        Same for all of these if you want a sum across all files:

        Code:
        $a += ($data=~tr/a/A/);
        $t += ($data=~tr/t/T/);
        $g += ($data=~tr/g/G/);
        $c += ($data=~tr/c/C/);

        Comment

        • freshpetals
          New Member
          • Sep 2008
          • 7

          #5
          yah...now its working...but not giving correct result... coz if I have 10 letters /bases in one of the file its showing 16...why??And how do I remove it??

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Without seeing your data how do you expect me or anyone to know?

            Comment

            • freshpetals
              New Member
              • Sep 2008
              • 7

              #7
              I have two files having just lines of bases...like this
              AGTGCCGTA and no other lines....

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                Originally posted by freshpetals
                I have two files having just lines of bases...like this
                AGTGCCGTA and no other lines....
                There is no way to debug the problem when you post one line of data. Post the real data you say gives incorrect results.

                Comment

                Working...