我已经编辑了上一个问题,因为它太长而且烦人,现在我已经找到了我想要的东西,我看到在下面的代码中有一些小故障。寻求建议。
我有代码,现在它按预期工作,但我得到一个额外的0行,我无法理解为什么?有什么建议吗?
码
#!/bin/bash
#$ -S /bin/bash
cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test
cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp
printf "chr\tstart\tend" > tsamples
for file in `ls *.bed`; do
printf "\t" >> tsamples
printf `basename $file .bed` >> tsamples
#echo $file | cut -d_ -f 1,2,3 >> tsamples
intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2
mv tmp2 tmp
done
echo "" >> tsamples
cat tsamples tmp > histone_marks.map
rm tsamples tmp
输出
chr start end test_K27ac_S12818 test_K27ac_S12838 test_K27me3_S12815_5cols test_K27me3_S12830_5cols test_K4me1_S12816 test_K4me1_S12831 test_K4me1_S12836
chr1 754118 754696 0 0 0 0 290 576 0
chr1 804929 805633 0 0 704 0 277 0 704
chr1 826069 826438 0 0 0 0 369 0 0
chr1 839340 839608 0 0 268 0 268 0 0
chr1 840388 843628 0 0 3240 0 816 2434 923
chr1 845517 847768 0 0 2251 820 1113 2106 1677
chr1 850950 854146 0 0 3196 3196 2184 3196 1302
chr1 855361 857280 0 0 1919 0 1911 1919 979
chr1 857930 859278 0 0 1348 0 1139 1125 923
chr1 859906 860677 351 0 771 463 0 0 771
0
一切都很好,除了最后一行显示0,不知道为什么?任何建议
答案 0 :(得分:1)
我相信我做的正确,所以我自己更改了代码,这就是我做的方式
#!/bin/bash
#$ -S /bin/bash
cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test
cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp
printf "chr\tstart\tend" > tsamples
for file in `ls *.bed`; do
printf "\t" >> tsamples
printf `basename $file .bed` >> tsamples
#echo $file | cut -d_ -f 1,2,3 >> tsamples
intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2
mv tmp2 tmp
done
echo "" >> tsamples
cat tsamples tmp > histone_marks.map
rm tsamples tmp
sed '$d' histone_marks.map
这确实有效,但我知道这是一种非常粗暴的方式。我无法弄清楚为什么最后一行0会出来,但它是用某种操作我相信bash而不是intesectBed操作,因为列非常好。