# FILE: compute-average-fasta.py # AUTHOR: William Stafford Noble # CREATE DATE: 18 January 2007 # PROJECT: GENOME 559 import sys # Make sure we got a filename on the command line. if (len(sys.argv) != 2): print("USAGE: count-fasta.py ") sys.exit(1) # Open the file for reading. fasta_file = open(sys.argv[1], "r") num_seqs = 0 total_chars = 0.0 for line in fasta_file: # Increment the sequence count or the character count. if (line[0] == ">"): num_seqs += 1 else: # Error check: Make sure we don't have sequence before ID. if (num_seqs == 0): print("Invalid FASTA format.") sys.exit(1) # Subtract one for the end-of-line character. total_chars += len(line) - 1 print( total_chars / num_seqs) fasta_file.close()