Example #1
0
 def __init__(self):
     self.data = FileReader('dataset.txt')
     self.data_list = self.data.e_read()
     self.A = 0
     self.C = 0
     self.G = 0
     self.T = 0
Example #2
0
class WordCount:
    def __init__(self):
        self.data = FileReader('dataset.txt')
        self.data_list = self.data.e_read()
        self.word_dict = {}

    def create_dictionary(self):
        try:
            for element in self.data_list:
                if element in self.word_dict:
                    self.word_dict.update(
                        {element: self.word_dict[element] + 1})
                else:
                    self.word_dict.update({element: 1})
            return True
        except Exception as e:
            print('Exception occurred while creating the dictionary; ' +
                  str(e))
            return False

    def create_output(self):
        try:
            output = []

            for element in self.word_dict:  # iterate through dictionary
                output.append(element + ' ' + str(self.word_dict[element]) +
                              '\n')

            self.data.write_to_file('output_6_file.txt', output)
            return '[OK]'
        except Exception as e:
            print('Exception occurred while creating the output; ' + str(e))
            return '[ERROR]'
Example #3
0
class Nucleotides:
    def __init__(self):
        self.data = FileReader('dataset.txt')
        self.data_list = self.data.e_read()
        self.A = 0
        self.C = 0
        self.G = 0
        self.T = 0

    # counts the nucleotides and
    def count_nucleotides(self):
        try:
            for nucleotide in self.data_list[0]:  # Iterate through nucleotides
                if nucleotide == 'A':
                    self.A += 1
                elif nucleotide == 'C':
                    self.C += 1
                elif nucleotide == 'G':
                    self.G += 1
                elif nucleotide == 'T':
                    self.T += 1
            return True
        except Exception as e:
            print('Exception occurred while creating the output; ' + str(e))

    def create_output(self):
        try:
            output = [self.A, self.C, self.G, self.T]
            self.data.write_to_file_7('output_7_file.txt', output)
            return '[OK]'
        except Exception as e:
            print('Exception occurred while creating the output; ' + str(e))
            return '[ERROR]'
Example #4
0
# Introduction to Bioinformatics 2019/20
# 8 - Treanscribing DNA into RNA

from h_read import FileReader


class RNA:
    def __init__(self, dna_string):
        self.dna_string = dna_string
        self.rna_string = ''

    # transcribes - replaces T with U
    def transcribe(self):
        for nucleotide in self.dna_string:
            if nucleotide == 'T':
                self.rna_string += 'U'
            else:
                self.rna_string += nucleotide
        return self.rna_string


if __name__ == '__main__':
    data = FileReader('dataset.txt')
    data_list = data.e_read()

    rna = RNA(data_list[0])
    print(rna.transcribe())
Example #5
0
 def __init__(self):
     self.data = FileReader('dataset.txt')
     self.data_list = self.data.e_read()
     self.word_dict = {}