Skip to content
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

Refactoring/format #14

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions locidex/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os, sys
from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter)
from locidex.version import __version__
from locidex.constants import FORMAT_RUN_DATA
from locidex.constants import DBFiles
from locidex.classes import run_command
from locidex.constants import DBConfig

Expand Down Expand Up @@ -165,21 +165,10 @@ def run(cmd_args=None):
input_file = cmd_args.input_file
outdir = cmd_args.outdir
force = cmd_args.force
run_data = FORMAT_RUN_DATA
run_data = dict()
run_data['analysis_start_time'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
run_data['parameters'] = vars(cmd_args)

#config = {}
#for f in DB_CONFIG_FIELDS:
# config[f] = ''

#config["db_name"] = cmd_args.name
#config["db_version"] = cmd_args.db_ver
#config["db_desc"] = cmd_args.db_desc
#config["db_author"] = cmd_args.author
#if cmd_args.date == '':
# config["db_date"] = datetime.now().strftime("%Y/%d/%m")

config = DBConfig(
db_name=cmd_args.name,
db_version =cmd_args.db_ver,
Expand All @@ -199,14 +188,14 @@ def run(cmd_args=None):
sys.exit()

run_data['analysis_end_time'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(os.path.join(outdir,"config.json"),"w") as oh:
with open(os.path.join(outdir,DBFiles.config_file),"w") as oh:
oh.write(json.dumps(obj.config.to_dict(),indent=4))

with open(os.path.join(outdir,"meta.json"),"w") as oh:
with open(os.path.join(outdir, DBFiles.meta_file),"w") as oh:
oh.write(json.dumps(obj.meta,indent=4))


with open(os.path.join(outdir,"results.json"),"w") as oh:
with open(os.path.join(outdir, DBFiles.results_file),"w") as oh:
oh.write(json.dumps(run_data,indent=4))


Expand Down
82 changes: 52 additions & 30 deletions locidex/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from dataclasses import dataclass, asdict, fields
import pathlib
from typing import Any, Union
from typing import Any, Union, NamedTuple, Optional

DNA_AMBIG_CHARS = ['b', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 'u', 'v', 'w', 'x',
'y', 'z', '-']
Expand Down Expand Up @@ -39,8 +39,8 @@


FILE_TYPES = {
'genbank':["gbk","genbank","gbf","gbk.gz","genbank.gz","gbf.gz","gbff","gbff.gz"],
'fasta':["fasta","fas","fa","ffn","fna","fasta.gz","fas.gz","fa.gz","ffn.gz","fna.gz"],
'genbank': ["gbk","genbank","gbf","gbk.gz","genbank.gz","gbf.gz","gbff","gbff.gz"],
'fasta': ["fasta","fas","fa","ffn","fna","fasta.gz","fas.gz","fa.gz","ffn.gz","fna.gz"],
}


Expand Down Expand Up @@ -121,9 +121,6 @@ class ManifestFields:

}

FORMAT_RUN_DATA = {

}

DB_EXPECTED_FILES = {
'config':'config.json',
Expand All @@ -132,28 +129,53 @@ class ManifestFields:
'protein':'protein.fasta',
}

LOCIDEX_DB_HEADER = [
'seq_id',
'locus_name',
'locus_name_alt',
'locus_product',
'locus_description',
'locus_uid',
'dna_seq',
'dna_seq_len',
'dna_seq_hash',
'aa_seq',
'aa_seq_len',
'aa_seq_hash',
'dna_min_len',
'dna_max_len',
'aa_min_len',
'aa_max_len',
'dna_min_ident',
'aa_min_ident',
'min_dna_match_cov',
'min_aa_match_cov',
'count_int_stops',
'dna_ambig_count'

]
class LocidexDBHeader(NamedTuple):
seq_id: str
locus_name: str
locus_name_alt: str
locus_product: str
locus_description: str
locus_uid: str
dna_seq: str
dna_seq_len: int
dna_seq_hash: str
aa_seq: Optional[str]
aa_seq_len: Optional[int]
aa_seq_hash: Optional[str]
dna_min_len: int
dna_max_len: int
aa_min_len: Optional[int]
aa_max_len: Optional[int]
dna_min_ident: float
aa_min_ident: Optional[float]
min_dna_match_cov: int
min_aa_match_cov: Optional[int]
count_int_stops: int
dna_ambig_count: int


#LOCIDEX_DB_HEADER = [
# 'seq_id',
# 'locus_name',
# 'locus_name_alt',
# 'locus_product',
# 'locus_description',
# 'locus_uid',
# 'dna_seq',
# 'dna_seq_len',
# 'dna_seq_hash',
# 'aa_seq',
# 'aa_seq_len',
# 'aa_seq_hash',
# 'dna_min_len',
# 'dna_max_len',
# 'aa_min_len',
# 'aa_max_len',
# 'dna_min_ident',
# 'aa_min_ident',
# 'min_dna_match_cov',
# 'min_aa_match_cov',
# 'count_int_stops',
# 'dna_ambig_count'
#]
114 changes: 57 additions & 57 deletions locidex/example/format_db_mlst_out/locidex.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions locidex/example/format_db_mlst_out/results.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"analysis_start_time": "2024-04-04 15:51:06",
"analysis_start_time": "2024-05-07 15:30:10",
"parameters": {
"input": "locidex/example/format_db_mlst_in",
"outdir": "/tmp/pytest-of-mwells/pytest-115/build0",
"input": "./locidex/example/format_db_mlst_in/",
"outdir": "./locidex/example/format_db_mlst_out/",
"min_len_frac": 0.7,
"max_len_frac": 1.3,
"min_ident": 80.0,
Expand All @@ -11,6 +11,6 @@
"not_coding": false,
"force": true
},
"result_file": "/tmp/pytest-of-mwells/pytest-115/build0/locidex.txt",
"analysis_end_time": "2024-04-04 15:51:06"
"result_file": "./locidex/example/format_db_mlst_out/locidex.txt",
"analysis_end_time": "2024-05-07 15:30:10"
}
Loading
Loading