-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3482 update output format #5
base: main
Are you sure you want to change the base?
Changes from all commits
d75defd
2c93e4f
fe35828
17d10a8
1b3262c
49f3eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,21 +1,33 @@ | ||||||
import json | ||||||
import subprocess | ||||||
from pathlib import Path | ||||||
from typing import BinaryIO | ||||||
from uuid import uuid4 | ||||||
|
||||||
import polars as pl | ||||||
|
||||||
def transform(src: Path, dst: Path) -> None: | ||||||
# load the homologues | ||||||
initial = pl.read_json(src) | ||||||
|
||||||
# prepare node data | ||||||
inputGenes = pl.DataFrame( | ||||||
initial['genes'] | ||||||
) | ||||||
def transform(src: BinaryIO, dst: BinaryIO) -> None: | ||||||
jq_command = '.genes | {"genes": map({id: .id, name: .name})}' | ||||||
|
||||||
# Generate a temporary file path tp store the source file | ||||||
temp_path = Path(f'/tmp/{uuid4()}.json') | ||||||
|
||||||
# extract genes list | ||||||
genes_list = inputGenes.explode('genes').unnest('genes') | ||||||
temp_path.write_bytes(src.read()) | ||||||
|
||||||
# read id and name | ||||||
output = genes_list.select(["id","name"]) | ||||||
# Ejecuta jq con subprocess | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should keep comments in english |
||||||
result = subprocess.run( | ||||||
['jq', jq_command, temp_path], | ||||||
capture_output=True, | ||||||
text=True | ||||||
) | ||||||
|
||||||
# write the result | ||||||
output.write_ndjson(dst) | ||||||
# Verifica si el comando se ejecutó correctamente | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here! |
||||||
if result.returncode == 0: | ||||||
output = json.loads(result.stdout) | ||||||
input_genes = pl.DataFrame(output, strict=False, infer_schema_length=3) | ||||||
# extract genes list | ||||||
genes_list = input_genes.unnest('genes') | ||||||
# # read id and name | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
output = genes_list.select(['id', 'name']) | ||||||
output.write_csv(dst, separator='\t', include_header=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.