pipeline/script/target_therapy_snpindel.pl

290 lines
12 KiB
Perl
Raw Normal View History

2023-11-01 10:09:29 +08:00
#!/usr/bin/perl
use strict;
use warnings;
2023-11-29 15:13:30 +08:00
die "useage:perl $0 input output cancer_type" unless @ARGV == 3;
2023-11-01 10:09:29 +08:00
2023-11-29 15:13:30 +08:00
my ($input, $output, $cancer_type) = @ARGV;
2023-11-01 10:09:29 +08:00
2023-11-29 15:13:30 +08:00
my $database_path = defined $ENV{'DATABASE'} ? $ENV{'DATABASE'} : "/dataseq/jmdna/codes/reportbase";
print "SnpIndel药物注释使用路径$database_path\n";
2023-11-01 10:09:29 +08:00
##将点突变信息记录到%mut
2023-11-29 15:13:30 +08:00
open MUT, "$database_path/snv_indel_mutation.csv";
2023-11-01 10:09:29 +08:00
<MUT>;
my %mut;
while (<MUT>) {
my @line = split(/,/);
$mut{$line[0]}{$line[1]} = $line[2];
}
##将用药信息记录到%therapy
2023-11-29 15:13:30 +08:00
open THERAPY, "$database_path/targetTherapy.txt";
2023-11-01 10:09:29 +08:00
my $h1 = <THERAPY>;
chomp $h1;
my %therapy;
while (<THERAPY>) {
chomp;
my @line = split("\t");
2023-11-29 15:13:30 +08:00
push @{$therapy{$line[0]}{$line[1]}}, $_ if ($line[9] ne 'D' and $line[2] !~ /Leukemia|Lymphoma|Myeloid/i);
2023-11-01 10:09:29 +08:00
}
##药物翻译信息
2023-11-29 15:13:30 +08:00
open DRUG, "$database_path/target_drug.txt";
2023-11-01 10:09:29 +08:00
my %drug;
<DRUG>;
while (<DRUG>) {
chomp;
my @line = split(/\t/);
next unless $line[1];
foreach my $drug (split(/\|/, $line[0])) {
$drug{lc $drug} = $line[1];
}
}
##疾病翻译信息
2023-11-29 15:13:30 +08:00
# 分两部分,向上匹配,和向下匹配
open DIS, "$database_path/oncotree.cancertype.20230801.txt";
2023-11-01 10:09:29 +08:00
<DIS>;
2023-11-29 15:13:30 +08:00
my (%dis, @id, %dis2);
2023-11-01 10:09:29 +08:00
while (<DIS>) {
chomp;
my @line = split(/\t/);
2023-11-29 15:13:30 +08:00
$dis{lc $line[2]} = $line[3];
$dis{lc $line[4]} = $line[5];
push @{$dis2{$line[0]}}, lc $line[2];
push @{$dis2{$line[0]}}, lc $line[4];
push @id, $line[0];
}
foreach my $ID ($cancer_type) {
my @family;
my @ids = split("", $ID);
for (my $i = 1; $i < @ids; $i = $i + 2) {
push @family, join("", @ids[0 .. $i]);
}
push @family, (grep {/^$ID/} @id);
foreach my $t (@family) {
push @{$dis2{$ID}}, @{$dis2{$t}};
}
}
foreach my $key (keys(%dis2)) {
my %uniq;
@{$dis2{$key}} = grep {++$uniq{$_} < 2} @{$dis2{$key}};
2023-11-01 10:09:29 +08:00
}
open IN, "$input";
open POS, ">$output.pos.txt";
open NEG, ">$output.neg.txt";
open VUS, ">$output.vus.txt";
my $h2 = <IN>;
chomp $h2;
2023-11-29 15:13:30 +08:00
my $h = $h2 . "\tfun_change\t" . join("\t", (split("\t", $h1))[0 .. 9, 14]) . "\tLabel\tDrugCn\tIndication";
print POS "$h\n";
print NEG $h2 . "\tfun_change\n";
print VUS $h2 . "\tfun_change\n";
my @column_names = split('\t', $h2);
2023-11-01 10:09:29 +08:00
my (@pos, @neg, @vus);
while (<IN>) {
chomp;
2023-11-29 15:13:30 +08:00
my @splitline = split("\t");
# 将数据与表头对应
my %record;
@record{@column_names} = @splitline;
2023-11-01 10:09:29 +08:00
my ($protein, $mut_type);
2023-11-29 15:13:30 +08:00
my $gene = $record{'Gene_refGene'};
if ($record{'AAChange_refGene'} =~ /(\w+):(\w+):exon(\d+):c\.(\S+):p\.(\S+)$/) {
2023-11-01 10:09:29 +08:00
my $exon = $3;
my $codon = $4;
2023-11-29 15:13:30 +08:00
if ($5 =~ /\d+X$|\d+\*$/
or $record{'ExonicFunc_refGene'} eq 'stopgain'
or $record{'ExonicFunc_refGene'} eq 'frameshift deletion'
or $record{'ExonicFunc_refGene'} eq 'frameshift insertion') {
2023-11-01 10:09:29 +08:00
$protein = 'Truncating Mutations';
}
else {
$protein = $5;
}
2023-11-29 15:13:30 +08:00
# $mut_type = ($codon =~ /del/) ? ("Exon $exon deletion") : ($codon =~ /ins/) ? ("Exon $exon insertion") : ("Exon $exon mutation");
$mut_type = ($codon =~ /del/) ? ("Exon $exon deletion") :
($codon =~ /ins/) ? ("Exon $exon insertion") :
($codon =~ /dup/) ? ("Exon $exon insertion") :
("Exon $exon mutation");
2023-11-01 10:09:29 +08:00
}
2023-11-29 15:13:30 +08:00
elsif ($record{'AAChange_refGene'} =~ /splicing/) {
2023-11-01 10:09:29 +08:00
$protein = 'Truncating Mutations';
$mut_type = '';
}
2023-11-29 15:13:30 +08:00
elsif ($record{'ExonicFunc_refGene'} =~ /skipping/) {
2023-11-01 10:09:29 +08:00
$protein = 'Exon 14 skipping Mutations';
$mut_type = '';
}
else {
print $_;
}
##若突变不存在于%mut,写入@vus,若突变存在于%mut且neutral写入@neg;若基因不存在于%therapy写入@vus;
if (not exists $mut{$gene}{$protein}) {
2023-11-29 15:13:30 +08:00
if ($record{'CLNSIG'} =~ /benign/i and $record{'CLNSIG'} !~ /sensitivity|pathogenic|uncertain|\./i and $record{'cosmic91'} ne '.') {
2023-11-01 10:09:29 +08:00
push @neg, "$_\t.";
}
else {
push @vus, "$_\t.";
}
}
else {
if ($mut{$gene}{$protein} =~ /neutral/i) {
push @neg, "$_\t$mut{$gene}{$protein}";
}
elsif ($mut{$gene}{$protein} =~ /Inconclusive/i) {
push @vus, "$_\t$mut{$gene}{$protein}";
}
else {
if (not exists $therapy{$gene}) {
2023-11-29 15:13:30 +08:00
if ($record{'CLNSIG'} =~ /benign/i and $record{'CLNSIG'} !~ /sensitivity|pathogenic|uncertain|\./i and $record{'cosmic91'} ne '.') {
2023-11-01 10:09:29 +08:00
push @neg, "$_\t$mut{$gene}{$protein}";
}
else {
push @vus, "$_\t$mut{$gene}{$protein}";
}
}
else {
my $bool = 0;
2023-11-29 15:13:30 +08:00
# 匹配 p.
2023-11-01 10:09:29 +08:00
if (exists $therapy{$gene}{$protein}) {
foreach my $entry (@{$therapy{$gene}{$protein}}) {
my @line = split("\t", $entry);
2023-11-29 15:13:30 +08:00
if (($line[14] eq 'A') and (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (($line[14] eq 'A') and (grep {lc $line[2] ne lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t非适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}}) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t\.\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
}
}
2023-11-29 15:13:30 +08:00
# 匹配 Mutation
2023-11-01 10:09:29 +08:00
if (exists $therapy{$gene}{'Mutation'}) {
foreach my $entry (@{$therapy{$gene}{'Mutation'}}) {
my @line = split("\t", $entry);
2023-11-29 15:13:30 +08:00
if (($line[14] eq 'A') and (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (($line[14] eq 'A') and (grep {lc $line[2] ne lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t非适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}}) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t\.\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
}
}
2023-11-29 15:13:30 +08:00
# 去掉最后一个字符 例如V600E 去掉之后 V600再去匹配
2023-11-01 10:09:29 +08:00
if ($protein =~ /^(\w\d+)\w$/ and exists $therapy{$gene}{$1}) {
foreach my $entry (@{$therapy{$gene}{$1}}) {
my @line = split("\t", $entry);
2023-11-29 15:13:30 +08:00
if (($line[14] eq 'A') and (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (($line[14] eq 'A') and (grep {lc $line[2] ne lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t非适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}}) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t\.\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
}
}
2023-11-29 15:13:30 +08:00
# 去掉最后一个字符 加上“.X”去匹配
2023-11-01 10:09:29 +08:00
if ($protein =~ /^(\w\d+)\w$/ and exists $therapy{$gene}{$1 . "X"}) {
foreach my $entry (@{$therapy{$gene}{$1 . "X"}}) {
my @line = split("\t", $entry);
2023-11-29 15:13:30 +08:00
if (($line[14] eq 'A') and (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (($line[14] eq 'A') and (grep {lc $line[2] ne lc $_} @{$dis2{$cancer_type}})) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t非适应症" . "\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
2023-11-29 15:13:30 +08:00
elsif (grep {lc $line[2] eq lc $_} @{$dis2{$cancer_type}}) {
2023-11-01 10:09:29 +08:00
push @pos, "$_\t$mut{$gene}{$protein}\t" . join("\t", @line[0 .. 9, 14]) . "\t\.\t" . &drug($line[3]) . "\t" . $dis{lc $line[2]};
$bool = 1;
}
}
}
2023-11-29 15:13:30 +08:00
# 外显子 模式去匹配
2023-11-01 10:09:29 +08:00
if (exists $therapy{$gene}{$mut_type}) {
2023-11-29 15:13:30 +08:00
foreach my $entry(@{$therapy{$gene}{$mut_type}}){
my @line=split("\t",$entry);
if (($line[14] eq 'A') and (grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$mut{$gene}{$protein}\t".join("\t",@line[0..9,14])."\t适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(($line[14] eq 'A') and (grep{lc$line[2] ne lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$mut{$gene}{$protein}\t".join("\t",@line[0..9,14])."\t非适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}}){
push @pos,"$_\t$mut{$gene}{$protein}\t".join("\t",@line[0..9,14])."\t\.\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}
}
2023-11-01 10:09:29 +08:00
}
2023-11-29 15:13:30 +08:00
# 没有匹配上
2023-11-01 10:09:29 +08:00
if ($bool == 0) {
2023-11-29 15:13:30 +08:00
if ($record{'CLNSIG'} =~ /benign/i and $record{'CLNSIG'} !~ /sensitivity|pathogenic|uncertain|\./i and $record{'cosmic91'} ne '.') {
2023-11-01 10:09:29 +08:00
push @neg, "$_\t$mut{$gene}{$protein}";
}
else {
push @vus, "$_\t$mut{$gene}{$protein}";
}
}
}
}
}
}
sub drug {
my $drugs = shift @_;
my @translation;
foreach my $drug (split(/,/, $drugs)) {
if ($drug =~ /\+/) {
my $plus;
foreach my $drug_c (split(/\s+\+\s+/, $drug)) {
my $new = (exists $drug{lc $drug_c}) ? $drug{lc $drug_c} : ($drug_c);
$plus .= " + $new";
}
$plus =~ s/^ \+ //;
push @translation, $plus;
}
else {
my $new = (exists $drug{lc $drug}) ? $drug{lc $drug} : ($drug);
push @translation, $new;
}
}
return (join(",", @translation));
}
if (@pos) {
print POS join("\n", @pos) . "\n";
}
if (@neg) {
print NEG join("\n", @neg) . "\n";
}
if (@vus) {
print VUS join("\n", @vus) . "\n";
}