Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rendrick27 committed Apr 23, 2024
1 parent 72bbe4c commit daa01b0
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions ASCN_Download.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/usr/bin/env python3

from Bio import Entrez
import sys


def fetch_sequences(database, accession_numbers):
"""
Fetch sequences from NCBI database using accession numbers.
Args:
database (str): Database name to fetch sequences from.
accession_numbers (list): List of accession numbers.
Returns:
None
"""
Entrez.email = "fakeemail@exemplo.com"
Entrez.tool = "fetch_sequences.py"

Expand All @@ -19,24 +28,47 @@ def fetch_sequences(database, accession_numbers):
print(f"Error fetching sequences: {e}")
sys.exit(1)

if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: python fetch_sequences.py [database] [file_path_to_accession_numbers]")
sys.exit(1)

database = sys.argv[1]
file_path = sys.argv[2]

def read_accession_numbers(file_path):
"""
Read accession numbers from a file.
Args:
file_path (str): Path to the file containing accession numbers.
Returns:
list: List of accession numbers.
"""
try:
with open(file_path) as file:
# Filter out empty lines and strip whitespace from each line
accession_numbers = [line.strip() for line in file if line.strip()]
return accession_numbers
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
sys.exit(1)


def main():
"""
Main function to execute the script.
"""
if len(sys.argv) != 3:
print("Usage: python fetch_sequences.py [database] "
"[file_path_to_accession_numbers]")
sys.exit(1)

database = sys.argv[1]
file_path = sys.argv[2]

accession_numbers = read_accession_numbers(file_path)

if not accession_numbers:
print("Error: No accession numbers found in the file.")
sys.exit(1)

fetch_sequences(database, accession_numbers)


if __name__ == '__main__':
main()

0 comments on commit daa01b0

Please sign in to comment.