[英]How extract array of array as TSV from json using jq?
I'd like to extract the data from here.我想从这里提取数据。
http://d2p2.pro/api/seqid/["P04637","P51608"] http://d2p2.pro/api/seqid/["P04637","P51608"]
I currently use .[] | [.[][0], .[][2]["disorder"]["consranges"][] ]
我目前使用
.[] | [.[][0], .[][2]["disorder"]["consranges"][] ]
.[] | [.[][0], .[][2]["disorder"]["consranges"][] ]
. .[] | [.[][0], .[][2]["disorder"]["consranges"][] ]
。 And I get this.我明白了。
[
"P04637",
[
"1",
"22"
],
[
"26",
"27"
],
[
"30",
"31"
],
[
"33",
"97"
],
[
"281",
"329"
],
[
"343",
"393"
]
]
[
"P51608",
[
"1",
"118"
],
[
"151",
"281"
],
[
"283",
"486"
]
]
But I want to get the result in a TSV format, as this.但我想得到 TSV 格式的结果,就像这样。
P04637<TAB>1<TAB>22
P04637<TAB>26<TAB>27
...
Does anybody know what is the correct jq command to extract the output in this format?有谁知道以这种格式提取 output 的正确 jq 命令是什么?
EDIT:编辑:
Of the following to files.以下为文件。
==> 1.json <==
{"P51608":[["P51608","Uniprot 2018_03 genome",{"structure":{"weak":[],"pfam":[["Domain","CL0081","PF01429.14","MBD","Methyl-CpG binding domain","4e-21","74.3","90","164"]],"strong":[["DNA-binding domain","54171","6.54e-33","Methyl-CpG-binding domain, MBD","54178","0.000000724","73-187"]]},"disorder":{"disranges":[["VLXT","1","120"],["VSL2b","1","117"],["PrDOS","1","93"],["PV2","1","118"],["IUPred-S","1","10"],["IUPred-L","1","113"],["Espritz-N","1","133"],["Espritz-X","1","119"],["Espritz-D","1","486"],["IUPred-S","13","111"],["IUPred-L","115","126"],["IUPred-L","136","137"],["Espritz-N","141","243"],["IUPred-L","143","143"],["PV2","146","486"],["Espritz-X","146","218"],["VSL2b","150","486"],["IUPred-L","150","214"],["IUPred-S","153","214"],["PrDOS","161","486"],["VLXT","163","209"],["IUPred-S","216","216"],["IUPred-L","216","486"],["IUPred-S","218","218"],["IUPred-S","220","278"],["Espritz-X","226","243"],["VLXT","234","281"],["Espritz-N","252","263"],["Espritz-N","266","273"],["Espritz-N","283","294"],["Espritz-X","285","289"],["VLXT","290","319"],["Espritz-N","298","312"],["Espritz-X","318","486"],["Espritz-N","324","486"],["VLXT","334","362"],["IUPred-S","334","486"],["VLXT","377","436"],["VLXT","446","483"],["VLXT","485","485"]],"conflict":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,8,8,8,7,6,5,4,4,4,4,4,3,3,2,2,2,2,2,2,1,1,2,2,1,1,1,2,2,4,3,2,4,4,4,4,6,7,7,7,7,7,7,7,7,7,7,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,9,8]}}]],"P01106":[]}
==> 2.json <==
{"P01106":[],"P51608":[["P51608","Uniprot 2018_03 genome",{"structure":{"strong":[["DNA-binding domain","54171","6.54e-33","Methyl-CpG-binding domain, MBD","54178","0.000000724","73-187"]],"weak":[],"pfam":[["Domain","CL0081","PF01429.14","MBD","Methyl-CpG binding domain","4e-21","74.3","90","164"]]},"disorder":{"conflict":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,8,8,8,7,6,5,4,4,4,4,4,3,3,2,2,2,2,2,2,1,1,2,2,1,1,1,2,2,4,3,2,4,4,4,4,6,7,7,7,7,7,7,7,7,7,7,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"consranges":[["1","118"],["151","281"],["283","486"]],"disranges":[["VLXT","1","120"],["VSL2b","1","117"],["PrDOS","1","93"],["PV2","1","118"],["IUPred-S","1","10"],["IUPred-L","1","113"],["Espritz-N","1","133"],["Espritz-X","1","119"],["Espritz-D","1","486"],["IUPred-S","13","111"],["IUPred-L","115","126"],["IUPred-L","136","137"],["Espritz-N","141","243"],["IUPred-L","143","143"],["PV2","146","486"],["Espritz-X","146","218"],["VSL2b","150","486"],["IUPred-L","150","214"],["IUPred-S","153","214"],["PrDOS","161","486"],["VLXT","163","209"],["IUPred-S","216","216"],["IUPred-L","216","486"],["IUPred-S","218","218"],["IUPred-S","220","278"],["Espritz-X","226","243"],["VLXT","234","281"],["Espritz-N","252","263"],["Espritz-N","266","273"],["Espritz-N","283","294"],["Espritz-X","285","289"],["VLXT","290","319"],["Espritz-N","298","312"],["Espritz-X","318","486"],["Espritz-N","324","486"],["VLXT","334","362"],["IUPred-S","334","486"],["VLXT","377","436"],["VLXT","446","483"],["VLXT","485","485"]],"consensus":[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,8,8,8,7,6,5,4,4,4,4,4,3,3,2,2,2,2,2,2,1,1,2,2,1,1,1,2,2,4,3,2,4,4,4,4,6,7,7,7,7,7,7,7,7,7,7,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,7,7,7,8,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,7,7,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,6,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,8,8,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,9,8]}}]]}
Here is the output.这是 output。 So "try(.[][0]) | [.[0]] + (.[2].disorder.consranges[]) | @tsv" depends on the order of entries in the input.
所以 "try(.[][0]) | [.[0]] + (.[2].disorder.consranges[]) | @tsv" 取决于输入中条目的顺序。 Therefore, it is not robust.
因此,它并不稳健。
$ jq -r "try(.[][0]) | [.[0]] + (.[2].disorder.consranges[]) | @tsv" < /tmp/1.json
P51608 1 118
P51608 151 281
P51608 283 486
$ jq -r "try(.[][0]) | [.[0]] + (.[2].disorder.consranges[]) | @tsv" < /tmp/2.json
The following filter produces results as shown below, which are in accordance with those in the question, so hopefully this will provide the guidance you're looking for:以下过滤器产生的结果如下所示,与问题中的结果一致,因此希望这将为您提供所需的指导:
.[][0]
| [.[0]] + (.[2].disorder.consranges[])
| @tsv
P04637 1 22
P04637 26 27
P04637 30 31
P04637 33 97
P04637 281 329
P04637 343 393
P51608 1 118
P51608 151 281
P51608 283 486
The requirements are not very clear with respect to robustness, but sprinkling one or more try
statements around will confer a measure of robustness.关于健壮性的要求不是很清楚,但是在周围散布一个或多个
try
语句将赋予健壮性度量。 The following will handle both the two variants in the update to the Q:以下将处理 Q 更新中的两个变体:
.[][0]
| try [.[0]] + (.[2].disorder.consranges[])
| @tsv
Here is an illustration of one way to increase the flexibility of the program with respect to the structure of the inputs, without using try
at all:下面是一种在输入结构方面增加程序灵活性的方法的说明,根本不使用
try
:
.[][]
| .[0] as $p
| ..
| objects
| select(has("disorder"))
| [$p] + (.disorder.consranges[])
| @tsv
But be careful what you wish for!但要小心你的愿望!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.