Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,15 @@ def extract_sequences(genome_data):
|
|
16 |
# Extract the sequence part from the FASTA format
|
17 |
lines = genome_data.splitlines()
|
18 |
sequence = ''.join(lines[1:]) # Join all lines except the first (which is the header)
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def main():
|
22 |
st.title("NCBI Genome Sequence Extractor")
|
@@ -28,22 +36,26 @@ def main():
|
|
28 |
# Read and split accession numbers from the uploaded file
|
29 |
accession_numbers = uploaded_file.read().decode("utf-8").splitlines()
|
30 |
|
31 |
-
|
|
|
|
|
32 |
|
33 |
for accession_number in accession_numbers:
|
34 |
genome_data = get_genome_from_ncbi(accession_number)
|
35 |
if genome_data:
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
main()
|
|
|
16 |
# Extract the sequence part from the FASTA format
|
17 |
lines = genome_data.splitlines()
|
18 |
sequence = ''.join(lines[1:]) # Join all lines except the first (which is the header)
|
19 |
+
|
20 |
+
# Get the first 55 and last 114 base pairs
|
21 |
+
start_sequence = sequence[:55] # First 55 base pairs
|
22 |
+
end_sequence = sequence[-114:] # Last 114 base pairs
|
23 |
+
|
24 |
+
return start_sequence, end_sequence
|
25 |
+
|
26 |
+
def format_fasta(accession_number, sequence):
|
27 |
+
return f">{accession_number}\n{sequence}"
|
28 |
|
29 |
def main():
|
30 |
st.title("NCBI Genome Sequence Extractor")
|
|
|
36 |
# Read and split accession numbers from the uploaded file
|
37 |
accession_numbers = uploaded_file.read().decode("utf-8").splitlines()
|
38 |
|
39 |
+
# Prepare lists to store formatted sequences
|
40 |
+
starting_sequences = []
|
41 |
+
ending_sequences = []
|
42 |
|
43 |
for accession_number in accession_numbers:
|
44 |
genome_data = get_genome_from_ncbi(accession_number)
|
45 |
if genome_data:
|
46 |
+
start_sequence, end_sequence = extract_sequences(genome_data)
|
47 |
+
formatted_start_sequence = format_fasta(accession_number, start_sequence)
|
48 |
+
formatted_end_sequence = format_fasta(accession_number, end_sequence)
|
49 |
+
starting_sequences.append(formatted_start_sequence)
|
50 |
+
ending_sequences.append(formatted_end_sequence)
|
51 |
+
|
52 |
+
# Write starting sequences to a file for download
|
53 |
+
start_sequences_text = "\n".join(starting_sequences)
|
54 |
+
st.download_button("Download Starting Sequences", start_sequences_text, file_name="starting_sequences.txt", mime="text/plain")
|
55 |
+
|
56 |
+
# Write ending sequences to a file for download
|
57 |
+
end_sequences_text = "\n".join(ending_sequences)
|
58 |
+
st.download_button("Download Ending Sequences", end_sequences_text, file_name="ending_sequences.txt", mime="text/plain")
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
main()
|