pipeline/script/cnv_targetTherapy.pl

136 lines
4.7 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 THERAPY,"/dataseq/jmdna/codes/reportbase/targetTherapy.txt";
my $h1=<THERAPY>;
chomp $h1;
my %therapy;
my $cancer_type=$ARGV[4];
while(<THERAPY>){
chomp;
my @line=split("\t");
push @{$therapy{$line[0]}{$line[1]}},$_ if (($line[1] eq "Deletion" or $line[1] eq "Amplification") 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];
}
open INFO,"$codes_dir/info.txt";
<INFO>;
while (<INFO>){
chomp;
my @line=split(/\t/,$_);
if ($line[0] eq $project){
if($line[5] ne "NA"){
my @cnv_target=split(/\//,$line[5]);
open POS,">$output_dir/cnvkit/${name}.cnv.pos.txt";
open VUS,">$output_dir/cnvkit/${name}.cnv.vus.txt";
my (@pos,@vus,@cnv_detected);
open IN,"$output_dir/cnvkit/${name}.rmdup.cns";
my $h2=<IN>;
chomp $h2;
while(<IN>){
chomp;
my @line2=split(/\t/);
my @cnv_detected=split(/,/,$line2[3]);
my %uniq;
foreach my $cnv_detected(@cnv_detected){
$uniq{$cnv_detected}++;
next if $uniq{$cnv_detected}>1;
if (grep{$cnv_detected eq $_}@cnv_target){
my $bool=0;
my $cn=sprintf("%.1f",2**(1+$line2[4]));
if($cn>=4 and exists $therapy{$cnv_detected}{'Amplification'}){
foreach my $entry(@{$therapy{$cnv_detected}{'Amplification'}}){
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$cn\tOncogenic\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$cn\tOncogenic\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$cn\tOncogenic\t".join("\t",@line[0..9,14])."\t\.\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}
}
}elsif($cn==0 and exists $therapy{$cnv_detected}{'Deletion'}){
foreach my $entry(@{$therapy{$cnv_detected}{'Deletion'}}){
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$cn\tOncogenic\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$cn\tOncogenic\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$cn\tOncogenic\t".join("\t",@line[0..9,14])."\t\.\t".&drug($line[3])."\t".$dis{lc$line[2]};$bool=1;
}
}
}else{
push @vus,"$_\t$cn\t.";
}
if($bool==0){
push @vus,"$_\t$cn\t.";
}
}
}
}
if(@pos){
my $h=$h2."\tcn\tfun_change\t".join("\t",(split("\t",$h1))[0..9,14])."\t标签\t药物中文名\t疾病中文名";
print POS "$h\n";
print POS join("\n",@pos)."\n";
}
if(@vus){
print VUS $h2."\tcn\tfun_change\n";
print VUS join("\n",@vus)."\n";
}
}
}
}