<commit_before>use VRPipe::Base;

#Example VariantFiltration command - GATK v1.3
#java -Xmx2g -jar GenomeAnalysisTK.jar \
#   -R ref.fasta \
#   -T VariantFiltration \
#   -o output.vcf \
#   --variant input.vcf \	# version 1.3+
#   --filterExpression "AB < 0.2 || MQ0 > 50" \
#   --filterName "Nov09filters" \
#   --mask mask.vcf \
#   --maskName InDel

class VRPipe::Steps::gatk_variant_filter extends VRPipe::Steps::gatk {
    around options_definition {
        return { %{$self->$orig},
                 reference_fasta => VRPipe::StepOption->get(description => 'absolute path to reference genome fasta'),
                 var_filter_opts => VRPipe::StepOption->get(description => 'options for GATK VariantFiltration, excluding reference genome, input and output'),
               };
    }

    method inputs_definition {
        return { vcf_files => VRPipe::StepIODefinition->get(type => 'bin', max_files => -1, description => 'one or more tabixed vcf files for hard-filtering variant calls'),
		};
    }

    method body_sub {
        return sub {
            use VRPipe::Utils::gatk;
            
            my $self = shift;
            my $options = $self->options;
            my $gatk = VRPipe::Utils::gatk->new(gatk_path => $options->{gatk_path}, java_exe => $options->{java_exe});
            
            my $var_filter_opts = $options->{var_filter_opts};
			my $reference_fasta = $options->{reference_fasta};

            my $req = $self->new_requirements(memory => 1200, time => 1);
            my $jvm_args = $gatk->jvm_args($req->memory);

            foreach my $vcf (@{$self->inputs->{vcf_files}}) {
                my $vcf_path = $vcf->path;
				my $basename = $vcf->basename;
				if ($basename =~ /\.vcf.gz$/) {
					$basename =~ s/\.vcf.gz$/.filt.vcf.gz/;
				}
				else {
					$basename =~ s/\.vcf$/.filt.vcf/;
				}

				my $vcf_filt_file = $self->output_file(output_key => 'filtered_vcf_files', basename => $basename, type => 'vcf');
				my $vcf_filt_path = $vcf_filt_file->path;

				my $cmd = $gatk->java_exe.qq[ $jvm_args -jar ].$gatk->jar.qq[ -T VariantFiltration -R $reference_fasta --variant $vcf_path -o $vcf_filt_path $var_filter_opts ];
				$self->warn($cmd);
				$self->dispatch([$cmd, $req, {output_files => [$vcf_filt_file]}]); 
			}
        };
    }<commit_msg>remove debug cmd<commit_after>use VRPipe::Base;

#Example VariantFiltration command - GATK v1.3
#java -Xmx2g -jar GenomeAnalysisTK.jar \
#   -R ref.fasta \
#   -T VariantFiltration \
#   -o output.vcf \
#   --variant input.vcf \
#   --filterExpression "AB < 0.2 || MQ0 > 50" \
#   --filterName "Nov09filters" \
#   --mask mask.vcf \
#   --maskName InDel

class VRPipe::Steps::gatk_variant_filter extends VRPipe::Steps::gatk {
    around options_definition {
        return { %{$self->$orig},
                 reference_fasta => VRPipe::StepOption->get(description => 'absolute path to reference genome fasta'),
                 var_filter_opts => VRPipe::StepOption->get(description => 'options for GATK VariantFiltration, excluding reference genome, input and output'),
               };
    }

    method inputs_definition {
        return { vcf_files => VRPipe::StepIODefinition->get(type => 'bin', max_files => -1, description => 'one or more tabixed vcf files for hard-filtering variant calls'),
		};
    }

    method body_sub {
        return sub {
            use VRPipe::Utils::gatk;
            
            my $self = shift;
            my $options = $self->options;
            my $gatk = VRPipe::Utils::gatk->new(gatk_path => $options->{gatk_path}, java_exe => $options->{java_exe});
            
            my $var_filter_opts = $options->{var_filter_opts};
			my $reference_fasta = $options->{reference_fasta};

            my $req = $self->new_requirements(memory => 1200, time => 1);
            my $jvm_args = $gatk->jvm_args($req->memory);

            foreach my $vcf (@{$self->inputs->{vcf_files}}) {
                my $vcf_path = $vcf->path;
				my $basename = $vcf->basename;
				if ($basename =~ /\.vcf.gz$/) {
					$basename =~ s/\.vcf.gz$/.filt.vcf.gz/;
				}
				else {
					$basename =~ s/\.vcf$/.filt.vcf/;
				}

				my $vcf_filt_file = $self->output_file(output_key => 'filtered_vcf_files', basename => $basename, type => 'vcf');
				my $vcf_filt_path = $vcf_filt_file->path;

				my $cmd = $gatk->java_exe.qq[ $jvm_args -jar ].$gatk->jar.qq[ -T VariantFiltration -R $reference_fasta --variant $vcf_path -o $vcf_filt_path $var_filter_opts ];
#				$self->warn($cmd);
				$self->dispatch([$cmd, $req, {output_files => [$vcf_filt_file]}]); 
			}
        };
    }
{'fraction_non_alphanumeric': 0.1601741022850925, 'fraction_numerical': 0.007399347116430903, 'mean_word_length': 2.5655546935609, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '1073772', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1626, 'n_words': 322}