pipeline/script/fusion_targetTherapy.pl

203 lines
5.6 KiB
Perl
Raw Normal View History

2023-08-25 10:06:31 +08:00
#!/usr/bin/perl
use strict;
use warnings;
my ($codes_dir,$name,$output_dir,$project)=@ARGV;
die "useage:perl $0 codes_dir name output_dir project cancer_type" unless @ARGV==5;
open INFO,"$codes_dir/info.txt";
<INFO>;
my (@fusion,@longindel);
my $cancer_type=$ARGV[4];
while (<INFO>){
chomp;
my @line=split(/\t/,$_);
if ($line[0] eq $project){
if($line[6] ne "NA"){
@fusion=split(/\//,$line[6]);
}
if($line[7] ne "NA"){
@longindel=split(/\//,$line[7]);
}
}
}
open THERAPY,"/dataseq/jmdna/codes/reportbase/targetTherapy.txt";
my $h1=<THERAPY>;
chomp $h1;
my %therapy;
while(<THERAPY>){
chomp;
my @line=split("\t");
push @{$therapy{$line[0]}{$line[1]}},$_ if ($line[1]=~/fusion/i and $line[9] ne 'D' and $line[5] ne 'CSCO' and $line[2] !~/Leukemia|Lymphoma|Myeloid/i);
}
##药物翻译信息
open DRUG,"/dataseq/jmdna/codes/reportbase/target_drug.txt";
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];
}
}
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));
}
##疾病翻译信息
open DIS,"/dataseq/jmdna/codes/reportbase/cancer_type.txt";
my (%dis,%dis2);
<DIS>;
while(<DIS>){
chomp;
my @line=split(/\t/);
$dis{lc$line[0]}=$line[1];
push @{$dis2{$line[3]}},$line[0];
push @{$dis2{$line[4]}},$line[0];
}
if(@fusion){
open MUT, "/dataseq/jmdna/codes/reportbase/fusion.csv";
<MUT>;
my %mut;
while (<MUT>){
my @line=split(/,/);
$mut{$line[1]}{$line[0]}=$line[2];
}
open IN,"$output_dir/fusion/${name}.fusion.reanno.vcf";
open POS,">$output_dir/fusion/${name}.fusion.pos.txt";
open NEG,">$output_dir/fusion/${name}.fusion.neg.txt";
open VUS,">$output_dir/fusion/${name}.fuison.vus.txt";
my (@pos,@neg,@vus);
my $h2;
while(<IN>){
next if /^##/;
if (/^#CHROM/){
$h2=$_;
chomp $h2;
}
chomp;
my @line=split(/\t/);
if(grep{$_ eq $line[13]}@fusion or grep{$_ eq $line[14]}@fusion){
my ($gene1,$gene2,$alt)=@line[13,14,15];
if (not exists $mut{"$alt Fusion"}{$gene1} and not exists $mut{"$alt Fusion"}{$gene2}){
push @vus,"$_\t.";
}else{
my $gene=(keys %{$mut{"$alt Fusion"}})[0];
my $sig=$mut{"$alt Fusion"}{$gene};
if ($sig=~/neutral/i){
push @neg,"$_\t$sig";
}else{
if (not exists $therapy{$gene}){
push @vus,"$_\t$sig";
}else{
my $bool=0;
##
if (exists $therapy{$gene}{"$alt Fusion"}){
foreach my $entry(@{$therapy{$gene}{"$alt Fusion"}}){
my @line=split("\t",$entry);
if (($line[5] eq "FDA" or $line[5] eq "NCCN" or $line[5] eq "NMPA") and (lc$line[2] eq "solid tumor" or grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(($line[5] eq "FDA" or $line[5] eq "NCCN" or $line[5] eq "NMPA") and (lc$line[2] ne "solid tumor" and grep{lc$line[2] ne lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t非适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(lc$line[2] eq "solid tumor" or grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}}){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t\.\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}
}
}
##
if (exists $therapy{$gene}{"Fusion"}){
foreach my $entry(@{$therapy{$gene}{"Fusion"}}){
my @line=split("\t",$entry);
if (($line[5] eq "FDA" or $line[5] eq "NCCN" or $line[5] eq "NMPA") and (lc$line[2] eq "solid tumor" or grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(($line[5] eq "FDA" or $line[5] eq "NCCN" or $line[5] eq "NMPA") and (lc$line[2] ne "solid tumor" and grep{lc$line[2] ne lc$_}@{$dis2{$cancer_type}})){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t非适应症"."\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}elsif(lc$line[2] eq "solid tumor" or grep{lc$line[2] eq lc$_}@{$dis2{$cancer_type}}){
push @pos,"$_\t$sig\t".join("\t",@line[0..9,14])."\t\.\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}
}
}
push @vus,"$_\t$sig" if $bool==0;
# print "yes\n" if $bool==0;
}
}
}
}
}
my $h=$h2."\tfun_change\t".join("\t",(split("\t",$h1))[0..9,14])."\t标签\t药物中文名\t疾病中文名";
if(@pos){
print POS "$h\n";
print POS join("\n",@pos)."\n";
}
if(@neg){
print NEG $h2."\tfun_change\n";
print NEG join("\n",@neg)."\n";
}
if(@vus){
print VUS $h2."\tfun_change\n";
print VUS join("\n",@vus)."\n";
}
}
if(@longindel){
my @pos;
open LONGINDEL, ">$output_dir/fusion/${name}.longindel.pos.txt";
open IN2, "$output_dir/fusion/${name}.longindel.vcf";
my $h2;
while(<IN2>){
chomp;
next if /^##/;
if (/^#CHROM/){
$h2=$_;
next;
}
my @line=split(/\t/);
$line[7]=~/Gene.refGene=(.*?);/;
if (grep{$1=~/$_/}@longindel){
if($1 eq "BCL2L11"){
push @pos,$_ if $line[1]=='111883194';
}else{
push @pos,$_;
}
}
}
if(@pos){
print LONGINDEL "$h2\n";
print LONGINDEL join("\n",@pos)."\n";
}
}