0
!/usr/bin/perl
use Cwd;
use warnings;

open($fh,'<', "clinical.txt");
$line = <$fh>;

while($line = <$fh>)
{   
    
    my @fields2 =split(" ",$line);
    push(@id,$fields2[1]);

    push(@status,$fields2[3]);
    }
@flow = grep { -d } glob "*"; 
$arrSize = @flow;
for ($p = 0; $p < $arrSize; $p++)
{

    @files=<$flow[$p]/*.maf>;
    print $flow[$p],"\n";
    
    foreach $file(@files)
    {
        print $file,"\n";
        open(x,$file);
        %hash={};
        %tested={};
        %Mut_Count={};
        $hyper=0;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        while($line = <x>)
        {
            @temp=split("\t",$line);
            $key=$temp[4]."_".$temp[5]."_".$temp[6]."_".$temp[10]."_".$temp[11]."_".$temp[12]."_".$temp[15];
            push @{$hash{$key}}, "0";
            push @{$Mut_Count{$temp[15]}}, "0";
        }
        
        @nm=split(/\./,$file);
        open(x,$file);
        open(Out1,">Results/".$nm[1]."_Hyper.txt");
        $line = <x>;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        $line = <x>;
        @temp=split(" ",$line);
        @temp2=split(",",$temp[1]);
        print Out1 "Gene\tMutation\tType\tdbSNP\tStatus\tPolyphen\tSift";
        for($j=0;$j<scalar(@id);$j++){
        my @M=split('-', $id[$j]);
        for($i=0;$i<scalar(@temp2);$i++)
        {
        my @N=split('-', $temp2[$i]);
            if(scalar(@{$Mut_Count{$temp2[$i]}})>499 && $M[0] eq $N[0] && $M[1] eq $N[1] && $M[2] eq $N[2] && $status[$j] eq 'MSS')
            {
                print Out1 "\t",$temp2[$i];
                $hyper++;
            }
        }
}
        $line = <x>;
        while($line = <x>)
        {
            $hy=0;
            @temp=split("\t",$line);
            $key=$temp[4]."_".$temp[5]."_".$temp[6]."_".$temp[10]."_".$temp[11]."_".$temp[12];
            if(!exists $tested{$key})
            {
                push @{$tested{$key}}, "0";
                print Out1 "\n",$temp[0],"\t",$key,"\t",$temp[8],"\t",$temp[13],"\t",$temp[25],"\t",$temp[72],"\t",$temp[73];
                
        for($i=0;$i<scalar(@temp2);$i++)
        {

                
                    $key=$temp[4]."_".$temp[5]."_".$temp[6]."_".$temp[10]."_".$temp[11]."_".$temp[12]."_".$temp2[$i];
                    
                    my @L=split('-', $temp2[$i]);
                    for($j=0;$j<scalar(@id);$j++){
        my @O=split('-', $id[$j]);
                    if(scalar(@{$Mut_Count{$temp2[$i]}})>499 && $L[0] eq $O[0] && $L[1] eq $O[1] && $L[2] eq $O[2] && $status[$j] eq 'MSS')
                    {
                        if(exists $hash{$key})
                        {
                            print Out1 "\t1";
                            $hy++;
                        }
                        else
                        {
                            print Out1 "\t0";
                        }
                    }
                    }
                }
                
                
            }
        }
        open(Out3,">Results/".$nm[1]."_Summary.txt");
        print Out3 "Hypermutated\t$hyper\n";
    }
}

$line = <$fh>; while($line = <$fh>) these lines are showing readline() on closed filehandle $fh

%hash={}; %tested={}; %Mut_Count={}; on these three lines it says Reference found where even-sized list expected

.maf are basically GDC downloaded files with bit modified header according to our need with unique TCGA IDs. Whereas, Clinical Info is file contaning TCGA IDs, its source and MSI_Status that tells us whether it is MSI-L, MSI-H or MSS. I'm reading multiple .maf files and comparing it with clinical_info file and if the if condition is satisfied that I want it to generate mastertable(write a file) I'm doing it in windows. Kindly, help me resolve this, Thanks in anticipation.

9
  • 2
    Could you please show us the entire error message and also it would be great to include the input files which you're trying to read and expected results(output) as well. Commented Jan 17, 2023 at 7:50
  • 1
    Also, you must always have use warnings; (adding which requires no changes to the rest of the code), and use strict; (for which you need to declare with my all variables as they are introduced) Commented Jan 17, 2023 at 8:12
  • 1
    Has the question changed? This issue was about a readline on a closed filehandle a while ago. Not is is something different. Please post links to the input files you are using -- there is not enough context to fault find you issue by just looking at the code. Ideally keep the input file ssmall. Commented Jan 17, 2023 at 9:35
  • 1
    You need to supply us with some input data that triggers the issue. We need to reproduce the issue to understand the rppt-cause. Commented Jan 17, 2023 at 10:17
  • 2
    @AqsaArshad.: I have rolled your question back to the original one. If you have solved this question please post a solution and accept it. But if you have a new problem then please post it as a new, separate question. Commented Jan 17, 2023 at 12:19

1 Answer 1

1

Answer to

%hash={}; %tested={}; %Mut_Count={}; on these three lines it says Reference found where even-sized list expected

You can get rid of the errors by getting rid of these three lines, though if you accept (please!) the use strict; recommendation you will need to replace them with my %hash; and so forth.

Under Perl, hashes (and arrays) do not need to be initialized. If you wish to initialize one, you assign it another array, or a list, or another hash. The length of the initializer must be even, since it is interpreted as key/value pairs. Your code supplied a hash reference, which will not be expanded by Perl to an empty hash. Hence the error.

If it makes you nervous not to initialize the hash, you can say my %hash = ();.

On the other hand, if you intend to use a scalar as a hash reference, you will need to initialize it. This is where you use the curly brackets, which (among other things) are a hash constructor which returns a reference to the constructed hash. So:

my $hash = {};
$hash->{$key} = $value;
...
Sign up to request clarification or add additional context in comments.

2 Comments

push @{$hash{$key}}, "0"; in this line value passed should be array not a hash element.
@{$hash{$key}} is an array. If element $hash{$key} does not exist, it will be autovivified as an array reference, and "0" will be pushed onto it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.