<commit_before>use VRPipe::Base;

class VRPipe::Steps::bcf_to_vcf with VRPipe::StepRole {
    method options_definition {
        return { bcftools_exe => VRPipe::StepOption->get(description => 'path to bcftools executable', optional => 1, default_value => 'bcftools'),
                 bcftools_view_options => VRPipe::StepOption->get(description => 'bcftools view options', optional => 1, default_value => '-p 0.99 -vcgN') };
    }
    method inputs_definition {
        return { bcf_files => VRPipe::StepIODefinition->get(type => 'bin', max_files => -1, description => '1 or more bcf files to convert to compressed vcf'),
                 samples_files => VRPipe::StepIODefinition->get(type => 'txt', min_files => 0, max_files => -1, description => 'Optional samples file for restricting samples to call on and/or defining ploidy for each sample'),
                 # sites_file => VRPipe::StepIODefinition->get(type => 'txt', min_files => 0, max_files => 1, description => 'Optional sites file for calling only at the given sites'),
             };
    }

    method body_sub {
        return sub {
            my $self = shift;
            my $options = $self->options;
            my $bcftools = $options->{bcftools_exe};
            my $view_opts = $options->{bcftools_view_options};
            
            my %samples;
            foreach my $sample_file (@{$self->inputs->{samples_files}}) {
                my $bcf = $sample_file->metadata->{source_bcf} || next;
                $samples{$bcf} = $sample_file->path;
            }
            
            my $req = $self->new_requirements(memory => 500, time => 1);
            foreach my $bcf (@{$self->inputs->{bcf_files}}) {
                my $bcf_meta = $bcf->metadata;
                my $bcf_path = $bcf->path;
                my $basename = $bcf->basename;
                $basename =~ s/bcf$/vcf.gz/;
                my $vcf_file = $self->output_file(output_key => 'vcf_files', basename => $basename, type => 'vcf', metadata => $bcf_meta);
                my $vcf_path = $vcf_file->path;
                
                my $sample_opts;
                if (exists $samples{$bcf_path}) {
                    $sample_opts = " -s $samples{$bcf_path}";
                }
                my $cmd = qq[$bcftools view $view_opts$sample_opts $bcf_path | bgzip -c > $vcf_path];
                $self->dispatch([$cmd, $req, {output_files => [$vcf_file]}]); 
            }
            <commit_msg>fixed to avoid Use of uninitialized value in concatenation when there are no sample opts<commit_after>use VRPipe::Base;

class VRPipe::Steps::bcf_to_vcf with VRPipe::StepRole {
    method options_definition {
        return { bcftools_exe => VRPipe::StepOption->get(description => 'path to bcftools executable', optional => 1, default_value => 'bcftools'),
                 bcftools_view_options => VRPipe::StepOption->get(description => 'bcftools view options', optional => 1, default_value => '-p 0.99 -vcgN') };
    }
    method inputs_definition {
        return { bcf_files => VRPipe::StepIODefinition->get(type => 'bin', max_files => -1, description => '1 or more bcf files to convert to compressed vcf'),
                 samples_files => VRPipe::StepIODefinition->get(type => 'txt', min_files => 0, max_files => -1, description => 'Optional samples file for restricting samples to call on and/or defining ploidy for each sample'),
                 # sites_file => VRPipe::StepIODefinition->get(type => 'txt', min_files => 0, max_files => 1, description => 'Optional sites file for calling only at the given sites'),
             };
    }

    method body_sub {
        return sub {
            my $self = shift;
            my $options = $self->options;
            my $bcftools = $options->{bcftools_exe};
            my $view_opts = $options->{bcftools_view_options};
            
            my %samples;
            foreach my $sample_file (@{$self->inputs->{samples_files}}) {
                my $bcf = $sample_file->metadata->{source_bcf} || next;
                $samples{$bcf} = $sample_file->path;
            }
            
            my $req = $self->new_requirements(memory => 500, time => 1);
            foreach my $bcf (@{$self->inputs->{bcf_files}}) {
                my $bcf_meta = $bcf->metadata;
                my $bcf_path = $bcf->path;
                my $basename = $bcf->basename;
                $basename =~ s/bcf$/vcf.gz/;
                my $vcf_file = $self->output_file(output_key => 'vcf_files', basename => $basename, type => 'vcf', metadata => $bcf_meta);
                my $vcf_path = $vcf_file->path;
                
                my $sample_opts = '';
                if (exists $samples{$bcf_path}) {
                    $sample_opts = " -s $samples{$bcf_path}";
                }
                my $cmd = qq[$bcftools view $view_opts$sample_opts $bcf_path | bgzip -c > $vcf_path];
                $self->dispatch([$cmd, $req, {output_files => [$vcf_file]}]); 
            }
            
{'fraction_non_alphanumeric': 0.1379103282626101, 'fraction_numerical': 0.00600480384307446, 'mean_word_length': 2.1407919547454433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5609684', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1484, 'n_words': 360}