Как сохранить распознанное регулярное выражение в столбце в том же текстовом файле, в котором был найден шаблон? - PullRequest
0 голосов
/ 01 октября 2018

У меня есть файл со многими столбцами (1-я строка)

TRINITY_DN3472760_c4_g4 TRINITY_DN3472760_c4_g4_i1  DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex`DHAS_AQUAE^DHAS_AQUAE^Q:2-361,H:214-332^53.333%ID^E:4.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex TRINITY_DN3472760_c4_g4_i1.p2   2-373[+]    DHAS_AQUAE^DHAS_AQUAE^Q:1-120,H:214-332^53.333%ID^E:1.37e-32^RecName: Full=Aspartate-semialdehyde dehydrogenase {ECO:0000255|HAMAP-Rule:MF_02121};^Bacteria; Aquificae; Aquificales; Aquificaceae; Aquifex  PF02774.15^Semialdhyde_dhC^Semialdehyde dehydrogenase, dimerisation domain^1-108^E:6.4e-24  COG0136^Catalyzes the NADPH-dependent formation of L-aspartate- semialdehyde (L-ASA) by the reductive dephosphorylation of L- aspartyl-4-phosphate (By similarity)  KEGG:aae:aq_1866`KO:K00133  KEGG:aae:aq_1866`KO:K00133  GO:0005737^cellular_component^cytoplasm`GO:0004073^molecular_function^aspartate-semialdehyde dehydrogenase activity`GO:0003942^molecular_function^N-acetyl-gamma-glutamyl-phosphate reductase activity`GO:0051287^molecular_function^NAD binding`GO:0050661^molecular_function^NADP binding`GO:0071266^biological_process^'de novo' L-methionine biosynthetic process`GO:0019877^biological_process^diaminopimelate biosynthetic process`GO:0009097^biological_process^isoleucine biosynthetic process`GO:0009089^biological_process^lysine biosynthetic process via diaminopimelate`GO:0009088^biological_process^threonine biosynthetic process   GO:0003942^molecular_function^N-acetyl-gamma-glutamyl-phosphate reductase activity`GO:0016620^molecular_function^oxidoreductase activity, acting on the aldehyde or oxo group of donors, NAD or NADP as acceptor`GO:0046983^molecular_function^protein dimerization activity`GO:0008652^biological_process^cellular amino acid biosynthetic process`GO:0055114^biological_process^oxidation-reduction process`GO:0005737^cellular_component^cytoplasm   GGAGCGTAAGGTCACCTGGGAGACGCGCAAGATCATGGACCTGCCCGACCTCCCTGTGTCGTGCACGTGCGTGCGCATCCCCACGCTGCGCGCGCACGGCGAGTCGATCACCATCGAGACGGAGAAGCCGATCAACATGGAGAGGGCCTACGCTGTGCTCAACGAGGCCTCCGGCGTCGTCGTCGTCGACGACACCTCGAAGAACCTCTACCCGATGCCGATCACCGCCTCGACCAAGTTCGACGTCGAGGTCGGCCGCCTCCGCATCAACGACGTCTTCGGCGAGAACGGCCTCGACATGTTCGTCGTCGGCGATCAGCTCCTCCGCGGCGCGGCGCTCAACGCCGTCCTCATCGCGGAGGCCGTCATGTAAACTTGTTTACACCCGCGCCGCCACTCGTGCTGTTTGCTGCCGCCGGCCCGCTTCGGCCCAAACCGCGACGCCCTTGCGTGGCTTGGC    ERKVTWETRKIMDLPDLPVSCTCVRIPTLRAHGESITIETEKPINMERAYAVLNEASGVVVVDDTSKNLYPMPITASTKFDVEVGRLRINDVFGENGLDMFVVGDQLLRGAALNAVLIAEAVM*

В одном из этих столбцов есть несколько аннотаций, которые могут выглядеть следующим образом:

KEGG:aag:AaeL_AAEL000291`KO:K02155
KEGG:aag:AaeL_AAEL003872
KEGG:aag:AaeL_AAEL005901`KEGG:aag:AaeL_AAEL013158`KO:K02984
KEGG:ago:AGOS_AGR122C`KO:K13126
KEGG:ame:408385`KO:K03231

Меня интересуетизвлечение детали с помощью KO-аннотации, т.е. с помощью grep

grep -P 'K[0-9]{5}' myfile

, но затем я хотел бы сохранить соответствующий шаблон в том же файле, скажем, в столбце 15. Другой вариант, который мог бы мне помочь, - это если соответствующий шаблонхранится в том же месте, но все остальное удаляется.

Итак, мой ожидаемый результат - число, соответствующее K [0-9] {5}, сохраненное в том же файле.

Может ли кто-нибудь помочь мне с этим?

1 Ответ

0 голосов
/ 01 октября 2018

Проверьте, действительно ли поле 9 заканчивается нужным вам шаблоном, а затем sub сопоставьте с sub(/.*:/, "", r) и добавьте только в конце допустимой строки:

awk -F"\t" '{if ($9 ~ /KO:K[0-9]{5}$/) { r=$9; sub(/.*:/, "", r); print $0 "\t" r; } else print $0; }' file > outfile

Здесь,

  • -F"\t" разбивается на поля с помощью символа табуляции
  • if ($9 ~ /KO:K[0-9]{5}$/) является условием, только если поле 9 ($9) оканчивается на KO:K + 5 цифр,
    • r=$9; назначьте значение поля 9 для r
    • sub(/.*:/, "", r);, затем удалите все вплоть до последнего включительно :
    • print $0 "\t" r; затем,распечатайте всю запись с помощью вкладки, а r значение
  • else
    • print $0; распечатайте запись как есть.
...