Perl无法打开文件;来自Ploteig剧本

时间:2014-07-22 13:38:41

标签: perl

在计算机编程和perl方面,我是一个新手,所以如果这个问题很简单,请原谅我!

我正在尝试运行一个perl脚本(称为ploteig,免费遗传程序下载的一个组件,Eigenstrat:Eigenstrat software),直到我进入第96行

open (YY, ">$dfile") || die "can't open $dfile\n" ;

我收到错误,该文件无法打开,脚本死亡。

下面,我已经为您提供了完整的代码(老实说,我不知道代码的哪一部分可能会影响无法打开文件)。该代码使用先前使用Eigenstrat创建的文件的输入,例如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分数,列特定pcas。第一列样本名称,最后一列案例或控制状态)

此外,我按如下方式调用代码:

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 ;

}

0 个答案:

没有答案