Skip to content

Commit

Permalink
Use Python 10 syntax for types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirvolque committed Oct 7, 2024
1 parent 9e34e05 commit a42ac5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python3 clean_up_vcf.py --vcf input.vcf --info AC AN_nfe_est faf95 > output.vcf
This command will remove all INFO fields from input.vcf except for AC, AN_nfe_est, and faf95, and will write the result to output.vcf.

# Requirements
To use clean-up-vcf, you need Python 3.9 or higher installed on your system.
To use clean-up-vcf, you need Python 3.10 or higher installed on your system.

# License
This script is licensed under the MIT License. See LICENSE for more information.
8 changes: 4 additions & 4 deletions clean_up_vcf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import csv
import argparse
from typing import Tuple, Optional, Generator
from typing import Generator

CHROM = "#CHROM"
INFO = "INFO"
Expand All @@ -14,15 +14,15 @@ def parse_info(info_content: str) -> dict[str, str]:
)
}

def split(field: str) -> Tuple[str, Optional[str]]:
def split(field: str) -> tuple[str, str | None]:
"""Splits a field by '=' if present, otherwise returns the field as a key with None value."""
return (field, None) if "=" not in field else tuple(field.split("="))

def to_pair(key: str, value: Optional[str]) -> str:
def to_pair(key: str, value: str | None) -> str:
"""Formats a key-value pair into 'key=value', or just 'key' if value is None."""
return f"{key}={value}" if key and value else key

def get_info_pair_for_key(info: dict[str, str], key: str) -> Optional[str]:
def get_info_pair_for_key(info: dict[str, str], key: str) -> str | None:
"""Retrieves a formatted pair for a given key if it exists in the info dictionary."""
return to_pair(key, info.get(key)) if key in info else None

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.9"
python = ">=3.10"

[tool.poetry.scripts]
clean-up-vcf = "clean_up_vcf:main"
Expand Down

0 comments on commit a42ac5a

Please sign in to comment.