#!/usr/bin/perl use strict; use warnings; die "usage:perl $0 germline/somatic sample_type name input_file output_file" unless @ARGV == 5; my ($type, $sample_type, $name, $input, $output) = @ARGV; open IN, $input or die "Cannot open file $input: $!"; open OUT, ">${output}"; if ($type eq "germline") { while () { if (/^##/) { print OUT; next; } elsif (/^#CHROM/) { $_ =~ s/TUMOR/$name/; print OUT; next; } else { chomp; my @line = split("\t", $_); next if $line[6] ne "PASS"; if ($sample_type eq 'c') { my $n_af = (split(":", $line[-1]))[6]; print OUT "$_\n" if $n_af >= 0.1; } else { my $n_af = (split(":", $line[-1]))[6]; my $t_af = (split(":", $line[-2]))[6]; print OUT "$_\n" if ($n_af >= 0.1 and $t_af >= 0.1); } } } } elsif ($type eq "somatic") { while () { if (/^##/) { print OUT; next; } elsif (/^#CHROM/) { $_ =~ s/TUMOR/$name/; print OUT; next; } else { chomp; my @line = split("\t", $_); next if $line[6] ne "PASS"; if ($sample_type eq 'c') { my $t_af = (split(":", $line[-1]))[6]; print OUT "$_\n" if $t_af >= 0.02; } else { my $n_af = (split(":", $line[-1]))[6]; my $t_af = (split(":", $line[-2]))[6]; print OUT "$_\n" if ($n_af < 0.02 and $t_af >= 0.05); } } } } else { die "erro type!!! somatic or germline for now" }