From 561939379d3e08f42fa72b5bdabeefcfa7cfe169 Mon Sep 17 00:00:00 2001 From: tina-z-jia <145156075+tina-z-jia@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:23:09 -0700 Subject: [PATCH] Update state.py (#1) * Update state.py * Update class name to State * moving example to another file * default constructor --- sanclone/state.py | 52 +++++++++++++++++++++++++++++++++++++++++--- tests/test_sanity.py | 25 +++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/sanclone/state.py b/sanclone/state.py index dd7b818..657cedb 100644 --- a/sanclone/state.py +++ b/sanclone/state.py @@ -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 diff --git a/tests/test_sanity.py b/tests/test_sanity.py index 120d2d1..3cf8939 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -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) \ No newline at end of file