<commit_before>'''
fastitr.py

Iterates through a FASTA or FASTQ file returning dnaobj objects from dnaobj.py

<NAME>
<EMAIL>
Triplett Lab, University of Florida
'''

from dnaobj import *

class fastitr:
    ''' iterates through a fasta or fastq file, returning dnaobj objects '''
    
    def __init__(self, handle, filetype):
    
        self.filetype = filetype
        self.handle = handle
        
    def __iter__(self):
    
        if self.filetype == 'fastq':
            counter = 0
            rec = { 0: '', 1: '', 2: '', 3: '' }
            
            for line in self.handle:
                if counter < 3:
                    rec[counter] = line.strip()
                    counter += 1
                elif counter == 3:
                    rec[counter] = line.strip()
                    counter = 0        
                    yield dnaobj(rec[0], rec[1], rec[3])
                    
        elif self.filetype == 'fasta':
            header = ''
            sequence = []
            for line in self.handle:
                if line[0] == '>':
                    if sequence: yield dnaobj(header, ''.join(sequence))
                    header = line.strip()
                    sequence = []
                else:
                    sequence.append(line)
                    
            yield dnaobj(header, ''.join(sequence))<commit_msg>forgot to strip last line of sequence when appending to sequence list<commit_after>'''
fastitr.py

Iterates through a FASTA or FASTQ file returning dnaobj objects from dnaobj.py

<NAME>
<EMAIL>
Triplett Lab, University of Florida
'''

from dnaobj import *

class fastitr:
    ''' iterates through a fasta or fastq file, returning dnaobj objects '''
    
    def __init__(self, handle, filetype):
    
        self.filetype = filetype
        self.handle = handle
        
    def __iter__(self):
    
        if self.filetype == 'fastq':
            counter = 0
            rec = { 0: '', 1: '', 2: '', 3: '' }
            
            for line in self.handle:
                if counter < 3:
                    rec[counter] = line.strip()
                    counter += 1
                elif counter == 3:
                    rec[counter] = line.strip()
                    counter = 0        
                    yield dnaobj(rec[0], rec[1], rec[3])
                    
        elif self.filetype == 'fasta':
            header = ''
            sequence = []
            for line in self.handle:
                if line[0] == '>':
                    if sequence: yield dnaobj(header, ''.join(sequence))
                    header = line.strip()
                    sequence = []
                else:
                    sequence.append(line.strip())
                    
            yield dnaobj(header, ''.join(sequence))
{'fraction_non_alphanumeric': 0.10415175375805297, 'fraction_numerical': 0.009305654974946313, 'mean_word_length': 1.2705117790414298, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3037090', 'n_tokens_mistral': 774, 'n_tokens_neox': 727, 'n_words': 214}