Jayesh13 commited on
Commit
ca02cf1
·
verified ·
1 Parent(s): 96d0940

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
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
- return sequence # Return the full sequence
 
 
 
 
 
 
 
 
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
- output_sequences = []
 
 
32
 
33
  for accession_number in accession_numbers:
34
  genome_data = get_genome_from_ncbi(accession_number)
35
  if genome_data:
36
- # Extract the sequence
37
- sequence = extract_sequences(genome_data)
38
- # Format the output as per the requirement
39
- output_sequence = f">{accession_number}\n{sequence}"
40
- output_sequences.append(output_sequence)
41
-
42
- # Create output text with the specified format
43
- output_text = "\n".join(output_sequences)
44
-
45
- # Provide a download button for the formatted output
46
- st.download_button("Download Sequences", output_text, file_name="formatted_sequences.txt", mime="text/plain")
 
 
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()