Exemple #1
0

# setup stuff: check for command line args, etc.
if __name__ == '__main__':
    # check if database name(s) passed on command line
    if len(sys.argv) > 1:
        fasta_files = sys.argv[1:]

    # if not, browse to database file
    else:
        database = r'C:\Xcalibur\database'  # set a default to speed up browsing
        if not os.path.exists(database):
            database = os.getcwd()
        fasta_files = fasta_lib.get_files(database,
                                          [('FASTA files', '*.fasta'),
                                           ('Zipped FASTA files', '*.gz'),
                                           ('All files', '*.*')],
                                          'Select a FASTA database')
        if not fasta_files: sys.exit()  # cancel button repsonse

    # print version info, etc. (here because of the loop)
    print('===============================================================')
    print(' count_fasta.py, v 1.1.0, written by Phil Wilmarth, OHSU, 2017 ')
    print('===============================================================')

    # call counter function for each fasta file
    print('start', time.ctime())
    for fasta_file in fasta_files:
        try:
            fasta_counter(fasta_file)
        except FileNotFoundError:  # FastaReader class raises exception if file not found
    return


# print program name and version
print('==========================================================')
print(' program check_fasta.py, v1.0.0, Phil Wilmarth, OHSU 2020 ')
print('==========================================================')

# browse to the database
database = r"C:\Xcalibur\database"
if not os.path.exists(database):
    database = os.getcwd()
file_ext_list = [('FASTA files', '*.fasta'), ('FASTA files', '*.fa'),
                 ('FASTA files', '*.gz')]
fasta_files = fasta_lib.get_files(database, file_ext_list, 'Select a FASTA database')
if not fasta_files:
    sys.exit()     # cancel button repsonse

# create a log file to mirror screen output
_folder = os.path.split(fasta_files[0])[0]
log_obj = open(os.path.join(_folder, 'fasta_utilities.log'), 'a')
write = [None, log_obj]
fasta_lib.time_stamp_logfile('\n>>> starting: check_fasta.py', log_obj)

# process the FASTA files
for fasta_file in fasta_files:
    try:
        fasta_checker(fasta_file, write)
    except FileNotFoundError:
        pass