最近需要抓取各种序列,就尝试了大量的文本处理语句,简单整理一下好用的,希望对大家有帮助~
关键词: awk |grep |sed 正则表达式
引子 $ head -2 pathcat_BACTERIA.mitab.txt # protein_xref_1 protein_xref_2 alternative_identifiers_1 alternative_identifiers_2 protein_alias_1 protein_alias_2 detection_method author_name pmid protein_taxid_1 protein_taxid_2 interaction_type source_database_id database_identifier confidence uniprotkb:P22897 uniprotkb:Q81SE4 intact:EBI-2809438|uniprotkb:A5PKW3|uniprotkb:Q5VSJ2|uniprotkb:Q5VSK2 intact:EBI-2826271|uniprotkb:Q6KUI7|uniprotkb:E9R5T6|uniprotkb:A0A2P0HCH6 psi-mi:mrc1_human(display_long)|uniprotkb:MRC1(gene name)|psi-mi:MRC1(display_short)|uniprotkb:CLEC13DL(gene name synonym)|uniprotkb:C-type lectin domain family 13 member D-like(gene name synonym)|uniprotkb:CLEC13D(gene name synonym)|uniprotkb:MRC1L1(gene name synonym)|uniprotkb:C-type lectin domain family 13 member D(gene name synonym)|uniprotkb:Macrophage mannose receptor 1-like protein 1(gene name synonym)|uniprotkb:Human mannose receptor(gene name synonym) psi-mi:q81se4_bacan(display_long)|uniprotkb:flhA(gene name)|psi-mi:flhA(display_short)|uniprotkb:GBAA_1716(locus name) psi-mi:MI:0398(two hybrid pooling approach) Dyer et al. (2010) pubmed:20711500|imex:IM-13779 taxid:9606(human|Homo sapiens) taxid:1392(bacan|Bacillus anthracis) psi-mi:MI:0915(physical association) psi-mi:MI:0469(IntAct) intact:EBI-2839221|imex:IM-13779-4420 author score:1|intact-miscore:0.37
目的是想要在信息表中获得物种的拉丁名,就要有以下的操作: $ awk -F '\t' '{match ($11,/\|(.*)\)/,a);print a[1]}' pathcat_BACTERIA.mitab.txt |head -1 $ Bacillus anthracis
(莫名的成就感) 两三步法也是有滴: $ cut -f 11 pathcat_BACTERIA.mitab.txt |sed 's/.*|\(.*\))/\1/' $ Bacillus anthracis
思路&笔记 首先要再啰嗦一下正则表达式,正则可以分为以下三类: 基础的正则表达式(Basic RegEx,简称:BREs) 扩展的正则表达式(Extended RegEx,简称:EREs) Perl的正则表达式(Perl RegEx,简称:PREs)
简单收集了一下不同的正则表达式分类中,基本组成及含义描述。(要注意的时其中Shell中的一些正则表达式是无法使用的),不过也可以调用,比如 grep -P 就可以调用Perl RegEx。 POSIX字符类POSIX字符类是一个形如[:...:]的特殊元序列(meta sequence),他可以用于匹配特定的字符范围。
元字符元字符(meta character)是一种Perl风格的正则表达式,只有一部分文本处理工具支持它。
awk match(string,regexp,array 配合正则,而后将array输出就好啦。
彩蛋
|