Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl无法打开文件;从绘图脚本_Perl - Fatal编程技术网

Perl无法打开文件;从绘图脚本

Perl无法打开文件;从绘图脚本,perl,Perl,说到计算机编程和perl,我完全是个新手,所以如果这个问题很简单,请原谅我 我正在尝试运行一个perl脚本(称为ploteig,是免费遗传学程序下载的一个组件,Egenestrat:),在我到达第96行之前,该脚本运行良好- open (YY, ">$dfile") || die "can't open $dfile\n" ; 我得到的错误是,文件无法打开,脚本死亡 下面,我为您提供了完整的代码(老实说,我不知道代码的哪一部分会影响无法打开文件)。代码使用先前使用Egenstrat创建的

说到计算机编程和perl,我完全是个新手,所以如果这个问题很简单,请原谅我

我正在尝试运行一个perl脚本(称为ploteig,是免费遗传学程序下载的一个组件,Egenestrat:),在我到达第96行之前,该脚本运行良好-

open (YY, ">$dfile") || die "can't open $dfile\n" ;
我得到的错误是,文件无法打开,脚本死亡

下面,我为您提供了完整的代码(老实说,我不知道代码的哪一部分会影响无法打开文件)。代码使用先前使用Egenstrat创建的文件的输入,例如4行12列:

#eigvals:    20.388     7.503     4.033     2.929     2.822     2.726     2.700     2.590     2.451     2.365 
GREY_BI_011_COMSTOCK_11     0.0164      0.0164      0.0382     -0.1283     -0.0658      0.0406      0.0322      0.0105     -0.0851     -0.0625             Case
GREY_BI_014_COMSTOCK_14     0.0191      0.0094      0.0567     -0.0250      0.0804     -0.0531     -0.0165      0.0321      0.1130     -0.0025          Control
GREY_BI_015_COMSTOCK_15     0.0221     -0.0042     -0.0031      0.0091      0.1448      0.0351      0.0430      0.0359      0.0049      0.0791          Control
(行表示单个样本pca分数、特定于列的pca。第一列样本名称、最后一列案例或控制状态)

此外,我调用代码如下:

perl ploteig –i combogreyout.pca.evec –p Case:Control –s Out –c 1:2 –x –o utploteig.xtxt –k 
我真的不知道该从这里走到哪里。我尝试更改文件权限并确保它位于工作目录中,但它不允许我更改权限以及指向正确目录的所有内容。然而,我不确定这两个问题是否是真正的问题

我将非常感谢任何人能给我的任何帮助! 非常感谢你

> #!/usr/bin/perl  -w 

### ploteig -i eigfile -p pops -c a:b [-t title] [-s stem] [-o outfile] [-x] [-k]  [-y] 
[-z sep]   [-f fixgreen]
use Getopt::Std ;
use File::Basename ;

## pops : separated  -x = make postscript and pdf  -z use another separator
##  -k keep intermediate files
## NEW if pops is a file names are read one per line

getopts('i:o:p:c:s:d:z:t:xkyf',\%opts) ;
$postscmode = $opts{"x"} ;
$oldkeystyle =  $opts{"y"} ;
$kflag = $opts{"k"} ;
$keepflag = 1 if ($kflag) ;
$keepflag = 1 unless ($postscmode) ;
$dofixgreen = ( exists $opts{"f"} ? $opts{"f"} : 0 );

$zsep = ":" ;
if (defined $opts{"z"}) {
 $zsep = $opts{"z"} ;
 $zsep = "\+" if ($zsep eq "+") ;
}

$title = "" ;
if (defined $opts{"t"}) {
 $title = $opts{"t"} ;
}
if (defined $opts{"i"}) {
 $infile = $opts{"i"} ;
}
else {
 usage() ;
 exit 0 ;
}
open (FF, $infile) || die "can't open $infile\n" ;
@L = (<FF>) ;
chomp @L ;
$nf = 0 ;
foreach $line (@L) { 
 next if ($line =~ /\#/) ;
 @Z = split " ", $line ;
 $x = @Z ;
 $nf = $x if ($nf < $x) ;
}
printf "## number of fields: %d\n", $nf ;
$popcol = $nf-1 ;


if (defined $opts{"p"}) {
 $pops = $opts{"p"} ;
}
else {
 die "p parameter compulsory\n" ;
}

$popsname = setpops ($pops) ;
print "$popsname\n" ;

$c1 = 1; $c2 =2 ;
if (defined $opts{"c"}) {
 $cols = $opts{"c"} ;
 ($c1, $c2) = split ":", $cols ;
 die "bad c param: $cols\n" unless (defined $cols) ;
}

$stem = "$infile.$c1:$c2" ;
if (defined $opts{"s"}) {
 $stem = $opts{"s"} ;
}
$gnfile = "$stem.$popsname.xtxt" ;

if (defined $opts{"o"}) {
 $gnfile = $opts{"o"} ;
}


@T = () ; ## trash 
open (GG, ">$gnfile") || die "can't open $gnfile\n" ;
print GG "## " unless ($postscmode) ;
print GG "set terminal postscript color\n" ;
print GG "set title  \"$title\" \n" ; 
print GG "set key outside\n" unless ($oldkeystyle) ; 
print GG "set xlabel  \"eigenvector $c1\" \n" ; 
print GG "set ylabel  \"eigenvector $c2\" \n" ; 
print GG "plot " ;
$np = @P ;
$lastpop = $P[$np-1] ;
$d1 = $c1+1 ;
$d2 = $c2+1 ;
foreach $pop (@P)  { 
 $dfile = "$stem:$pop" ;
 push @T, $dfile ;
 print GG " \"$dfile\" using $d1:$d2 title \"$pop\" " ;
 print GG ", \\\n" unless ($pop eq $lastpop) ;
  chomp $dfile;
 open (YY, ">$dfile") || die "can't open $dfile\n" ;
 foreach $line (@L) {
  next if ($line =~ /\#/) ;
  @Z = split " ", $line ;
  next unless (defined $Z[$popcol]) ;
  next unless ($Z[$popcol] eq $pop) ;
  print YY "$line\n" ;
 }
 close YY ;
}
print GG "\n" ;
print GG "## "  if ($postscmode) ;
print GG "pause 9999\n"  ;
close GG ;

if ($postscmode) { 
$psfile = "$stem.ps" ;

 if ($gnfile =~ /xtxt/) { 
  $psfile = $gnfile ;
  $psfile  =~ s/xtxt/ps/ ;
 }
system "gnuplot < $gnfile > $psfile" ;
if ( $dofixgreen )  {
  system "fixgreen  $psfile" ;
}
system "ps2pdf  $psfile " ;
}
unlink (@T) unless $keepflag ;

sub usage { 

print "ploteig -i eigfile -p pops -c a:b [-t title] [-s stem] [-o outfile] [-x] [-k]\n" ;  
print "-i eigfile     input file first col indiv-id last col population\n" ;
print "## as output by smartpca in outputvecs \n" ;
print "-c a:b         a, b columns to plot.  1:2 would be common and leading 2 eigenvectors\n" ;
print "-p pops        Populations to plot.  : delimited.   eg  -p Bantu:San:French\n" ;
print "## pops can also be a filename.  List populations 1 per line\n" ;
print "[-s stem]      stem will start various output files\n"  ;
print "[-o ofile]     ofile will be gnuplot control file.  Should have xtxt suffix\n"; 
print "[-x]           make ps and pdf files\n" ; 
print "[-k]           keep various intermediate files although  -x set\n" ;
print "## necessary if .xtxt file is to be hand edited\n" ;
print "[-y]           put key at top right inside box (old mode)\n" ;
print "[-t]           title (legend)\n" ;
print "[-f]           fix green and yellow colors\n";

print "The xtxt file is a gnuplot file and can be easily hand edited.  Intermediate files
needed if you want to make your own plot\n" ;

}
sub setpops {      
 my ($pops) = @_  ; 
 local (@a, $d, $b, $e) ; 

 if (-e $pops) {  
  open (FF1, $pops) || die "can't open $pops\n" ;
  @P = () ;
  foreach $line (<FF1>) { 
  ($a) = split " ", $line ;
  next unless (defined $a) ;
  next if ($a =~ /\#/) ;
  push  @P, $a ;
  }
  $out = join ":", @P ; 
  print "## pops: $out\n" ;
  ($b, $d , $e) = fileparse($pops) ;
  return $b ;
 }
 @P = split $zsep, $pops ;
 return $pops ;

}
#/usr/bin/perl-w
###绘图-i eigfile-p pops-c a:b[-t标题][s干][o输出文件][x][-k][-y]
[-z sep][f固定绿色]
使用Getopt::Std;
使用File::Basename;
##pops:separated-x=使postscript和pdf-z使用另一个分隔符
##-k保留中间文件
##如果pops是新文件,则每行读取一个文件名
getopts('i:o:p:c:s:d:z:t:xkyf',\%opts);
$postscmode=$opts{“x”};
$oldkeystyle=$opts{“y”};
$kflag=$opts{“k”};
$keepflag=1,如果($kflag);
$keepflag=1,除非($postscmode);
$dofixgreen=(存在$opts{“f”}?$opts{“f”}:0);
$zsep=“:”;
if(定义为$opts{“z”}){
$zsep=$opts{“z”};
$zsep=“\+”如果($zsep eq“+”);
}
$title=“”;
if(定义为$opts{“t”}){
$title=$opts{“t”};
}
if(定义为$opts{“i”}){
$infle=$opts{“i”};
}
否则{
用法();
出口0;
}
打开(FF,$infle)| |死“无法打开$infle\n”;
@L=();
chomp@L;
$nf=0;
foreach$行(@L){
下一个if($line=~/\\\\/);
@Z=分割线;
$x=@Z;
$nf=$x如果($nf<$x);
}
printf“##字段数:%d\n”,$nf;
$popcol=$nf-1;
if(定义为$opts{“p”}){
$pops=$opts{“p”};
}
否则{
模具“p参数强制\n”;
}
$popsname=setpops($pops);
打印“$popsname\n”;
$c1=1$c2=2;
if(定义为$opts{“c”}){
$cols=$opts{“c”};
($c1,$c2)=拆分“,$cols;
死“坏c参数:$cols\n”,除非(定义为$cols);
}
$stem=“$infile.$c1:$c2”;
if(定义为$opts{“s”}){
$stem=$opts{“s”};
}
$gnfile=“$stem.$popsname.xtxt”;
if(定义为$opts{“o”}){
$gnfile=$opts{“o”};
}
@T=()###废物
打开(GG,“>$gnfile”)| | die“无法打开$gnfile\n”;
除非($postscmode),否则打印GG“##”;
打印GG“设置终端postscript颜色\n”;
打印GG“设置标题\”$title\“\n”;
除非($oldkeystyle),否则打印GG“设置密钥外部\n”;
打印GG“set xlabel\”特征向量$c1\“\n”;
打印GG“set ylabel\”特征向量$c2\“\n”;
打印GG“绘图”;
$np=@P;
$lastpop=$P[$np-1];
$d1=$c1+1;
$d2=$c2+1;
foreach$pop(@P){
$dfile=“$stem:$pop”;
按@T,$d文件;
使用$d1:$d2标题“$pop”打印GG“\”$dfile\”;
打印GG“,\\\n”,除非($pop eq$lastpop);
咀嚼$dfile;
打开(YY,“>$dfile”)| |死亡“无法打开$dfile\n”;
foreach$行(@L){
下一个if($line=~/\\\\/);
@Z=分割线;
下一个除非(定义为$Z[$popcol]);
下一个除非($Z[$popcol]eq$pop);
打印YY“$line\n”;
}
关闭YY;
}
打印GG“\n”;
如果($postscmode),则打印GG“##”;
打印GG“暂停9999\n”;
关闭GG;
如果($postscmode){
$psfile=“$stem.ps”;
如果($gnfile=~/xtxt/){
$psfile=$gnfile;
$psfile=~s/xtxt/ps/;
}
系统“gnuplot<$gnfile>$psfile”;
如果($dofixgreen){
系统“fixgreen$psfile”;
}
系统“ps2pdf$psfile”;
}
除非$keepflag,否则取消链接(@T);
子用法{
打印“ploteig-i eigfile-p pops-c a:b[-t title][s stem][o outfile][x][k]\n”;
打印“-i eigfile输入文件第一列索引id最后一列填充\n”;
打印“##作为smartpca在outputvecs中的输出\n”;
打印“-c a:b a,b列以进行绘图。1:2为公共值,前导2个特征向量\n”;
打印“-p”要绘图的区域:分隔。例如-p Bantu:San:French\n”;
打印“##pops也可以是文件名。列出每行1个\n”;
打印“[-s stem]stem将启动各种输出文件\n”;
打印“[-o ofile]ofile将是gnuplot控制文件。应具有XTXTXT后缀\n”;
打印“[-x]制作ps和pdf文件\n”;
打印“[-k]保留各种中间文件,尽管-x集合\n”;
打印“##如果要手动编辑.xtxt文件,则需要\n”;
打印“[-y]将键放在框的右上角(旧模式)\n”;
打印“[-t]标题(图例)\n”;
打印“[-f]固定绿色和黄色\n”;
打印“xtxt文件是一个gnuplot文件,可以很容易地手工编辑。中间文件
如果要制作自己的绘图,则需要\n“;
}
子集合{
我的($pops)=@;
本地(@a,$d,$b,$e);
如果(-e$pops){
打开(FF1,$pops)|死亡“无法打开$pops\n”;
@P=();
foreach$line(){
($a)=拆分“,”行;
下一个除非(定义为$a);
下一个if($a=~/\\\\/);
按@P$a;
}
$out=join:“,@P;
打印“##pops:$out\n”;
($b,$d,$e)=文件解析($pops);
返回$b;
}
@P=分割$zsep,$pops;
返回$pops;
}

为了让@toolic说的更清楚,请将该行更改为:
open(YY,“>$dfile”)| | die“无法打开$dfile:$!\n”,您将得到一些关于为什么无法打开文件的提示。谢谢toolic和@leeft。当我将行更改为open(YY,“>$dfile”)| | die“无法打开$dfile:$!\n”时得到的结果;是错误消息“没有这样的文件或目录”。我确实尝试过使用-d和-e标志