2016-07-25 7 views
0

以下のbashでは、ユーザが最初にselectで使用するファイルを選択し、そのファイルの数字が自動的に 'the second file. The problem is that when the second file is selected the path appears in the name so the bash`エラーを選択するために使用されます。私はこれを修正することができないといくつかの助けが必要です。私は長い記事をお詫びし、必要なファイルがすべてここにあることを確認しようとしています。ありがとうございました :)。2番目の選択でパスを削除するbash

バッシュ

FILESDIR=/home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools 
ANNOVARDIR=/home/cmccabe/Desktop/NGS/API/5-14-2016/vcf/overall/annovar 

PS3="please select a file to analyze with a panel: " # specify file 
select file in $(cd ${FILESDIR};ls);do break;done 
    file1=`basename ${FILESDIR}/${file}` 
    printf "File 1 is: ${file1} and will be used to filter reads, identify target bases and genes less than 20 and 30 reads, create a low coverage bed for vizulization, calculate 20x and 30x coverage, and filter the vcf for the 98 gene epilepsy panel" 
for file in /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools/$file; do 
bname=$(basename $file) 
pref=${bname%%.txt} 
grep -wFf /home/cmccabe/Desktop/NGS/panels/EPILEPSY_unix_trim.bed $file > /home/cmccabe/Desktop/NGS/API/5-14-2016/panel/reads/${pref}_EPILEPSY.txt 
done 
# filter vcf 
printf "\n\n" 
file2=`basename $(ls ${ANNOVARDIR}/${file%%_*}*)` 
     printf "File 2 is: ${file2} and will be used filtered using the epilepsy genes" 
pref=${bname%%} 
awk 'NR==FNR{for (i=1;i<=NF;i++) a[$i];next} FNR==1 || ($7 in a)' /home/cmccabe/Desktop/NGS/panels/EPILEPSY_unix_trim.bed $file2 | awk '{split($2,a,"-"); print a[1] "\t" $0}' | cut -f2-> /home/cmccabe/Desktop/NGS/API/5-14-2016/vcf/panel/annovar/${pref}_Epilepsyfiltered.bed 

第 `ユーザが選択した場合12311_base_counts.txt)を選択するためのファイル秒間

12311_base_counts.txt 
45611_base_counts.txt 

ファイルが選択

12311_variant_strandbias_readcount.vcf.hg19_multianno_removed_final (this one is automatically selected because it has the same starting digits as the original file) 
45611_variant_strandbias_readcount.vcf.hg19_multianno_removed_final 

エラーthis portion of the path is the problem I think, /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools/

1) 12311_base_counts.txt 
2) 45611_base_counts.txt 

please select a file to analyze with a panel: 7 
File 1 is: T31129_base_counts.txt and will be used to filter reads, identify target bases and genes less than 20 and 30 reads, create a low coverage bed for visualization, calculate 20x and 30x coverage, and filter the vcf for the 98 gene epilepsy panel 

ls: cannot access /home/cmccabe/Desktop/NGS/API/5-14-2016/vcf/overall/annovar//home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools/T31129*: No such file or directory/home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools/ 
File 2 is: and will be used filtered using the epilepsy genes 
+0

私は間違った場所に 'basename'を持っていました。愚かな間違い私は謝罪し、あなたに感謝:) – Chris

答えて

0

とbashのは次のようになります。

file2=$(ls ${ANNOVARDIR}/`basename ${file%%_*}`*) 
+1

Ewww。 http://mywiki.wooledge.org/ParsingLsを参照してください。この全体をhttp://shellcheck.net/で実行してください。 –

関連する問題