我在生物信息学的工作,我需要在这看起来像大文件计算的模式,如GATTACCA:
“ATTTCCCGATCCGAG GATT(/ N)
ACCA CGTAGATGATACACGT(etc)“ 有没有办法让Grep忽略/ n换行符? 感谢您的帮助!用grep搜索超过multipile行模式
1
A
回答
1
我想这可能就是你所想要的东西:
tr -d '\n' < file | grep -o GATTACCA
它(临时)从文件(使用tr
及其-d
选项删除)传递到grep
之前移除换行。
+0
谢谢!这工作到目前为止最简单... 现在...任何想法如何解析成python? 我知道如何在python中使用简单的linux命令,但不知道如何管道... – MrJanx
1
你可以做到这一点通过awk和grep来算在你的文件的话GATTACCA
的出现次数,
awk -v RS="\0" '{gsub (/\n/,""); print}' file | grep -o 'GATTACCA' | wc -l
说明:
RS="\0" # Turns the input file into a single record.
gsub (/\n/,"") # Removes all the \n character.
grep -o 'GATTACCA' # From the awk output, it fetches the string GATTACCA and prints every match in a new line.
wc -l # To count the number of lines
0
你已经有两个很好的通用答案。另一种方法是使用sed
:
perl -pe 's/\n//' file | grep -o GATACA
但是,如果你在FASTA文件时,这可以是有趣:
#! /bin/sh
gawk '{
if (substr($1,1,1)==">")
if (NR>1)
printf "\n%s\t", substr($0,2,length($0)-1)
else
printf "%s\t", substr($0,2,length($0)-1)
else
printf "%s", $0
}END{printf "\n"}' "[email protected]"
上面的脚本改变FASTA格式TBL(SEQ IDsequence,所有在同一行上)。我经常用它来grepping:
FastaToTbl foo.fa | grep GATTACA
我也有一个TblToFasta恢复原来的:
#! /bin/sh
# tbl-to-fasta.awk transforms a tbl file into a fasta file, 60 columns per record
# usage=gawk -f tbl-to-fasta TBL_FILE
gawk '{
sequence=$NF
ls = length(sequence)
is = 1
fld = 1
while (fld < NF)
{
if (fld == 1){printf ">"}
printf "%s " , $fld
if (fld == NF-1)
{
printf "\n"
}
fld = fld+1
}
while (is <= ls)
{
printf "%s\n", substr(sequence,is,60)
is=is+60
}
}' "[email protected]"
1
相关问题
- 1. 模式搜索Grep
- 2. 使用grep多个搜索模式
- 3. 使用grep进行搜索
- 4. grep的搜索特定的模式
- 5. grep,如何搜索确切模式?
- 6. Grep/Sed/Awk块和搜索模式
- 7. 混乱上的grep模式搜索
- 8. 搜索超过使用NSPredicate
- 9. 使用正则表达式grep搜索
- 10. 使用grep来搜索R中的行
- 11. Bash脚本使用Grep来搜索文件中的模式
- 12. 使用grep搜索多个模式的函数
- 13. Vim多行搜索模式
- 14. 通行证搜索模式
- 15. 使用grep来搜索
- 16. Bash使用存储在文件中的模式执行多个grep搜索
- 17. Grep命令搜索
- 18. grep搜索替换
- 19. 多的grep搜索
- 20. 递归搜索grep
- 21. grep的挑战 - 搜索任意数量的字符后提取搜索模式
- 22. 通过PostgreSql函数搜索'grep-alike'
- 23. 模式搜索()
- 24. 模式搜索
- 25. 搜索超过Rails中
- 26. grep命令不是搜索完整模式
- 27. 带模式文件的反向grep搜索?
- 28. 在grep搜索中返回行吗?
- 29. 在grep搜索后显示n行
- 30. jedi-vim自动完成。通过grep式搜索完成
你只是需要的数'GATT \ nACCA'发生?这个文件有多大? – Kent
档案有多大?其次 - grep通过换行符识别,所以它不能匹配它。但是你可以使用“tr”来替换换行符和空格,但是再次,文件有多大? –