Skip to content

Commit

Permalink
added tofasta
Browse files Browse the repository at this point in the history
  • Loading branch information
haeussma committed May 11, 2024
1 parent b3981b6 commit e41320f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
1 change: 0 additions & 1 deletion pyeed/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .dnarecord import DNARecord
from .ontology import Ontology
from .organism import Organism
from .pairwisealignment import PairwiseAlignment
from .pairwisealignmentresult import PairwiseAlignmentResult
from .proteinrecord import ProteinRecord
from .region import Region
Expand Down
83 changes: 45 additions & 38 deletions pyeed/core/proteinrecord.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import os
import warnings
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, List, Optional
Expand All @@ -15,7 +14,6 @@
from sdRDM.base.listplus import ListPlus
from sdRDM.tools.utils import elem2dict

from pyeed.container.abstract_container import Blastp
from pyeed.fetch.blast import Blast, BlastProgram, NCBIDataBase
from pyeed.fetch.proteinfetcher import ProteinFetcher

Expand Down Expand Up @@ -385,42 +383,42 @@ def ncbi_blast(

return asyncio.run(ProteinFetcher(ids=accessions).fetch(force_terminal=False))

def blastp(
self,
db_path: str,
identity: float = 0,
evalue: float = 10,
n_hits: int = 500,
subst_matrix: str = "BLOSUM62",
word_size: int = 3,
gapopen: int = 11,
gapextend: int = 1,
threshold: int = 11,
n_cores: int = os.cpu_count(),
ncbi_key: str = None,
email: str = None,
):
blaster = Blastp(
_db_path=db_path,
identity=identity,
evalue=evalue,
n_hits=n_hits,
subst_matrix=subst_matrix,
word_size=word_size,
gapopen=gapopen,
gapextend=gapextend,
threshold=threshold,
n_cores=n_cores,
ncbi_key=ncbi_key,
)

command = blaster.setup_command()
accession_ids = blaster.run_container(
command=command, data=self._fasta_string()
)
protein_infos = ProteinRecord.get_ids(accession_ids, email, ncbi_key)
protein_infos.insert(0, self)
return protein_infos
# def blastp(
# self,
# db_path: str,
# identity: float = 0,
# evalue: float = 10,
# n_hits: int = 500,
# subst_matrix: str = "BLOSUM62",
# word_size: int = 3,
# gapopen: int = 11,
# gapextend: int = 1,
# threshold: int = 11,
# n_cores: int = os.cpu_count(),
# ncbi_key: str = None,
# email: str = None,
# ):
# blaster = Blastp(
# _db_path=db_path,
# identity=identity,
# evalue=evalue,
# n_hits=n_hits,
# subst_matrix=subst_matrix,
# word_size=word_size,
# gapopen=gapopen,
# gapextend=gapextend,
# threshold=threshold,
# n_cores=n_cores,
# ncbi_key=ncbi_key,
# )

# command = blaster.setup_command()
# accession_ids = blaster.run_container(
# command=command, data=self._fasta_string()
# )
# protein_infos = ProteinRecord.get_ids(accession_ids, email, ncbi_key)
# protein_infos.insert(0, self)
# return protein_infos

def get_dna(self):
if not self.coding_sequence_ref:
Expand All @@ -432,6 +430,15 @@ def _nblast(sequence: str, n_hits: int = None) -> List["ProteinRecord"]:
# blast_record = NCBIXML.read(result_handle)
raise NotImplementedError("This method is not implemented yet.")

def fasta_string(self) -> str:
return f">{self.id}\n{self.sequence}"

def to_fasta(self, path: str):
with open(path, "w") as f:
f.write(self.fasta_string())

print(f"💾 Sequence saved to {path}")

@staticmethod
def _get_accessions(blast_record: NCBIXML) -> List[str]:
return [alignment.accession for alignment in blast_record.alignments]
Expand Down
1 change: 1 addition & 0 deletions pyeed/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 1 addition & 2 deletions tests/unit/alignment_tests/test_hmm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Generated by CodiumAI
"""
from pyeed.core.alignment import Alignment
Expand All @@ -21,4 +20,4 @@ def test_initialized_with_name_and_alignment(self):
assert hmm.alignment == alignment
assert hmm.model is None
"""
"""

0 comments on commit e41320f

Please sign in to comment.