Конвертировать JSON с именами и значениями в TSV? - PullRequest
0 голосов
/ 26 октября 2019

Для следующего входного JSON, я хотел бы получить такой вывод (▸ для TAB и ¬ для новой строки). Я не знаю, каков наилучший способ сделать это. Не могли бы вы показать мне, какой самый краткий способ извлечь такую ​​информацию из входных данных JSON? Спасибо.

Gene.primaryIdentifier▸ Gene.name▸  Gene.symbol▸    Gene.description▸   Gene.chr▸   Gene.mitoEvidenceMitoCarta▸ Gene.mitoEvidenceIMPI▸  Gene.mitoEvidenceGO▸    Gene.mitoEvidenceHumanProteinAtlas▸ Gene.MTSipsort▸ Gene.MTSmitofates▸  Gene.MTSmitoprot▸   Gene.MTStargetP¬
ENSG00000002330▸    572▸    BAD▸    BCL2 associated agonist of cell death▸  11▸ true▸   Known mitochondrial▸    true▸   true▸   0▸  0▸  0.0088▸ 0.064¬
...
{
  "rootClass": "Gene",
  "modelName": "genomic",
  "start": 0,
  "views": [
    "Gene.primaryIdentifier",
    "Gene.name",
    "Gene.symbol",
    "Gene.description",
    "Gene.chr",
    "Gene.mitoEvidenceMitoCarta",
    "Gene.mitoEvidenceIMPI",
    "Gene.mitoEvidenceGO",
    "Gene.mitoEvidenceHumanProteinAtlas",
    "Gene.MTSipsort",
    "Gene.MTSmitofates",
    "Gene.MTSmitoprot",
    "Gene.MTStargetP"
  ],
  "iTotalRecords": 1157,
  "columnHeaders": [
    "Gene > Ensembl Primary Identifier",
    "Gene > NCBI Gene ID",
    "Gene > Gene Symbol",
    "Gene > Description",
    "Gene > Chromosome",
    "Gene > Mito Evidence MitoCarta",
    "Gene > Mito Evidence IMPI",
    "Gene > Mito Evidence GO Annotation",
    "Gene > Mito Evidence Human Protein Atlas",
    "Gene > Mito Targeting Seq iPSORT",
    "Gene > Mito Targeting Seq MitoFates",
    "Gene > Mito Targeting Seq MitoProt",
    "Gene > Mito Targeting Seq TargetP"
  ],
  "results": [
    [
      {
        "id": 1026800,
        "column": "Gene.primaryIdentifier",
        "value": "ENSG00000002330",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.name",
        "value": "572",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.symbol",
        "value": "BAD",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.description",
        "value": "BCL2 associated agonist of cell death",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.chr",
        "value": "11",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.mitoEvidenceMitoCarta",
        "value": true,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.mitoEvidenceIMPI",
        "value": "Known mitochondrial",
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.mitoEvidenceGO",
        "value": true,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.mitoEvidenceHumanProteinAtlas",
        "value": true,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.MTSipsort",
        "value": 0,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.MTSmitofates",
        "value": 0,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.MTSmitoprot",
        "value": 0.0088,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      },
      {
        "id": 1026800,
        "column": "Gene.MTStargetP",
        "value": 0.064,
        "class": "Gene",
        "url": "/report.do?id=1026800"
      }
    ],
    [
      {
        "id": 1025305,
        "column": "Gene.primaryIdentifier",
        "value": "ENSG00000002549",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.name",
        "value": "51056",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.symbol",
        "value": "LAP3",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.description",
        "value": "leucine aminopeptidase 3",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.chr",
        "value": "4",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.mitoEvidenceMitoCarta",
        "value": true,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.mitoEvidenceIMPI",
        "value": "Known mitochondrial",
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.mitoEvidenceGO",
        "value": false,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.mitoEvidenceHumanProteinAtlas",
        "value": false,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.MTSipsort",
        "value": 1,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.MTSmitofates",
        "value": 0.997,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.MTSmitoprot",
        "value": 0.9979,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      },
      {
        "id": 1025305,
        "column": "Gene.MTStargetP",
        "value": 0.946,
        "class": "Gene",
        "url": "/report.do?id=1025305"
      }
    ]
  ],
  "executionTime": "2019.10.26 03:00::38",
  "wasSuccessful": true,
  "error": null,
  "statusCode": 200
}

1 Ответ

0 голосов
/ 26 октября 2019

Если .views и .results упорядочены последовательно, то вы можете использовать этот фильтр jq (вместе с параметром командной строки -r):

.views,
 (.results[] | map(.value))
| @tsv

Однако, поскольку этобольшое предположение, может быть предпочтительнее принять более надежное решение, такое как:

def gather($ary):
  INDEX(.[]; .column) as $dict
  | $ary
  | map( $dict[.] | .value );

.views as $views
| ($views,
   (.results[] | gather($views)))
| @tsv
...