fastsSructure的安装及使用介绍

来源:生信百科1 5,349

本期我将介绍一下非 root 用户如何安装 Python 的包以及群体遗传结构分析常用软件 fastStructure 的安装和使用。

非 root 用户安装 Python 的包

非 root 用户安装 Python 包有很多办法,本期我主要介绍如何在不重新安装 Python 的情况下 (使用集群自带的 python) 安装自己需要的包,相信熟悉 Python 的小伙伴可能已经猜到了——使用 pip,pip 是一种比较简单的安装 Python 包的方法;更高级的方法,比如想同时拥有不同版本的 Python,更简单的安装与管理 Python 的包,则推荐使用 anaconda。

1 下载并配置 pip

cd $HOME/software

wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user

mv ${HOME}/.local/bin/* ${HOME}/software/bin

 

将 ${HOME}/.local/bin/* 下的所有应用程序直接移到  ${HOME}/software/bin 目录下,则可以直接调用 pip 命令而不需要指定其所在路径。因为,在上一期的博文里,我们已经将 bin 目录写入环境变量 PATH 中了。

如果集群上已经安装了 pip,则可以忽略上面的步骤,直接进行下面的操作。

2 配置环境变量

export PYTHONPATH="${HOME}/.local/lib/python2.7/site-packages:${PYTHONPATH}"

 

使用 vim 或者 nano 编辑 ~/.bash_profile, 添加上面一行内容。

我使用的集群安装的是 2.7 版本的 Python,如果版本与我的不同请替换上述命令中 'python2.7' 处的版本号。

现在我们可以尽情的安装我们所需要的包了,我这次只安装 fastStructure 软件需要的几个包:Cython, Scipy , matplotlib 以及 Numpy。

3 安装需要的软件包

pip install Cython --user

pip install Scipy --user

pip install Numpy --user

pip install matplotlib --user

 

matplotlib 这个包在 fastStructure 网站上并没有提到是必须要装的,但 distruct.py 命令需要用到这个包,我们可以在这里提前准备好。

安装 fastStructure 依赖的 GNU Scientific Library

1 下载并解压 gsl

cd $HOME/software

wget http://ftp.acc.umu.se/mirror/gnu.org/gnu/gsl/gsl-latest.tar.gz

tar -zxvf gsl-latest.tar.gz

rm gsl-latest.tar.gz

mkdir $HOME/software/gsl

 

2 编译 gsl

cd gsl-2.3/

./configure --prefix=$HOME/software/gsl/

make

make check

make install

cd ..

rm -rf gsl-2.3

 

这个软件的安装时间有点久 (20-25分钟),可以先去泡杯茶或者喝杯咖啡,回来以后继续安装目的软件: fastStructure。

安装 fastStructure

1 下载并解压 fastStructure 软件包

wget --no-check-certificate https://github.com/rajanil/fastStructure/archive/master.tar.gz

tar -zxvf master.tar.gz

rm master.tar.gz

 

2 配置安装软件所需的环境变量

将下面的三行写入 ~/.bash_profile 之后,执行 source ~/.bash_profile,使环境变量配置生效。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/software/gsl/lib

export CFLAGS="-I$HOME/software/gsl/include"

export LDFLAGS="-L$HOME/software/gsl/lib"

 

3 编译 fastStructure

cd fastStructure-master/

python setup.py build_ext --inplace

cd vars/

python setup.py build_ext --inplace

cd ..

 

进行到这里,网站上的教程就结束了,但软件的使用方式为 python /path/to/fastStructure/structure.py + 参数,不是很方便。我们可以经过进一步设置,直接调用这些命令。

4 进一步优化设置,直接调用这些命令

首先运行下面的命令,使这些脚本变为可执行文件

chmod +x chooseK.py distruct.py structure.py

 

然后运行 which python, 将 #! 以及得到的运行结果合在一起,分别写入以上三个文件的第一行。

假如你用的 python 是系统默认的,运行 which python 得到的结果可能是:/usr/bin/python

然后你需要将 #!/usr/bin/python 分别写入chooseK.py, distruct.py 和 structure.py 文件的第一行。

最后,我们需要将这三个程序所在的目录写入环境变量。编辑 ~/.bash_profile, 加入下面的一行命令后,source ~/.bash_profile 使配置生效。

export PATH=$PATH:$HOME/software/fastStructure-master

 

至此,fastStructure 软件的安装就彻底完成了,我们现在可以在任何目录直接运行 chooseK.py, distruct.py 和 structure.py 这三个脚本了。简单来说:structure.py 用来计算不同的 K 值得到结果, chooseK.py 用来得到最优 K 值的范围,distruct.py 用来展现不同 K 值的分组结果。

    • lxy1554 0

      running build_ext
      skipping ‘utils.c’ Cython extension (up-to-date)
      Compiling allelefreq.pyx because it changed.
      Compiling marglikehood.pyx because it changed.
      [1/2] Cythonizing allelefreq.pyx
      /home/LinXG/miniconda3/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: ./allelefreq.pxd
      tree = Parsing.p_module(s, pxd, full_module_name)

      Error compiling Cython file:
      ————————————————————

      # use an iterative fixed-point solver to update parameter estimates.
      var_beta, var_gamma = self._unconstrained_solver(Dvarbeta, Dvargamma)

      # if a variable violates positivity constraint,
      # set it to an estimate from the previous update
      bad_beta = reduce(utils.OR,[(var_beta<=0),np.isnan(var_beta)])
      ^
      ————————————————————

      allelefreq.pyx:148:19: undeclared name not builtin: reduce
      Traceback (most recent call last):
      File "setup.py", line 25, in
      ext_modules = cythonize(ext_modules)
      File “/home/LinXG/miniconda3/lib/python3.7/site-packages/Cython/Build/Dependencies.py”, line 1101, in cythonize
      cythonize_one(*args)
      File “/home/LinXG/miniconda3/lib/python3.7/site-packages/Cython/Build/Dependencies.py”, line 1224, in cythonize_one
      raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: allelefreq.pyx

      您好请问我再构建扩展库的时候出现这个是什么原因?

    发表评论

    匿名网友