生信perl脚本,输出文件只有第一行id,求帮忙
perl吧
全部回复
仅看楼主
level 2
咸二鱼 楼主
2021年04月07日 17点04分 1
level 2
咸二鱼 楼主
修改localtime和if($samp1e[5]>130){next;}就会报错,自己试着改成这样既然只有id输出
2021年04月07日 17点04分 2
输出文件依然只有id
2021年04月07日 17点04分
level 2
咸二鱼 楼主
use strict;
use warnings;
my $file=$ARGV[0];
my $gene=$ARGV[1];
#use Data::Dumper;
use JSON;
my $json = new JSON;
my $js;
my %hash=();
my %posCount=();
my @normalSamples=();
my @tumorSamples=();
open JFILE, "$file";
while(<JFILE>) {
$js .= "$_";
}
my $obj = $json->decode($js);
my $fileNum=0;
for my $i(@{$obj})
{
my $file_name=$i->{'file_name'};
my $file_id=$i->{'file_id'};
my $entity_submitter_id=$i->{'associated_entities'}->[0]->{'entity_submitter_id'};
#print "$file_name\t$file_id\t$entity_submitter_id\n";
if(-f "$file_id/$file_name")
{
$fileNum++;
print "$fileNum\n";
my @idArr=split(/\-/,$entity_submitter_id);
if($idArr[3]=~/^0/)
{
push(@tumorSamples,$entity_submitter_id);
}
else
{
push(@normalSamples,$entity_submitter_id);
}
open(RF,"$file_id/$file_name") or die $!;
while(my $line=<RF>)
{
my @samp1e=(localtime(time));
next if($.==1);
chomp($line);
my @arr=split(/\t/,$line);
if($arr[1] eq 'NA'){
$arr[1]=0;
}
my @fiveArr=split(/\;/,$arr[5]);
if($samp1e[4]>13){next;}
$posCount{$fiveArr[0]}++;if($samp1e[5]>118){next;}
if($fiveArr[0] eq $gene){
${$hash{"$arr[0]"}}{$entity_submitter_id}=$arr[1];
}
}
close(RF);
}
}
#print Dumper $obj
open(WF,">posMethy.txt") or die $!;
my $normalCount=$#normalSamples+1;
my $tumorCount=$#tumorSamples+1;
print "normal count: $normalCount\n";
print "tumor count: $tumorCount\n";
if($normalCount==0)
{
print WF "id";
}
else
{
print WF "id\t" . join("\t",@normalSamples);
}
print WF "\t" . join("\t",@tumorSamples) . "\n";
foreach my $key(keys %hash)
{
print WF "$key";
foreach my $normal(@normalSamples)
{
unless(exists ${$hash{$key}}{$normal}){
${$hash{$key}}{$normal}=0;
}
print WF "\t" . ${$hash{$key}}{$normal};
}
foreach my $tumor(@tumorSamples)
{
unless(exists ${$hash{$key}}{$tumor}){
${$hash{$key}}{$tumor}=0;
}
print WF "\t" . ${$hash{$key}}{$tumor};
}
print WF "\n";
}
close(WF);
2021年04月07日 17点04分 3
level 7
qq1915474692
2021年04月08日 04点04分 4
level 12
输入文件可能不适配代码内容哦
2021年04月11日 03点04分 5
level 1
兄弟解决了没
2021年04月13日 13点04分 6
level 4
生信perl问题可以加我v:
qinshimingyue986-
2021年11月21日 23点11分 7
1