# Computational biology at CSU

## DSCI 512: RNA-seq

### Questions?

examkey

This is an old revision of the document!

def gc_content(sequence):

```gc = 0
for nt in sequence:
if nt == 'G' or nt == 'C':
gc += 1
else:
continue
return gc/len(sequence)```

def word_count(input_file):

```try:
file_handle = open(input_file)
except:
return -1
lines = 0
chars = 0
with file_handle:
for line in file_handle:
line = line.rstrip()
chars += len(line)
lines += 1
return lines, chars```

def matrix_mean(matrix):

```l = []
for i in range(len(matrix)):
sum = 0
for n in range(len(matrix[0])):
sum += matrix[i][n]
l.append(sum/len(matrix[0]))
return l```

def element_counter(some_list):

```d = {}
for element in some_list:
d[element] = d.get(element, 0) + 1
return d```

def motif_coordinates(sequence, motif):

```for i in range(len(sequence) - len(motif) + 1):
if sequence[i:i+len(motif)] == motif:
return i+1, i+len(motif)
```

if name == 'main':

```print(gc_content('ATTGCC')) # 0.5
print(word_count('test.txt')) # (2, 6)
print(matrix_mean([[1,2,3],[5,6,7]])) # [2.0, 6.0]
print(element_counter(['ATG', 'TAG', 'TTT', 'TAG', 'TTT'])) # {'TAG': 2, 'TTT': 2, 'ATG': 1}
print(motif_coordinates('ATGCTGTTAGCGA', 'CGA')) # (11, 13)```
examkey.1544464322.txt.gz · Last modified: 2018/12/10 10:52 by dokuroot