Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the iterative cdhit script useful for standalone use #61

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions lib/Bio/PanGenome/CommandLine/IterativeCdhit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ has '_error_message' => ( is => 'rw', isa => 'Str' );

has 'output_cd_hit_filename' => ( is => 'rw', isa => 'Str', default => '_clustered' );
has 'output_combined_filename' => ( is => 'rw', isa => 'Str', default => '_combined_files' );
has 'number_of_input_files' => ( is => 'rw', isa => 'Int' );
has 'number_of_input_files' => ( is => 'rw', isa => 'Int', default => 1 );
has 'output_filtered_clustered_fasta' => ( is => 'rw', isa => 'Str', default => '_clustered_filtered.fa' );

has 'lower_bound_percentage' => ( is => 'rw', isa => 'Num', default => 98 );
has 'upper_bound_percentage' => ( is => 'rw', isa => 'Num', default => 99 );
has 'step_size_percentage' => ( is => 'rw', isa => 'Num', default => 0.5 );


sub BUILD {
my ($self) = @_;

my ( $output_cd_hit_filename, $output_combined_filename, $number_of_input_files, $output_filtered_clustered_fasta,
my ( $output_cd_hit_filename,$lower_bound_percentage,$upper_bound_percentage,$step_size_percentage, $output_combined_filename, $number_of_input_files, $output_filtered_clustered_fasta,
$help );

GetOptionsFromArray(
Expand All @@ -34,9 +39,15 @@ sub BUILD {
'm|output_combined_filename=s' => \$output_combined_filename,
'n|number_of_input_files=i' => \$number_of_input_files,
'f|output_filtered_clustered_fasta=s' => \$output_filtered_clustered_fasta,
'l|lower_bound_percentage=s' => \$lower_bound_percentage,
'u|upper_bound_percentage=s' => \$upper_bound_percentage,
's|step_size_percentage=s' => \$step_size_percentage,
'h|help' => \$help,
);

$self->lower_bound_percentage($lower_bound_percentage/100) if ( defined($lower_bound_percentage) );
$self->upper_bound_percentage($upper_bound_percentage/100) if ( defined($upper_bound_percentage) );
$self->step_size_percentage($step_size_percentage/100) if ( defined($step_size_percentage) );
$self->output_cd_hit_filename($output_cd_hit_filename) if ( defined($output_cd_hit_filename) );
$self->output_combined_filename($output_combined_filename) if ( defined($output_combined_filename) );
$self->number_of_input_files($number_of_input_files) if ( defined($number_of_input_files) );
Expand All @@ -59,6 +70,10 @@ sub run {
output_combined_filename => $self->output_combined_filename,
number_of_input_files => $self->number_of_input_files,
output_filtered_clustered_fasta => $self->output_filtered_clustered_fasta,
lower_bound_percentage => $self->lower_bound_percentage,
upper_bound_percentage => $self->upper_bound_percentage,
step_size_percentage => $self->step_size_percentage

);
$obj->run;
}
Expand All @@ -68,9 +83,28 @@ sub usage_text {

return <<USAGE;
Usage: iterative_cdhit [options]
Iteratively run cdhit
Iteratively cluster a set of proteins with CD-hit, lower the threshold each time and extracting core genes (1 per isolate) to another file, and remove them from the input proteins file.

# Basic usage where you have a single isolate
iterative_cdhit -m proteome_fasta.faa

# Where you have 10 isolates
iterative_cdhit -m proteome_fasta.faa -n 10

# Specify the output file name cdhit results
iterative_cdhit -m proteome_fasta.faa -n 10 -c _clustered

# Specify the output file name for the output protein sequences
iterative_cdhit -m proteome_fasta.faa -n 10 -f output_filtered_clustered_fasta

# Change the lower bound percentage that you iterate to (defaults to 98%)
iterative_cdhit -m proteome_fasta.faa -l 95

# Change the upper bound percentage that you iterate from (defaults to 99%)
iterative_cdhit -m proteome_fasta.faa -l 100

iterative_cdhit -c _clustered -m _combined_files -n 10 -f _clustered_filtered.fa
# Change the intermediate step size (defaults to 0.5%)
iterative_cdhit -m proteome_fasta.faa -l 0.1

# This help message
iterative_cdhit -h
Expand Down
6 changes: 5 additions & 1 deletion lib/Bio/PanGenome/IterativeCdhit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ has 'output_combined_filename' => ( is => 'ro', isa => 'Str', required =>
has 'number_of_input_files' => ( is => 'ro', isa => 'Int', required => 1 );
has 'output_filtered_clustered_fasta' => ( is => 'ro', isa => 'Str', required => 1 );

has 'lower_bound_percentage' => ( is => 'ro', isa => 'Num', default => 0.98 );
has 'upper_bound_percentage' => ( is => 'ro', isa => 'Num', default => 0.99 );
has 'step_size_percentage' => ( is => 'ro', isa => 'Num', default => 0.005 );

sub run {
my ($self) = @_;

Expand All @@ -41,7 +45,7 @@ sub run {
$self->output_filtered_clustered_fasta, 1
);

for ( my $percent_match = 0.99 ; $percent_match >= 0.98 ; $percent_match -= 0.005 ) {
for ( my $percent_match = $self->upper_bound_percentage ; $percent_match >= $self->lower_bound_percentage ; $percent_match -= $self->step_size_percentage ) {
$self->filter_complete_clusters(
$self->output_cd_hit_filename,
$percent_match,
Expand Down