Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
def get_genome_from_ncbi(accession_number):
|
|
@@ -8,7 +9,7 @@ def get_genome_from_ncbi(accession_number):
|
|
| 8 |
if response.status_code == 200:
|
| 9 |
return response.text
|
| 10 |
else:
|
| 11 |
-
|
| 12 |
return None
|
| 13 |
|
| 14 |
def extract_sequences(genome_data):
|
|
@@ -23,14 +24,14 @@ def extract_sequences(genome_data):
|
|
| 23 |
return start_sequence, end_sequence
|
| 24 |
|
| 25 |
def main():
|
| 26 |
-
|
| 27 |
-
input_file = input("Enter the name of the input text file (with extension): ")
|
| 28 |
-
output_start_file = "starting_sequences.txt" # Output file for starting 55 base pairs
|
| 29 |
-
output_end_file = "ending_sequences.txt" # Output file for ending 114 base pairs
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Prepare lists to store sequences
|
| 36 |
starting_sequences = []
|
|
@@ -43,20 +44,13 @@ def main():
|
|
| 43 |
starting_sequences.append(f"{accession_number}: {start_sequence}")
|
| 44 |
ending_sequences.append(f"{accession_number}: {end_sequence}")
|
| 45 |
|
| 46 |
-
# Write starting sequences to file
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
file.write(seq + '\n')
|
| 50 |
-
|
| 51 |
-
# Write ending sequences to file
|
| 52 |
-
with open(output_end_file, 'w') as file:
|
| 53 |
-
for seq in ending_sequences:
|
| 54 |
-
file.write(seq + '\n')
|
| 55 |
-
|
| 56 |
-
print(f"Sequences extracted and saved to {output_start_file} and {output_end_file}.")
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
| 4 |
def get_genome_from_ncbi(accession_number):
|
|
|
|
| 9 |
if response.status_code == 200:
|
| 10 |
return response.text
|
| 11 |
else:
|
| 12 |
+
st.warning(f"Failed to retrieve genome for {accession_number}. Please check the accession number.")
|
| 13 |
return None
|
| 14 |
|
| 15 |
def extract_sequences(genome_data):
|
|
|
|
| 24 |
return start_sequence, end_sequence
|
| 25 |
|
| 26 |
def main():
|
| 27 |
+
st.title("NCBI Genome Sequence Extractor")
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# File uploader for the user to upload the input file
|
| 30 |
+
uploaded_file = st.file_uploader("Upload a text file containing accession numbers", type="txt")
|
| 31 |
+
|
| 32 |
+
if uploaded_file is not None:
|
| 33 |
+
# Read and split accession numbers from the uploaded file
|
| 34 |
+
accession_numbers = uploaded_file.read().decode("utf-8").splitlines()
|
| 35 |
|
| 36 |
# Prepare lists to store sequences
|
| 37 |
starting_sequences = []
|
|
|
|
| 44 |
starting_sequences.append(f"{accession_number}: {start_sequence}")
|
| 45 |
ending_sequences.append(f"{accession_number}: {end_sequence}")
|
| 46 |
|
| 47 |
+
# Write starting sequences to a file for download
|
| 48 |
+
start_sequences_text = "\n".join(starting_sequences)
|
| 49 |
+
st.download_button("Download Starting Sequences", start_sequences_text, file_name="starting_sequences.txt", mime="text/plain")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Write ending sequences to a file for download
|
| 52 |
+
end_sequences_text = "\n".join(ending_sequences)
|
| 53 |
+
st.download_button("Download Ending Sequences", end_sequences_text, file_name="ending_sequences.txt", mime="text/plain")
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|