<commit_before>###### ######

class FastqRead():
    def __init__(self, seq, seqid, qual):
        self.seq = seq
        self.seqid = seqid
        self.qual = qual
        
    def __str__(self):
        return '\n'.join([self.seqid, self.seq, '+', self.qual])
    
    def quality(self):
        qualities = map(ord, self.qual)
        return qualities

    def __len__(self):
        return len(self.seq)

    
###### ######

from evolib.formats.VCFcolumns import INFO, SAMPLE

class VCFheader(object):
    
    def __init__(self, header):
        self.names = header
        self.nsamples = len(header) - 9
        self.classes = [str, int, str, str, str, float, str, INFO, None] + [SAMPLE] * self.nsamples
        self.str_item = dict([(key, (self.classes[index], index)) for index, key in enumerate(header)])
        self.int_item = dict([(index, (self.classes[index], index)) for index, key in enumerate(header)])
        self.preamble = ''

    def __str__(self):
        return self.preamble

    
###### ######

class VCFrow(object):
    # row["CHROM"]
    # row[:2] -> refers only to samples

    # header.names = ['CHROM']
    # header.str_item = {'CHROM': (CHROM, 0), ...}
    # header.int_item = {0: (CHROM, 0), ...}

    def __init__(self, values, header, Format):
        self.values = values
        self.header = header
        self.Format = Format
        self.Format.value = self.values[8]
        self.nsamples = header.nsamples

    def __str__(self):
        return '\t'.join(self.values)

    def __getitem__(self, item):
        
        # 1 item costs 0.7s per 1 million rows (str lookup)
        # if statement along costs 0.5s per 1 million row (str lookup)
        if isinstance(item, str):
            itemClass, index = self.header.str_item[item]
        elif isinstance(item, int):
            itemClass, index = self.header.int_item[item]
        
        if index <= 8:
            # initialising an empty str class costs ~0.6s per 1 million rows (CHROM)
            value = itemClass(self.values[index])
            #value = self.values[index]
        else:
            value = itemClass(self.values[index], self.Format)

        return value

    def smap(self, mode, key):
        # currently ~ 8,500 rows/second (inc. CHROM and POS)
        return map(mode, (col.str_fetch(key) for col in self.iter_samples()))

    def iter_samples(self):
        
        maxRange = self.nsamples + 9
        SampleClass, index = self.header.int_item[9]

        for i in xrange(9, maxRange):
            yield SampleClass(self.values[i], self.Format, self.header.names[i])
        


###### ######

class GFFRecord():
    def __init__(self):
        self.exons = []
        self.name = None
        
    def add(self, items):
        if items[2] == "exon":
            self._exon(items)
        
        if self.name is None:
            self.name = items[0]
            
        try:
            self.records.append(items)<commit_msg>clearup<commit_after>###### ######

class FastqRead():
    def __init__(self, seq, seqid, qual):
        self.seq = seq
        self.seqid = seqid
        self.qual = qual
        
    def __str__(self):
        return '\n'.join([self.seqid, self.seq, '+', self.qual])
    
    def quality(self):
        qualities = map(ord, self.qual)
        return qualities

    def __len__(self):
        return len(self.seq)

    
###### ######

from evolib.formats.VCFcolumns import INFO, SAMPLE

class VCFheader(object):
    
    def __init__(self, header):
        self.names = header
        self.nsamples = len(header) - 9
        self.classes = [str, int, str, str, str, float, str, INFO, None] + [SAMPLE] * self.nsamples
        self.str_item = dict([(key, (self.classes[index], index)) for index, key in enumerate(header)])
        self.int_item = dict([(index, (self.classes[index], index)) for index, key in enumerate(header)])
        self.preamble = ''

    def __str__(self):
        return self.preamble

    
###### ######

class VCFrow(object):
    # row["CHROM"]
    # row[:2] -> refers only to samples

    # header.names = ['CHROM']
    # header.str_item = {'CHROM': (CHROM, 0), ...}
    # header.int_item = {0: (CHROM, 0), ...}

    def __init__(self, values, header, Format):
        self.values = values
        self.header = header
        self.Format = Format
        self.Format.value = self.values[8]
        self.nsamples = header.nsamples

    def __str__(self):
        return '\t'.join(self.values)

    def __getitem__(self, item):
        
        # 1 item costs 0.7s per 1 million rows (str lookup)
        # if statement alone costs 0.5s per 1 million row (str lookup)
        if isinstance(item, str):
            itemClass, index = self.header.str_item[item]
        elif isinstance(item, int):
            itemClass, index = self.header.int_item[item]
        
        if index <= 8:
            # initialising an empty str class costs ~0.6s per 1 million rows (CHROM)
            value = itemClass(self.values[index])
            #value = self.values[index]
        else:
            value = itemClass(self.values[index], self.Format)

        return value

    # currently broken as None items cannot be mapped
    #def smap(self, mode, key):
        # currently ~ 8,500 rows/second (inc. CHROM and POS)
    #    return map(mode, (col[key] for col in self.iter_samples()))

    def iter_samples(self):
        
        maxRange = self.nsamples + 9
        SampleClass, index = self.header.int_item[9]

        for i in xrange(9, maxRange):
            yield SampleClass(self.values[i], self.Format, self.header.names[i])
        


###### ######

class GFFRecord():
    def __init__(self):
        self.exons = []
        self.name = None
        
    def add(self, items):
        if items[2] == "exon":
            self._exon(items)
        
        if self.name is None:
            self.name = items[0]
            
        try:
            self.records.append(items)
{'fraction_non_alphanumeric': 0.1365771812080537, 'fraction_numerical': 0.0087248322147651, 'mean_word_length': 2.0584915341200616, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '1190371', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1828, 'n_words': 480}