INNER CODE UNIT · Python
read_fasta
linsalrob/ComputationalGenomicsManual · Python/countfasta.py:16
def read_fasta(fname: str, whole_id: bool = False, qual: bool = False) -> dict:
"""
Read a fasta file and return a hash.
If wholeId is set to false only the first part of the ID
(upto the first white space) is returned
:param fname: The file name to read
:param whole_id: Whether to keep the whole id, or trim to first whitespace (default = all)
:param qual: these are quality scores (so add a space between lines!)
:return: dict
"""
try:
if fname.endswith('.gz'):
f = gzip.open(fname, 'rt')
elif fname.endswith('.lrz'):
f = subprocess.Popen(['/usr/bin/lrunzip', '-q', '-d', '-f', '-o-', fname], stdout=subprocess.PIPE).stdout