2015-10-14 69 views
1

我已经编辑了上一个问题,因为它太长而且令人讨厌,现在我已经知道了我想要的东西,我发现在下面的代码中的某些操作中有一个小故障。寻求建议。如何将文件中的列粘贴到另一个临时文件?

我有代码,现在它工作正如我所料,但我得到一个额外的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,不知道为什么?任何建议

+1

你的问题是在你的printf语句之前intersectBed:在你的printf语句中的数字3之后删除逗号 – pcantalupo

+0

是的我想通了,谢谢但问题是输出没有头,我也想输出到具有文件名的典型标题以及输出文件的前3个字段将合并,如我在输出中所示。 –

+0

如果您自己回答了问题,请考虑发布答案并接受答案。 – pcantalupo

回答

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操作,因为列很好。

相关问题