in reply to maximum size of hash
#'...or die' removed for better reading #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my(%hash); my $startDir = '/home/s0571283/positiveSet/pdb0704071050/pdb/'; &test(); sub test(){ open(POSITIVE_CHAIN_ID, "<POSITIVE_CHAIN_ID"); #Example line: #1KMC A B C D while (my $line = <POSITIVE_CHAIN_ID>){ my @chainIDs = split(/ /,$line); my $pdbID = shift(@chainIDs); #1KMC $pdbID =~ tr/[A-Z]/[a-z]/;#1KMC -> 1kmc $hash{$pdbID} = [ @chainIDs ]; #1kmc-> A B C D } close(POSITIVE_CHAIN_ID); } foreach my $key (keys %hash){print "$key\n"; my $dir = substr($key,1,2); #km #/home/s0571283/positiveSet/pdb0704071050/pdb/km/pdb1kmc.ent my $pdbFile = $startDir . $dir . '/' . 'pdb' . $key . '.ent'; open(PDBFILE, "<$pdbFile"); while(my $line = <PDBFILE>){ if($line =~ /^ATOM/){ for my $index ( 0 .. $#{ $hash{$key} } ) { #look for chain ID, eg: 'A' if( substr($line,21,1) eq $hash{$key}[$index]){ open(SINGLE, ">>$startDir".$dir.'/'."$key".'_'. "$ha +sh{$key}[$index].pdb"); print SINGLE $line; close(SINGLE); } if ($index != $#{ $hash{$key} }){ for (my $i = $index+1; $i < $#{$hash{$key}}; $i++){ if( substr($line,21,1) eq $hash{$key}[$index] || +substr($line,21,1) eq $hash{$key}[$i]){ open(DOUBLE, ">>$startDir" . $dir . '/' . $key + . '_' . $hash{$key}[$index] . "$hash{$key}[$i].pdb"); print DOUBLE $line; close(DOUBLE); } }# for }# if($index != $#{ $hash{$key} }) }# for my $index ( 0 .. $#{ $hash{$key} } ) }# if($line =~ /^ATOM/) }# while(my $line = <PDBFILE>) close(PDBFILE); }# foreach
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: maximum size of hash
by ff (Hermit) on May 15, 2007 at 00:31 UTC | |
by Anonymous Monk on Apr 21, 2023 at 03:00 UTC | |
by hippo (Archbishop) on Apr 21, 2023 at 08:22 UTC |