我是生物信息学新手,我尝试在 bash 脚本中使用多个 R 脚本:
#!/bin/bash
#Pathway of your script
Rscript /home/administrateur/Bureau/guillaume/fichier_workflow/Script/script_analyse_complete_seq.R $1 $2 $3 &&
#$1 : pathway of the file to use
#$2 : Mabsilico table record pathway + filename
#$3 : fasta file record pathway + filename
#Pathway of your folder containing file you record previously to apply vquest function
cd /home/administrateur/Bureau/guillaume/fichier_workflow
vquest --species human --receptorOrLocusType IG --fileSequences $4
#$4 pathway of the file to use for vquest
#if needed parameter here can be changer depending of what you are working on
mv vquest_airr.tsv $5
#$5 : new file name
rm Parameters.txt
#Pathway of your script
cd /home/administrateur/Bureau/guillaume/fichier_workflow/Script
#Pathway of your script
Rscript /home/administrateur/Bureau/guillaume/fichier_workflow/Script/script_after_vquest.R $6 $7 $8 $9 $10
#$6 : pathway of the vquest file
#$7 : proportion file record pathway + filename
#$8 : IGHV proportion file record pathway + filename
#$9 : IGKV proportion file record pathway + filename
#$10 : IGLV proportion file record pathway + filename
#Pathway of your script
cd /home/administrateur/Bureau/guillaume/fichier_workflow/Script
#Pathway of your script
Rscript /home/administrateur/Bureau/guillaume/fichier_workflow/Script/script_opti_comp_tableau.R $11 $12 $13 $14
#$11 : Full pathway of the first table to compare
#$12 : Full pathway of the second table to compare
#$13 : pathway to record similarity table + filename
#$14 : pathway to record difference table + filename
echo "travail brute termine"
但是当用户想要使用它时,它看起来像这样:
sh bash_fusion.sh /home/administrateur/PycharmProjects/Roxane_10X/HD618_naive/outs/all_contig_annotations.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/MabSilico_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/HD618_naive.fasta /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/HD618_naive.fasta /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/vquest_HD618_naive.tsv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/vquest_HD618_naive.tsv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/proportion_clonotype_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/IGHV_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/IGKV_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/IGLV_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/IGHV_HD618_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/IGHV_HD619_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/same_HD618vsHD619_naive.csv /home/administrateur/Bureau/guillaume/fichier_workflow/test_fusion/dif_HD618vsHD619_naive.csv
而且它很长,并且所有参数都是位置性的,我想让它对用户更友好,比如将参数放在 bash 会读取的外部文件中,或者任何其他想法来使用户变得简单。
提前感谢您的回答!
这是一个 bash 脚本,可以在一定程度上简化您的工作:
#!/bin/bash
# Usage: quux.sh script1.R ... scriptN.R arg1 arg2 ... argX
# Effect:
# Rscript script1.R arg1 arg2 arg3 arg4
# Rscript script2.R arg5 arg6 arg7 arg8
# ... in groups of 4
SCRIPTS=()
for opt in "${@}" ; do
if [[ "${opt}" == *".R" ]]; then
SCRIPTS=("${SCRIPTS[@]}" "${opt}")
shift
else
break
fi
done
for SCRIPT in "${SCRIPTS[@]}" ; do
if [[ $# -le 1 ]]; then
break
fi
echo Rscript ${SCRIPT} $1 $2 $3 $4
if [[ $# -le 4 ]]; then
break
else
shift 4
fi
done
if [ $# -gt 0 ]; then
echo "! Unhandled arguments: ${@}" > /dev/stderr
exit 1
fi
### quick setup, just for demonstration
$ touch script1.R script2.R script3.R script4.R
### default usage
$ ./quux.sh script*.R path1 path2 path3 path4 path5 path6 path7 path8 path9 path10 path11 path12
Rscript script1.R path1 path2 path3 path4
Rscript script2.R path5 path6 path7 path8
Rscript script3.R path9 path10 path11 path12
### partial runs, not sure if your R scripts work with this:
$ ./quux.sh script*.R path1 path2 path3 path4 path5 path6
Rscript script1.R path1 path2 path3 path4
Rscript script2.R path5 path6
### if we run out of scripts before arguments, emit an error
$ ./quux.sh script1.R path1 path2 path3 path4 path5 path6
Rscript script1.R path1 path2 path3 path4
! Unhandled arguments: path5 path6
假设:
Rscript ...
,并且 Rscript
可在用户的 PATH
备注:
quux.sh
需要标记为可执行(chmod +x quux.sh
);我正在使用 ./quux.sh
,因为我位于当前目录中,但如果您将其移动到用户的 PATH
中的某个位置,那么这应该是不必要的sh
)及其数组和 [[
条件,/bin/sh
不适用于此