我有几个 .pdb 文件需要处理,以便从中检索现成可用的值。我制作了一个 bash 脚本来尝试将所有命令组合在一起。
我关于这个脚本的具体问题有两个:
我尝试通过键入/输入 ./myscript.bash 在 Ubuntu 命令行上的 bash 中运行脚本后,我的脚本卡住了,并且它没有将所需的文件输出到文件夹。我的脚本中有什么错误可能导致此卡住?
在最后的命令中,
grep 'model*' $file >> $file"-confscore".txt #command to keep only the 1-5 lines from each dir I want to keep that contain this full format " model1 -5.00 0.21+-0.05 19.9+-1.8 404 0.003 " then >> combinedcscore.txt #Then reformat it to just "$dir model1 -5.00" >> newcombcscore.txt
我不知道如何在 bash 中编写此命令。您在开头看到的 grep 会将包含任何模型*文本的行打印到名为 $file___.txt 的文件中。我需要特定格式的文件,我将其包含在 grep 下面的 #'d 行中。我正在考虑使用:
for files in $dirs; do awk -F':' ' { print $dir model* firstvalueidk? }' >> newcombcscore.txt
我对 awk 的使用正确吗?
完整脚本供引用:
#! /usr/bin/env bash
#Step 0 - Set up variables & navigate to app. directory
set GETLOCATION = "~/Desktop/DCompartment/RolandoHT_Scripts/Perl_Scripts"
set GETNAME = "get_right_pdb_format.pl"
set SSLOCATION = "~/Desktop/DCompartment/RolandoHT_Scripts/Perl_Scripts"
set SSNAME = "get_ss_dssp_itasser.pl"
set PROTALOCATION = "~/Desktop/protAlign-master/"
set dirs = ~/Videos/Proteins/*
#Step 1 - Process PDB for readily available values
for dir in $dirs; do
rm `cscore|model*.pdb|seq.fasta`
done
for dir in $dirs; do
for file in *.pdb; do
perl $GETLOCATION/$GETNAME $file
dssp -i $file"-fix" -o $file.dssp
perl $SSLOCATION/$SSNAME $file.dssp $file"-out"
done
for file in $dirs/*.dssp; do
grep 'ACCESSIBLE SURFACE OF PROTEIN' $file >> $file"-SASA".txt
done
for file in $dirs/*.txt; do
echo "$file `cat $file`" >> $dir-combinedSASAs.txt
done
done
#Step 2 - Set up tool
for dir in $dirs; do
./$PROTALOCATION/initialize.sh
source $PROTALOCATION/bin/activate
done
#Step 3 - Start analyzing files
for dir in $dirs; do
for file in *.pdb; do
./$PROTALOCATION/program_name.py $dir $dir/native.pdb $dir-SPAR
done
done
for file in $dirs/data; do
set filerep = native-*.txt
grep 'TM-score' $filerep >> combinedreports.txt
awk 'FNR%2' combinedreports.txt > newcombinedrep.txt
done
for dir in $dirs; do
for file in cscore; do
grep 'model*' $file >> $file"-confscore".txt
#command to keep only the 1-5 lines from each dir I want to keep that contain this full format " model1 -5.00 0.21+-0.05 19.9+-1.8 404 0.003 " then >> combinedcscore.txt
#Then reformat it to just "$dir model1 -5.00" >> newcombcscore.txt
done
done
最佳答案
我认为您的脚本正在卡住,因为您的所有变量都是空的,并且 grep
之类的命令在 STDIN 上阻塞!我快速清理了您的脚本并添加了一些我认为您可能需要的代码(以“GLR”注释为前缀)。研究这个,它应该会让你更接近。
#!/bin/bash
# Step 0 - Set up variables & navigate to app. directory
GETLOCATION=~/Desktop/DCompartment/RolandoHT_Scripts/Perl_Scripts
GETNAME=get_right_pdb_format.pl
SSLOCATION=~/Desktop/DCompartment/RolandoHT_Scripts/Perl_Scripts
SSNAME=get_ss_dssp_itasser.pl
PROTALOCATION=~/Desktop/protAlign-master
dirs=~/Videos/Proteins/*
# GLR: uncomment the next line for debugging
#set -x
#Step 1 - Process PDB for readily available values
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir
rm `cscore|model*.pdb|seq.fasta`
# GLR: back to original directory
popd
done
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir
for file in *.pdb; do
perl $GETLOCATION/$GETNAME $file
dssp -i ${file}-fix -o $file.dssp
perl $SSLOCATION/$SSNAME $file.dssp ${file}-out
done
for file in $dirs/*.dssp; do
grep 'ACCESSIBLE SURFACE OF PROTEIN' $file >> ${file}-SASA.txt
done
for file in $dirs/*.txt; do
echo "$file `cat $file`" >> $dir-combinedSASAs.txt
done
# GLR: back to original directory
popd
done
#Step 2 - Set up tool
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir
./$PROTALOCATION/initialize.sh
. $PROTALOCATION/bin/activate
# GLR: back to original directory
popd
done
#Step 3 - Start analyzing files
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir
for file in *.pdb; do
./$PROTALOCATION/program_name.py $dir $dir/native.pdb $dir-SPAR
done
# GLR: back to original directory
popd
done
# GLR: this won't do what you want
#for file in $dirs/data; do
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir/data
#;filerep=native-*.txt
#;grep 'TM-score' $filerep >> combinedreports.txt
grep 'TM-score' native-*.txt >> combinedreports.txt
awk 'FNR%2' combinedreports.txt > newcombinedrep.txt
# GLR: back to original directory
popd
done
for dir in $dirs; do
# GLR: Assume you want to change directory here?
pushd $dir
for file in cscore; do
grep 'model*' $file >> ${file}-confscore.txt
# command to keep only the 1-5 lines from each dir I want to keep
# that contain this full format
# " model1 -5.00 0.21+-0.05 19.9+-1.8 404 0.003 "
# then >> combinedcscore.txt
# Then reformat it to just "$dir model1 -5.00" >> newcombcscore.txt
done
# GLR: back to original directory
popd
done
exit 0
关于linux - bash 脚本卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38881409/