import gzip


def count_seq (filename, seq_type="fasta", gziped=False):
    """
    Count the number of sequences in a fastq or a fastq file
    @param filename Path to a valid readeable file
    @param file_type Should be either fastq or fastq. Default fasta
    @param gziped Boolean indicating if the file is gziped or not. Default False
    """
    #Standard library import

    # Verify if the file is fasta or fastq type
    assert seq_type in ["fasta", "fastq"], "The file has to be either fastq or fasta format"

    # Open the file
    if gziped:
        f = gzip.open(filename, "r")
    else:
        f = open(filename, "r")

    # FASTA Find a start line seq character ">" an increment the counter each time
    if seq_type ==  "fasta":
        nline = 0
        for line in f:
            if line[0] == ">":
                nline+=1
        f.close()
        return nline

    # FASTQ No motif to find, but 4 lines correspond to 1 sequence
    else:
        nline = 0
        for line in f:
            nline+=1
        f.close()
        return nline/4