-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9136640
commit 31e5bc3
Showing
6 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
# Persistent cache | ||
MAGNA_DIR = os.path.join(Path.home(), '.magna') | ||
|
||
# Temporary cache | ||
CACHE_DIR = os.path.join(tempfile.gettempdir(), 'magna') |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import Enum | ||
|
||
|
||
class GtdbRelease(Enum): | ||
R80 = '80' | ||
R83 = '83' | ||
R86 = '86' | ||
R89 = '89' | ||
R95 = '95' | ||
R202 = '202' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
from typing import Dict, Tuple | ||
|
||
from Bio import SeqIO | ||
from Bio.SeqRecord import SeqRecord | ||
|
||
from magna.gtdb.enums import GtdbRelease | ||
from magna.io import cache_file | ||
|
||
|
||
class Genome: | ||
|
||
def __init__(self, accession: str, root: str): | ||
self.accession: str = accession | ||
self.root: str = root | ||
|
||
# Generate paths | ||
base = os.path.basename(self.root) | ||
self.cds_path = os.path.join(self.root, f'{base}_cds_from_genomic.fna') | ||
self.fna_path = os.path.join(self.root, f'{base}_genomic.fna') | ||
|
||
def __repr__(self): | ||
return str(self.accession) | ||
|
||
def cds_seqio(self) -> Tuple[SeqRecord, ...]: | ||
# Returns the CDS generated from the FNA | ||
with open(self.cds_path, 'r') as f: | ||
out = tuple(SeqIO.parse(f, 'fasta')) | ||
return out | ||
|
||
def fna_seqio(self) -> Tuple[SeqRecord, ...]: | ||
# Returns the FNA | ||
with open(self.fna_path, 'r') as f: | ||
out = tuple(SeqIO.parse(f, 'fasta')) | ||
return out | ||
|
||
|
||
class GenomeDirs: | ||
|
||
def __init__(self, release: GtdbRelease): | ||
self.release = release | ||
|
||
# Create the paths | ||
srv_path = f'/srv/db/gtdb/genomes/ncbi/release{release.value}/genome_dirs.tsv' | ||
cache_path = cache_file(srv_path, f'genome_dirs_{self.release.value}.tsv') | ||
|
||
# Read the data | ||
self._data = self.read(cache_path) | ||
|
||
@staticmethod | ||
def read(path: str) -> Dict[str, str]: | ||
out = dict() | ||
with open(path, 'r') as f: | ||
for line in f: | ||
short, root, canonical = line.strip().split('\t') | ||
out[short] = root | ||
return out | ||
|
||
def get(self, accession: str) -> Genome: | ||
return Genome(accession=accession, root=self._data[accession]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters