Skip to content

Commit

Permalink
Density module can now read/write JSON files
Browse files Browse the repository at this point in the history
q
  • Loading branch information
amilacsw committed Aug 16, 2017
1 parent d1525b7 commit e399f75
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 19 deletions.
Binary file modified HotSpot3D-1.7.3.tar.gz
Binary file not shown.
27 changes: 26 additions & 1 deletion lib/TGI/Mutpro/Main/Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ sub new {
$this->{'MinPts'} = undef;
$this->{'number_of_runs'} = undef;
$this->{'probability_cut_off'} = undef;

$this->{'JSON_status'} = undef;
$this->{'mutations_json_hash'} = undef;
$this->{'distance_matrix_json_hash'} = undef;

bless $this, $class;
$this->process();
return $this;
Expand Down Expand Up @@ -242,6 +247,9 @@ sub setOptions {
'minPts=f' => \$this->{'MinPts'},
'number-of-runs=f' => \$this->{'number_of_runs'},
'probability-cut-off=f' => \$this->{'probability_cut_off'},
'use-JSON' => \$this->{'JSON_status'},
'mutations-hash-json-file=s' => \$this->{'mutations_json_hash'},
'distance-matrix-json-file=s' => \$this->{'distance_matrix_json_hash'},

'help' => \$help,
);
Expand Down Expand Up @@ -338,10 +346,22 @@ sub setOptions {
} else {
warn "HotSpot3D::Cluster::setOptions warning: no pairwise-file included (cannot produce mutation-mutation clusters)!\n";
}
if ( defined $this->{'JSON_status'} ) {
$this->{'JSON_status'} = 1;
warn "HotSpot3D::Cluster::setOptions warning: use-JSON flag used (will not look for pairwise data or maf file)\n";
if ( not defined $this->{'mutations_json_hash'} or not defined $this->{'distance_matrix_json_hash'} ) {
die "HotSpot3D::Cluster::setOptions Error: use-JSON flag is used, but json file locations are not provided!\n";
}
elsif ( not -e $this->{'mutations_json_hash'} or not -e $this->{'mutations_json_hash'} ) {
die "HotSpot3D::Cluster::setOptions Error: use-JSON flag is used, but the provided JSON files do not exist!\n";
}
}
else { $this->{'JSON_status'} = 0; }

if ( not defined $this->pairwiseFile() and
not defined $this->sitePairsFile() and
not defined $this->musitePairsFile() and
not defined $this->drugsCleanFile() ) {
not defined $this->drugsCleanFile() and not $this->{'JSON_status'} ) {
warn "HotSpot3D::Cluster::setOptions error: no pair file provided. Need at least one of *.pairwise, *.clean, *.sites, *.musites.\n";
die $this->help_text();
}
Expand Down Expand Up @@ -1901,6 +1921,11 @@ Usage: hotspot3d cluster [options]
--max-processes Set if using parallel type local (CAUTION: make sure you know your max CPU processes)
--gene-list-file Choose mutations from the genes given in this list
--structure-list-file Choose mutations from the structures given in this list
--use-JSON Use pre-encoded mutations and distance-matrix hashes in json format, default (no flag): do not use json
--mutations-hash-json-file JSON encoded mutations hash file produced by a previous cluster run
--distance-matrix-json-file JSON encoded distance-matrix hash file produced by a previous cluster run
--help this message
Expand Down
76 changes: 61 additions & 15 deletions lib/TGI/Mutpro/Main/Density.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use FileHandle;
use Data::Dumper qw(Dumper);
use List::Util qw[min max shuffle];
use Getopt::Long;
use JSON;

our @ISA = qw( TGI::Mutpro::Main::Cluster );

Expand Down Expand Up @@ -51,18 +52,6 @@ sub process {
my $mutations = {};
my $WEIGHT = "weight";

$this->readMAF( $temp_mutations );
$this->getDrugMutationPairs( $temp_distance_matrix );
$this->getMutationMutationPairs( $temp_distance_matrix );
$this->vertexFilter( $temp_mutations , $temp_distance_matrix , $mutations , $distance_matrix );
#$this->initializeSameSiteDistancesToZero( $distance_matrix );
#$this->networkClustering( $mutations , $distance_matrix );
$this->setSameSiteDistancesToZero( $distance_matrix, $mutations );

# my ( $help, $options );
# if ( $help ) { print STDERR $this->help_text(); exit 0; }
unless( $this->{'pairwise_file'} ) { warn 'You must provide a pairwise file! ', "\n"; die $this->help_text(); }
unless( -e $this->{'pairwise_file'} ) { warn "The input pairwise file (".$this->{'pairwise_file'}.") does not exist! ", "\n"; die $this->help_text(); }
if ( not defined $this->{'Epsilon'} ) {
warn "HotSpot3D::Cluster warning: no Epsilon value given, setting to default Epsilon value = 10\n";
$this->{'Epsilon'} = $EPSILONDEFAULT;
Expand All @@ -88,9 +77,35 @@ sub process {

#####################################################

# print "distance matrix\n";
if ( $this->{'JSON_status'} ) {
$mutations = readHash( $this->{'mutations_json_hash'} );
$distance_matrix = readHash( $this->{'distance_matrix_json_hash'} );
}
else {
unless( $this->{'pairwise_file'} ) { warn 'You must provide a pairwise file! ', "\n"; die $this->help_text(); }
unless( -e $this->{'pairwise_file'} ) { warn "The input pairwise file (".$this->{'pairwise_file'}.") does not exist! ", "\n"; die $this->help_text(); }

$this->readMAF( $temp_mutations );
$this->getDrugMutationPairs( $temp_distance_matrix );
$this->getMutationMutationPairs( $temp_distance_matrix );
$this->vertexFilter( $temp_mutations , $temp_distance_matrix , $mutations , $distance_matrix );

printHash( $distance_matrix, "distance_matrix_hash" );
printHash( $mutations, "mutations_hash" );
}

#print "distance matrix\n";
#print Dumper $distance_matrix;
#print "mutations\n";
#print Dumper $mutations;
#printHash( $distance_matrix, "distance_matrix_hash" );
#printHash( $mutations, "mutations_hash" );
#print "read from JSON\n";
#readHash( $distance_matrix, "distance_matrix_hash.json" );
#readHash( $mutations, "mutations_hash.json" );
# print "distance matrix from JSON\n";
# print Dumper $distance_matrix;
# print "mutations\n";
# print "mutations from JSON\n";
# print Dumper $mutations;

$this->densityClustering( $mutations, $distance_matrix );
Expand Down Expand Up @@ -455,7 +470,13 @@ sub GetFileName {
my $this = shift @_;

my @tempArray = split( "/",$this->{'pairwise_file'}) ;
$this->{'pairwise_file_name_only'} = pop @tempArray;

if ( not defined @tempArray ) {
$this->{'pairwise_file_name_only'} = 'HS3D.DensityClustering';
}
else {
$this->{'pairwise_file_name_only'} = pop @tempArray;
}

return $this;
}
Expand Down Expand Up @@ -1133,6 +1154,31 @@ sub setRWD {

}

sub printHash {
my ( $hashRef, $fileName ) = @_;
my $outfile = join( "", $fileName, ".json" ) ;
my $OUT = FileHandle->new( "$outfile" , "w" );

my $json = encode_json $hashRef;
$OUT->print( $json );
return;
}

sub readHash {
my $fileName = shift @_;
my $hashRef = {};
print "read JSON hash: $fileName\n";
my $fh = new FileHandle;
die "Could not open $fileName\n" unless( $fh->open( $fileName , "r" ) );

my $json = <$fh>;
$fh->close();

$hashRef = decode_json( $json );

return $hashRef;
}

sub help_text{
my $this = shift;
return <<HELP
Expand Down
11 changes: 8 additions & 3 deletions lib/TGI/Mutpro/Main/Visual.pm
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ sub densityVisual {
last;
}
}
$fh->print( "\n\# $CurrentSC.$CurrentLevel.$CurrentSub\n" );

if (not defined $PrevEntry) {
print "******** None of the variants appear in the given PDB structure *********\n";
Expand Down Expand Up @@ -813,17 +814,21 @@ sub setFirstColors {
my $GeneName = $1;
my $MutName = $2;

$fh->print( "\n\# ".$ClusterArrayRef->[0]."\n" ); # commented line with cluster id at the start of a new cluster

foreach my $key (keys %{$this->{mutations}->{$variant}}) {
my @ChainRes = split(":", $key);
my $chain = shift @ChainRes;
my $res = shift @ChainRes;

if ($SecondDigit == 0) { # super cluster
$fh->print( "\n" );
# $fh->print( "\n\# ".$ClusterArrayRef->[0]."\n" );
$fh->print( "sele ".$currentColor."_".$GeneName."_".$MutName."_".$chain.", (resi ".$res." and chain ".$chain.");\n" );
$fh->print( "color ".$currentColor.", (resi ".$res." and chain ".$chain.");\n" );
$fh->print( "show spheres, (resi ".$res." and chain ".$chain.");\n" );
}
elsif ($SecondDigit == 1) { # first level
$fh->print( "\n" );
# $fh->print( "\n\# ".$ClusterArrayRef->[0]."\n" );
$fh->print( "color ".$currentColor.", (resi ".$res." and chain ".$chain.");\n" );
$fh->print( "show spheres, (resi ".$res." and chain ".$chain.");\n" );
$fh->print( "sele ".$currentColor."_".$GeneName."_".$MutName."_".$chain.", (resi ".$res." and chain ".$chain.");\n" );
Expand All @@ -832,7 +837,7 @@ sub setFirstColors {
$this->{ClusterColors}->{$ClusterArrayRef->[0]} = $currentColor; # To keep track of the color of a given cluster ID. Usefull in setting surfaces
}
elsif ($SecondDigit > 1) { # higher levels
$fh->print( "\n" );
# $fh->print( "\n" );
if ( $ClusterArrayRef->[5] eq 2 ) { # this subcluster doesn't cover anything below it (no need to check PROCESSED)
$fh->print( "color ".$currentColor.", (resi ".$res." and chain ".$chain.");\n" );
$fh->print( "show spheres, (resi ".$res." and chain ".$chain.");\n" );
Expand Down

0 comments on commit e399f75

Please sign in to comment.