Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,36 +23,40 @@ def extract_sequences(genome_data):
|
|
| 23 |
return start_sequence, end_sequence
|
| 24 |
|
| 25 |
def main():
|
| 26 |
-
#
|
| 27 |
-
input_file = "
|
| 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 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
main()
|
|
|
|
| 23 |
return start_sequence, end_sequence
|
| 24 |
|
| 25 |
def main():
|
| 26 |
+
# Prompt user for the input file name
|
| 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 |
+
try:
|
| 32 |
+
with open(input_file, 'r') as file:
|
| 33 |
+
accession_numbers = file.read().splitlines() # Read lines into a list
|
| 34 |
|
| 35 |
+
# Prepare lists to store sequences
|
| 36 |
+
starting_sequences = []
|
| 37 |
+
ending_sequences = []
|
| 38 |
|
| 39 |
+
for accession_number in accession_numbers:
|
| 40 |
+
genome_data = get_genome_from_ncbi(accession_number)
|
| 41 |
+
if genome_data:
|
| 42 |
+
start_sequence, end_sequence = extract_sequences(genome_data)
|
| 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 |
+
with open(output_start_file, 'w') as file:
|
| 48 |
+
for seq in starting_sequences:
|
| 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 |
+
except FileNotFoundError:
|
| 59 |
+
print("Error: The specified file was not found. Please check the file name and try again.")
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
main()
|