生信求助perl
perl吧
全部回复
仅看楼主
level 1
一粒小麦g 楼主
使用perl脚本逐一提取文件中的信息,却报错文件不存在
报错文件不存在
附上代码:
use strict;
use warnings;
#use File::Basename;
use XML::Simple;
#use Data::Dumper;
my @dirs=glob("*");
open(WF,">clinical.xls") or die $!;
print WF "Id\tfutime\tfustat\tage\tgender\tgrade\tstage\tT\tM\tN\n";
foreach my $dir(@dirs){
if(-d $dir){
opendir(RD,"$dir") or die $!;
while(my $xmlfile=readdir(RD)){
if($xmlfile=~/\.xml$/){
#print "$dir\\$xmlfile\n";
my $userxs = XML::Simple->new(KeyAttr => "name");
my $userxml = $userxs->XMLin("$dir\\$xmlfile");
# print output
#open(WF,">dumper.txt") or die $!;
#print WF Dumper($userxml);
#close(WF);
my $disease_code=$userxml->{'admin:admin'}{'admin:disease_code'}{'content'}; #get disease code
my $disease_code_lc=lc($disease_code);
my $patient_key=$disease_code_lc . ':patient'; #ucec:patient
my $follow_key=$disease_code_lc . ':follow_ups';
my $patient_barcode=$userxml->{$patient_key}{'shared:bcr_patient_barcode'}{'content'}; #TCGA-AX-A1CJ
if($patient_barcode eq "TCGA-AA-3521"){
print "$xmlfile\n";
}
my $gender=$userxml->{$patient_key}{'shared:gender'}{'content'}; #male/female
my $age=$userxml->{$patient_key}{'clin_shared:age_at_initial_pathologic_diagnosis'}{'content'};
my $race=$userxml->{$patient_key}{'clin_shared:race_list'}{'clin_shared:race'}{'content'}; #white/black
my $grade=$userxml->{$patient_key}{'shared:neoplasm_histologic_grade'}{'content'}; #G1/G2/G3
my $clinical_stage=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:clinical_stage'}{'content'}; #stage I
my $clinical_T=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:clinical_categories'}{'shared_stage:clinical_T'}{'content'};
my $clinical_M=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:clinical_categories'}{'shared_stage:clinical_M'}{'content'};
my $clinical_N=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:clinical_categories'}{'shared_stage:clinical_N'}{'content'};
my $pathologic_stage=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:pathologic_stage'}{'content'}; #stage I
my $pathologic_T=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:pathologic_categories'}{'shared_stage:pathologic_T'}{'content'};
my $pathologic_M=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:pathologic_categories'}{'shared_stage:pathologic_M'}{'content'};
my $pathologic_N=$userxml->{$patient_key}{'shared_stage:stage_event'}{'shared_stage:tnm_categories'}{'shared_stage:pathologic_categories'}{'shared_stage:pathologic_N'}{'content'};
$gender=(defined $gender)?$gender:"unknow";
$age=(defined $age)?$age:"unknow";
$race=(defined $race)?$race:"unknow";
$grade=(defined $grade)?$grade:"unknow";
$clinical_stage=(defined $clinical_stage)?$clinical_stage:"unknow";
$clinical_T=(defined $clinical_T)?$clinical_T:"unknow";
$clinical_M=(defined $clinical_M)?$clinical_M:"unknow";
$clinical_N=(defined $clinical_N)?$clinical_N:"unknow";
$pathologic_stage=(defined $pathologic_stage)?$pathologic_stage:"unknow";
$pathologic_T=(defined $pathologic_T)?$pathologic_T:"unknow";
$pathologic_M=(defined $pathologic_M)?$pathologic_M:"unknow";
$pathologic_N=(defined $pathologic_N)?$pathologic_N:"unknow";
my $survivalTime="";
my $vital_status=$userxml->{$patient_key}{'clin_shared:vital_status'}{'content'};
my $followup=$userxml->{$patient_key}{'clin_shared:days_to_last_followup'}{'content'};
my $death=$userxml->{$patient_key}{'clin_shared:days_to_death'}{'content'};
if($vital_status eq 'Alive'){
$survivalTime="$followup\t0";
}
else{
$survivalTime="$death\t1";
}
for my $i(keys %{$userxml->{$patient_key}{$follow_key}}){
my @survivalArr=split(/\t/,$survivalTime);
eval{
$followup=$userxml->{$patient_key}{$follow_key}{$i}{'clin_shared:days_to_last_followup'}{'content'};
$vital_status=$userxml->{$patient_key}{$follow_key}{$i}{'clin_shared:vital_status'}{'content'};
$death=$userxml->{$patient_key}{$follow_key}{$i}{'clin_shared:days_to_death'}{'content'};
};
if($@){
$followup=$userxml->{$patient_key}{$follow_key}{$i}[0]{'clin_shared:days_to_last_followup'}{'content'};
$vital_status=$userxml->{$patient_key}{$follow_key}{$i}[0]{'clin_shared:vital_status'}{'content'};
$death=$userxml->{$patient_key}{$follow_key}{$i}[0]{'clin_shared:days_to_death'}{'content'};
}
if($vital_status eq 'Alive'){
if($followup>$survivalArr[0]){
$survivalTime="$followup\t0";
}
}
else{
if($death>$survivalArr[0]){
$survivalTime="$death\t1";
}
}
}
print WF "$patient_barcode\t$survivalTime\t$age\t$gender\t$grade\t$pathologic_stage\t$pathologic_T\t$pathologic_M\t$pathologic_N\n";
}
}
close(RD);
}
}
close(WF);
2020年03月25日 15点03分 1
level 1
一粒小麦g 楼主
卡了好几天了,求大佬救救孩子[泪][泪]
2020年03月25日 15点03分 2
同学解决了吗?
2020年12月04日 07点12分
level 12
[捂嘴笑]贴吧里面有你的同学。你们俩的脚步一模一样。前几天她才问我了
2020年03月25日 16点03分 3
level 12
哦,我知道问题了,这个脚本他写的是用在win环境下的,win环境下的目录结构是用\\
你这个mac所以目录结构是用要用 /
2020年03月26日 06点03分 4
大佬求助,能加微信,或者QQ不,一样的问题
2020年03月31日 09点03分
感谢大佬,确实在Windows下就解决了 [大拇指]
2020年03月27日 14点03分
2020年03月31日 10点03分
@HeMonseter 大佬求助,同样的代码,我生成的却是空的excel,是什么问题啊
2020年04月28日 09点04分
level 1
你是怎么安装Perl的?我安装的只有PerlCritic
2020年04月17日 07点04分 5
下个别的perl版本
2020年04月17日 14点04分
level 1
请问楼主用这个脚本提取的临床信息有没有unknow的,我的TMN分期都是unknow
2020年07月11日 00点07分 6
请问你解决了吗
2022年05月06日 14点05分
level 1
同问,解决了吗
2020年07月16日 05点07分 7
level 2
同生信 运行merge脚本出现文件夹为空 不知道怎么回事[泪][泪]
2020年10月03日 10点10分 8
解决了吗同学?
2020年12月04日 07点12分
level 1
楼楼可以把安装包给我发一份吗,我下载了好久了都没下好[泪][泪]马上就是作业ddl了呜呜
2020年10月07日 13点10分 9
level 1
兄弟加个微信啊,339672430
2021年01月03日 13点01分 10
level 4
perl问题可以加我v:
qinshimingyue986-
2021年11月21日 23点11分 11
level 4
生信perl问题可以加我v:
qinshimingyue986-
2021年11月21日 23点11分 12
level 1
友友们,生信刚入门,你们都是哪里 获取的perl的脚本啊
2023年10月25日 07点10分 14
1