使用Notepad ++.exe的脚本问题

使用Notepad ++.exe的脚本问题

嗨,我准备了从 biostar 手册中复制的脚本。该文件以 Unix 模式 LF 保存,并保存为 sh 文件。这里是

# Accession number for the reference genome
ACC=AF086833
# SRA run number.
SRR=SRR1972739
# How many reads to extract from the dataset.
N=10000
# The reference genome in three different formats: GenBank, FASTA and GFF
GB=refs/$ACC.gb
FA=refs/$ACC.fa
GFF=refs/$ACC.gff
# Make the reference directory.
mkdir -p refs
# Get a genbank file.
efetch -db nucleotide -format=gb -id=$ACC > $GB
# Convert the GenBank file into GFF3.
cat $GB | seqret -filter -feature -osformat gff3 > $GFF
# Convert the GenBank file into FASTA.
cat $GB | seqret -filter -feature -osformat fasta > $FA
# Create an index of the FASTA file
samtools faidx $FA
# Obtain the dataset.
fastq-dump -X $N --split-files $SRR
# Index reference with bwa.
bwa index $FA
# Index the reference with samtools.
samtools faidx $FA
# Shortcuts to read names
R1=${SRR}_1.fastq
R2=${SRR}_2.fastq
# Align with bwa mem.
bwa mem $FA $R1 $R2 | samtools sort > $SRR.bwa.bam
# Index the BAM file generated with bwa.
samtools index $SRR.bwa.bam
# Index reference with bowtie2.
bowtie2-build $FA $FA
# Align the same data with bowtie2.
bowtie2 -x $FA -1 $R1 -2 $R2 | samtools sort > $SRR.bowtie.bam
# Index the BAM file produced with bowtie2.
samtools index $SRR.bowtie.bam

这些命令在 ubuntu 中都可以通过复制和粘贴来工作,但是当我尝试使用命令通过 ubuntu 打开 myscript.sh 文件时

cat myscript.sh

我收到错误权限被拒绝

然后我使用命令行

se)
asifa86@DESKTOP-012ORAQ ~
$ conda activate bioinfo
(bioinfo)
asifa86@DESKTOP-012ORAQ ~
$ cat myscript.sh
cat: myscript.sh: Permission denied
(bioinfo)
asifa86@DESKTOP-012ORAQ ~
$ sudo cat myscript.sh
[sudo] password for asifa86:
# Accession number for the reference genome
ACC=AF086833
# SRA run number.
SRR=SRR1972739
# How many reads to extract from the dataset.
N=10000
# The reference genome in three different formats: GenBank, FASTA and GFF
GB=refs/$ACC.gb
FA=refs/$ACC.fa
GFF=refs/$ACC.gff
# Make the reference directory.
mkdir -p refs
# Get a genbank file.
efetch -db nucleotide -format=gb -id=$ACC > $GB
# Convert the GenBank file into GFF3.
cat $GB | seqret -filter -feature -osformat gff3 > $GFF
# Convert the GenBank file into FASTA.
cat $GB | seqret -filter -feature -osformat fasta > $FA
# Create an index of the FASTA file
samtools faidx $FA
# Obtain the dataset.
fastq-dump -X $N --split-files $SRR
# Index reference with bwa.
bwa index $FA
# Index the reference with samtools.
samtools faidx $FA
# Shortcuts to read names
R1=${SRR}_1.fastq
R2=${SRR}_2.fastq
# Align with bwa mem.
bwa mem $FA $R1 $R2 | samtools sort > $SRR.bwa.bam
# Index the BAM file generated with bwa.
samtools index $SRR.bwa.bam
# Index reference with bowtie2.
bowtie2-build $FA $FA
# Align the same data with bowtie2.
bowtie2 -x $FA -1 $R1 -2 $R2 | samtools sort > $SRR.bowtie.bam
# Index the BAM file produced with bowtie2.
samtools index $SRR.bowtie.bam(bioinfo)
asifa86@DESKTOP-012ORAQ ~


$ sudo bash myscript.sh
myscript.sh: line 14: efetch: command not found
myscript.sh: line 16: seqret: command not found
myscript.sh: line 18: seqret: command not found
myscript.sh: line 20: samtools: command not found
myscript.sh: line 22: fastq-dump: command not found
myscript.sh: line 24: bwa: command not found
myscript.sh: line 26: samtools: command not found
myscript.sh: line 31: bwa: command not found
myscript.sh: line 31: samtools: command not found
myscript.sh: line 33: samtools: command not found
myscript.sh: line 35: bowtie2-build: command not found
myscript.sh: line 37: bowtie2: command not found
myscript.sh: line 37: samtools: command not found
myscript.sh: line 39: samtools: command not found
(bioinfo)

这些命令单独工作,但使用 bash ubuntu 脚本则不起作用。问题是我必须完成工作,如果有人能指导我如何解决这种情况,我将不胜感激

答案1

sudo使用自己的PATH定义。阅读man sudoers,其中部分内容是

By default, the env_reset option is enabled.  This causes commands to be executed with a
     new, minimal environment.  On AIX (and Linux systems without PAM), the environment is
     initialized with the contents of the /etc/environment file.  The new environment contains
     the TERM, PATH, HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables in addition
     to variables from the invoking process permitted by the env_check and env_keep options.
     This is effectively a whitelist for environment variables.  Environment variables with a
     value beginning with () are removed unless both the name and value parts are matched by
     env_keep or env_check, as they may be interpreted as functions by the bash shell.  Prior to
     version 1.8.11, such variables were always removed.

你可以用绝对路径替换每个命令。像这样找到它们:

for i in efetch seqret samtools fastq-dump bwa bowtie2-build bowtie2 ; do
    type -p $i
done

相关内容