Jayesh13 commited on
Commit
1e0d468
·
verified ·
1 Parent(s): 0f05186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -22
app.py CHANGED
@@ -23,36 +23,40 @@ def extract_sequences(genome_data):
23
  return start_sequence, end_sequence
24
 
25
  def main():
26
- # Read accession numbers from a text file
27
- input_file = "accession_numbers.txt" # Input file containing accession numbers
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
- with open(input_file, 'r') as file:
32
- accession_numbers = file.read().splitlines() # Read lines into a list
 
33
 
34
- # Prepare lists to store sequences
35
- starting_sequences = []
36
- ending_sequences = []
37
 
38
- for accession_number in accession_numbers:
39
- genome_data = get_genome_from_ncbi(accession_number)
40
- if genome_data:
41
- start_sequence, end_sequence = extract_sequences(genome_data)
42
- starting_sequences.append(f"{accession_number}: {start_sequence}")
43
- ending_sequences.append(f"{accession_number}: {end_sequence}")
44
 
45
- # Write starting sequences to file
46
- with open(output_start_file, 'w') as file:
47
- for seq in starting_sequences:
48
- file.write(seq + '\n')
49
 
50
- # Write ending sequences to file
51
- with open(output_end_file, 'w') as file:
52
- for seq in ending_sequences:
53
- file.write(seq + '\n')
54
 
55
- print(f"Sequences extracted and saved to {output_start_file} and {output_end_file}.")
 
 
 
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()