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

Update state.py #1

Merged
merged 4 commits into from
Oct 6, 2023
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
52 changes: 49 additions & 3 deletions sanclone/state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
from pydantic import BaseModel
# -*- coding: utf-8 -*-
"""get_seq_annotation.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1dJEOj6Jw3qOHsxcsP-W3Uj7mbKhvWnHi
"""

from Bio import Entrez
from Bio import SeqIO


class State:
def __init__(self):
self.vector = None
self.linear_insert = None
self.clone_seq = None

def store_vector(self, vector):
if not isinstance(vector, SeqIO.SeqRecord):
raise ValueError("Input 'vector' must be a SeqRecord object from Biopython's SeqIO.")
self.vector = vector

def store_linear_insert(self, linear_insert):
# Ensure the linear_insert is a SeqRecord object from Biopython
if not isinstance(linear_insert, SeqIO.SeqRecord):
raise ValueError("Input 'linear_insert' must be a SeqRecord object from Biopython's SeqIO.")
self.linear_insert = linear_insert

def store_clone_seq(self, clone_seq):
# Ensure the linear_insert is a SeqRecord object from Biopython
self.clone_seq = clone_seq

def retrieve_vector(self):
return self.vector

def retrieve_linear_insert(self):
return self.linear_insert

def retrieve_clone_seq(self):
return self.clone_seq
# seq to annotation


def download_genbank_file(accession, filename):
Entrez.email = "tina.zetong.jia@example.com" # Always provide your email address when using NCBI's services
with Entrez.efetch(db="nucleotide", id=accession, rettype="gb", retmode="text") as handle:
with open(filename, 'w') as outfile:
outfile.write(handle.read())

class State(BaseModel):
pass
25 changes: 25 additions & 0 deletions tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,28 @@ def test_echo_tool():

tool = EchoTool(shared_state=State())
assert tool.run("Hello") == "Hello"

# def test_state_tool():
# from sanclone import State
# from sanclone.State import download_genbank_file
# accession_id_vector = "NC_005213"
# output_filename_vector = "NC_005213.gbk"
# accession_id_linear_insert = "NC_000932"
# output_filename_linear_insert = "NC_000932.gbk"
# download_genbank_file(accession_id_vector, output_filename_vector)
# download_genbank_file(accession_id_linear_insert, output_filename_linear_insert)

# for gb_record in SeqIO.parse(open(output_filename_linear_insert,"r"), "genbank") :
# # now do something with the record
# print ("Name %s, %i features" % (gb_record.name, len(gb_record.features)))

# vector_seq = list(SeqIO.parse(open(output_filename_vector,"r"), "genbank"))
# insert_seq = list(SeqIO.parse(open(output_filename_linear_insert,"r"), "genbank"))

# seq_anno = State(vector_seq[0])
# seq_anno.store_linear_insert(insert_seq[0])

# retrieved_vector = seq_anno.retrieve_vector()
# retrieved_insert = seq_anno.retrieve_linear_insert()
# print(retrieved_vector)
# print(retrieved_insert)
Loading