-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChromosome2.py
150 lines (111 loc) · 3.81 KB
/
Chromosome2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
import collections
# test string
randoDNA = "ATTGCGCGATA"
# opens DNAseq file, turns in into a variable, closes files again
human_ch21_FULL = open (r'C:\Users\Jenny\Desktop\HS_chromo21FULL.txt')
FULL_stored = human_ch21_FULL.read()
human_ch21_FULL.close()
# check if DNAseq is valid, meaning only ATCG, also turns all letter to uppercase
nucleos =["A", "C", "G", "T"]
def validateSeq(dna_seq):
tmpseq = dna_seq.upper()
for nuc in tmpseq:
if nuc not in nucleos:
return print ("Seq is INVALID")
return print ("Seq is valid", tmpseq)
# creates dictionary for nucleotides and pain-in-da-butt-other-letters
"""
def countNucFrequency (seq):
tmpFreqDict = {"A": 0, "C": 0, "G": 0, "T": 0, "\n": 0, "N": 0, "M": 0, "R": 0}
for nuc in seq:
tmpFreqDict[nuc] += 1
return tmpFreqDict
"""
# get rid of all the letters that are not ATCG
# creates dictionary via collections, same as above but shorter in code
def deleteNonNucleos (seq):
removeThis = ['N', 'R', 'M', '\n']
for character in removeThis:
seq = seq.replace(character,"")
return print (dict(collections.Counter(seq))), print ("Seq length:", len(seq))
# turn DNA strand into the cDNA and then transcribe it into RNA
# translate RNA into Polypeptide
# transcription
def transcription (seq):
for t in seq:
seq = seq.replace ("T","U")
return print (dict(collections.Counter(seq)))
def valiDeleTrans (seq):
tmpseq = seq.upper()
for nuc in tmpseq:
removeThis = ['N', 'R', 'M', '\n']
for character in removeThis:
seq = seq.replace(character,"")
seq = seq.replace ("T","U")
print (seq[0:20])
print ()
return print("First 20 nucleos:\n"),print (seq[0:20]),
print (dict(collections.Counter(seq))),
print ("Seq length:", len(seq))
# display of results
print ("_______________________________________________________________")
print ()
print ("Testcase DNAseq randoDNA: ")
print (validateSeq(randoDNA))
#print (countNucFrequency(randoDNA))
print ("_______________________________________________________________")
print ()
print ()
print ("_______________________________________________________________")
print ()
print ("DNAseq from file HS chromo21 FULL: " )
print ()
print (validateSeq(FULL_stored))
print ()
print ()
print ("Nucleotide proportions in the DNAseq from file")
print ()
#print (countNucFrequency(FULL_stored))
print ("_______________________________________________________________")
print ()
print ()
print ("_______________________________________________________________")
print ()
print ()
print ("_______________________________________________________________")
print ()
print ("Hopefully all non-Nucleo-letters were deleted")
print ()
print (deleteNonNucleos (FULL_stored))
print ()
print ("_______________________________________________________________")
print ()
print ("Transcribe DNA into RNA: the test seq")
print ("compare the seqs")
print ()
print ("test seq", randoDNA)
print ("into RNA", transcription(randoDNA))
print ()
print ()
print ("the whole chromosome: ")
print (transcription(FULL_stored))
print ()
print (dict(collections.Counter(FULL_stored)))
print ("_______________________________________________________________")
print ()
print ()
print ("All in one function: ")
print ()
print (valiDeleTrans(FULL_stored))
print ("_______________________________________________________________")
print ()
print (FULL_stored[0:20])
# die frage bleibt, wie sieht die verteilung der nicht-nukleotid buchstaben aus
#
# create the dataframe
data_frame = pd.read_csv(r'C:\Users\Jenny\Desktop\HS_chromo21FULL.txt', delimiter = "\t")