diff --git a/tests/test_transcript_structure.py b/tests/test_transcript_structure.py index 3535d8fcc228f0f79687f05ffdb2f72af5ae8622..b28f71ad32662715a163e49aa33b7ab50f55a81e 100644 --- a/tests/test_transcript_structure.py +++ b/tests/test_transcript_structure.py @@ -22,7 +22,7 @@ P_INTRON_1: float = 1 ) def test_csv_2_dict(test_input): builder = Gts.BuildTranscriptStructure(test_input[0], test_input[1], test_input[2]) - builder.__csv_2_dict() + builder._csv_2_dict() with open(TEST_CSV_TITLE) as csv: csv_lines = csv.readlines() first_line = csv_lines[0].split(',') @@ -38,7 +38,7 @@ def test_csv_2_dict(test_input): def test_gtf_2_dict(): builder = Gts.BuildTranscriptStructure(TEST_CSV_TITLE, GENE_COORDS, P_INTRON_0) - builder.__gtf_2_dict() + builder._gtf_2_dict() assert len(builder.gene_sequences_dict) == 2 # Two genes read in the dictionary. assert len(builder.gene_sequences_dict[GENE_KEYS[0]]) == 5 assert len(builder.gene_sequences_dict[GENE_KEYS[1]]) == 5 @@ -63,9 +63,9 @@ def test_gtf_2_dict(): ) def test_make_new_transcripts(test_input): builder = Gts.BuildTranscriptStructure(test_input[0], test_input[1], test_input[2]) - builder.__csv_2_dict() # Generates dictionary from gene count csv file. - builder.__gtf_2_dict() # Generates dictionary from gtf file. - builder.__make_new_transcripts() # Generates the differently spliced transcripts. + builder._csv_2_dict() # Generates dictionary from gene count csv file. + builder._gtf_2_dict() # Generates dictionary from gtf file. + builder._make_new_transcripts() # Generates the differently spliced transcripts. numb_trans_dict = 0 numb_trans_csv = 10 @@ -86,10 +86,10 @@ def test_make_new_transcripts(test_input): ) def test_make_gtf_lines(test_input): builder = Gts.BuildTranscriptStructure(test_input[0], test_input[1], test_input[2]) - builder.__csv_2_dict() # Generates dictionary from gene count csv file. - builder.__gtf_2_dict() # Generates dictionary from gtf file. - builder.__make_new_transcripts() # Generates the differently spliced transcripts. - builder.__make_gtf_info() + builder._csv_2_dict() # Generates dictionary from gene count csv file. + builder._gtf_2_dict() # Generates dictionary from gtf file. + builder._make_new_transcripts() # Generates the differently spliced transcripts. + builder._make_gtf_info() for line in builder.gtf_lines: columns = line.split('\t') assert columns[3] < columns[4] # Tests that the coordinates are increasing. @@ -104,10 +104,10 @@ def test_make_gtf_lines(test_input): ) def test_sort_gtf_lines(test_input): builder = Gts.BuildTranscriptStructure(test_input[0], test_input[1], test_input[2]) - builder.__csv_2_dict() # Generates dictionary from gene count csv file. - builder.__gtf_2_dict() # Generates dictionary from gtf file. - builder.__make_new_transcripts() # Generates the differently spliced transcripts. - builder.__make_gtf_info() + builder._csv_2_dict() # Generates dictionary from gene count csv file. + builder._gtf_2_dict() # Generates dictionary from gtf file. + builder._make_new_transcripts() # Generates the differently spliced transcripts. + builder._make_gtf_info() starts_before = [] # Verifies that the function actually has to sort. for line in builder.gtf_lines: @@ -116,9 +116,9 @@ def test_sort_gtf_lines(test_input): starts_before.append(columns[3]) for ii in range(len(starts_before)-1): assert starts_before[ii] > starts_before[ii+1] - builder.__sort_gtf_lines() + builder._sort_gtf_lines() - builder.__sort_gtf_lines() + builder._sort_gtf_lines() starts_after = [] # Verifies that the function sorted. for line in builder.gtf_lines: columns = line.split('\t') @@ -126,7 +126,6 @@ def test_sort_gtf_lines(test_input): starts_after.append(columns[3]) for ii in range(len(starts_before)-1): assert starts_after[ii] < starts_after[ii+1] - builder.__sort_gtf_lines() def test_write_gtf(): diff --git a/transcript_structure/Generate_transcript_structure.py b/transcript_structure/Generate_transcript_structure.py index bf491701edc078cd4a630c53d6726742f2e6b27e..31fc77a33ca0555051a45d1cf49edf2ca5fbf328 100644 --- a/transcript_structure/Generate_transcript_structure.py +++ b/transcript_structure/Generate_transcript_structure.py @@ -52,14 +52,14 @@ class BuildTranscriptStructure: def generate_transcript_structure(self): """Computes distribution and gene coordinates of differently spliced mRNA.""" - self.__csv_2_dict() # Generates dictionary from gene count csv file. - self.__gtf_2_dict() # Generates dictionary from gtf file. - self.__make_new_transcripts() # Generates the differently spliced transcripts. - self.__make_gtf_info() # Builds the gtf file of all newly created transcripts. - self.__sort_gtf_lines() # Sorts the gtf file by gene occurrence in sequence. + self._csv_2_dict() # Generates dictionary from gene count csv file. + self._gtf_2_dict() # Generates dictionary from gtf file. + self._make_new_transcripts() # Generates the differently spliced transcripts. + self._make_gtf_info() # Builds the gtf file of all newly created transcripts. + self._sort_gtf_lines() # Sorts the gtf file by gene occurrence in sequence. self._transcripts_generated = True # Adapts state variable. - def __csv_2_dict(self) -> None: + def _csv_2_dict(self) -> None: """Converts the csv file with gene count into a dictionary.""" with open(self.gene_count) as g_c: lines = g_c.readlines() @@ -72,7 +72,7 @@ class BuildTranscriptStructure: line_entries = line.split(',') self.gene_count_dict[line_entries[0]] = int(line_entries[1]) - def __gtf_2_dict(self) -> None: + def _gtf_2_dict(self) -> None: """Converts the gtf file into a nested dictionary.""" with open(self.input_coords) as c_g: # Reads coordinates from .gtf file. lines = c_g.readlines() @@ -109,7 +109,7 @@ class BuildTranscriptStructure: gene_info['exon_seq'] = coordinates self.gene_sequences_dict[gene_name] = gene_info - def __make_new_transcripts(self) -> None: + def _make_new_transcripts(self) -> None: """ Generates the differently spliced transcripts.""" for gene in self.gene_count_dict: @@ -135,7 +135,7 @@ class BuildTranscriptStructure: self.gene_transcript_dict[gene] = transcript_numbers - def __make_gtf_info(self) -> None: + def _make_gtf_info(self) -> None: """ Writes the lines of the new gtf file for the differently spliced transcripts.""" for gene in self.gene_transcript_dict: # Iterates over all genes required. self.gtf_lines.append(self.gene_sequences_dict[gene]['gene_line']) # Add gene line to list. @@ -188,7 +188,7 @@ class BuildTranscriptStructure: exon_lines.reverse() self.gtf_lines.extend(exon_lines) - def __sort_gtf_lines(self) -> None: + def _sort_gtf_lines(self) -> None: """ Sorts the gtf lines by the position of the genes (increasing) and returns it."""