Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions students/lavrentiy-danilov/codewars/week2_solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# 1. Human Readable Time https://www.codewars.com/kata/52685f7382004e774f0001f7/train/python

```python
def make_readable(seconds):
hours = seconds // 3600
minutes = (seconds - hours*3600) // 60
sec = seconds - hours*3600 - minutes*60
if len(str(hours)) == 1:
hours = '0'+ str(hours)

if len(str(minutes)) == 1:
minutes = '0' + str(minutes)

if len(str(sec)) == 1:
sec = '0' + str(sec)
return f'{hours}:{minutes}:{sec}'
```

# 2. Isograms https://www.codewars.com/kata/54ba84be607a92aa900000f1/train/python

```python
def is_isogram(string):
letter_set = []
for el in string.upper():
if el not in letter_set:
letter_set.append(el)
else:
out = False
try:
out
except NameError:
out = True
return out
```

# 3. Categorize New Member https://www.codewars.com/kata/5502c9e7b3216ec63c0001aa/train/python
```python
def openOrSenior(data):
result=[]
for _ in data:
if _[0]>=55 and _[1]>7:
result.append('Senior')
else:
result.append('Open')
return result
```

# 4. Vasya https://www.codewars.com/kata/555615a77ebc7c2c8a0000b8/train/python

```python
def tickets(people):
l=[0,0]
for i in people:
if i==25:
l[0]+=1
elif i==50:
if l[0]==0:
return "NO"
else:
l[0]-=1
l[1]+=1
else:
if l[1]>=1:
if l[0]==0:
return "NO"
else:
l[0]-=1
l[1]-=1
else:
if l[0]<3:
return "NO"
else:
l[0]-=3
return "YES"
```

# 5. The Supermarket Queue https://www.codewars.com/kata/57b06f90e298a7b53d000a86
```python
def queue_time(customers, n):
list_temp = [0]*n
for item in customers:
list_temp[list_temp.index(min(list_temp))] += item
return max(list_temp)
```

# 6. Sum of a sequence https://www.codewars.com/kata/586f6741c66d18c22800010a
```python
def sequence_sum(begin_number, end_number, step):
sum_tot = int()
for i in range(begin_number, end_number+1, step):
sum_tot+=i
```

# 7. Sum of a Beach https://www.codewars.com/kata/5b37a50642b27ebf2e000010
```python
def sum_of_a_beach(beach):
name_list = ["sand", "water", "fish", "sun"]
tot_sum = 0
for el in name_list:
tot_sum += beach.lower().count(el)
return tot_sum
```


# 8. Alphabet war https://www.codewars.com/kata/59377c53e66267c8f6000027
```python
def alphabet_war(fight):
count = 0
left = {'w': 4, 'p': 3, 'b': 2, 's': 1}
right = {'m': 4, 'q': 3, 'd': 2, 'z': 1}
for i in fight:
if i in left:
count += left[i]
elif i in right:
count -= right[i]
if count < 0:
return "Right side wins!"
if count > 0:
return "Left side wins!"
elif count == 0:
return "Let's fight again!"
```

# 9. Create Phone Number https://www.codewars.com/kata/525f50e3b73515a6db000b83
```python
def create_phone_number(n):
begin = "".join([str(elem) for elem in n[0:3]])
middle = "".join([str(elem) for elem in n[3:6]])
end = "".join([str(elem) for elem in n[6:]])

return f'({begin}) {middle}-{end}'
```

# 10. Rot13 https://www.codewars.com/kata/530e15517bc88ac656000716
```python
def rot13(message):
def decode(c):
if 'a' <= c <= 'z':
base = 'a'
elif 'A' <= c <= 'Z':
base = 'A'
else:
return c
return chr((ord(c) - ord(base) + 13) % 26 + ord(base))
return "".join(decode(c) for c in message)
```

# 11. Strip Comments https://www.codewars.com/kata/51c8e37cee245da6b40000bd/train/python

```python
def solution(string, markers):
lines = string.split('\n')
for i, line in enumerate(lines):
for marker in markers:
index = line.find(marker)
if index != -1:
line = line[:index]
lines[i] = line.rstrip(' ')
return '\n'.join(lines)
```






8 changes: 8 additions & 0 deletions students/lavrentiy-danilov/kunin/chapter2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Знаю - Правило чаргафф, репликация ДНК, комплиментраность, принцип подвеженной оибкам репликации, молекулярные часы, притяжене длинных ветвей, метод ближайших соседей, бутстреппинг, синапоморфия, гомоплазия, нейтральная теория, эгоистичный ген, ортологи, паралоги
Плохо знаю- maximum parsimony



1. Из-за каких особенностей эволюции при постоении филогенетики происходит эффект приближения дальних ветвей?
2. Для каких функциональных единциц необхоимо анализировать различия по последовательности ДНК, а для каких по белковой последовательности?
3. Определение ортологов и паралогов достаточно явны, а кто такие гены онтологи?
201 changes: 201 additions & 0 deletions students/lavrentiy-danilov/rosalind/week2_solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# 1. Let's Be Practical (http://rosalind.info/problems/ini/)

```python
def count_letters_DNA(path):
with open(path) as fl:
seq = fl.readline()[:-1]
seq_right = seq.upper()
return "{} {} {} {}".format(seq_right.count('A'), seq_right.count('C'), seq_right.count('G'), seq_right.count('T'))
```

# 2. Four Commonly Used Protein Databases


```python
from Bio import ExPASy
from Bio import SwissProt

def get_go_protein(protein_name)

handle = ExPASy.get_sprot_raw(protein_name)
record = SwissProt.read(handle)

bio_proc = []
for item in record.cross_references:
if item[0] == 'GO' and item[2][0]=='P':
bio_proc.append(item[2].lstrip('P:'))

return '\n'.join(bio_proc)
```


# 3. New Motif Discovery http://rosalind.info/problems/meme/

```python
import os
from subprocess import call

data, width, output= input().split()
CMD = f"meme {data} -text -protein -minw {width} > {output}"

if __name__ == '__main__':
c = call(CMD, shell=True)

with open(output) as outfile:
for line in outfile:
if 'regular expression' in line:
separator = outfile.readline()
reg = outfile.readline().rstrip()
break

os.remove('outfile')
print(reg)
```

# 4. GenBank Introduction http://rosalind.info/problems/gbk/

```python
from Bio import Entrez

def genbank(path_to_file):
with open(path_to_file, 'r') as fl:
lines = [line.rstrip('\n') for line in fl]
Entrez.email = "lavrentydanilov@gmail.com"
term = '%s[Organism] AND (%s[Publication Date] : %s[Publication Date])' % (lines[0], lines[1], lines[2])
handle = Entrez.esearch(db="nucleotide", term=term)
record = Entrez.read(handle)
return record["Count"]
```

# 5. Data Formats http://rosalind.info/problems/frmt/

```python
from Bio import Entrez
from Bio import SeqIO

def genbank_short_seq(path_ids):
Entrez.email = "lavrentydanilov@gmail.com"
with open(path_ids, 'r') as fl:
ids = fl.readline()
ids = ids.replace(" ", ", ")

# Fetch data from GenBank server
handle = Entrez.efetch(db="nucleotide", id=ids, rettype="fasta")
records = list(SeqIO.parse(handle, "fasta"))

rec = min(records, key=len)

print('>' + rec.description)
print(rec.seq)
genbank_short_seq('rosalind_frmt.txt')
```

# 6. FASTQ format introduction http://rosalind.info/problems/tfsq/

```python
from Bio import SeqIO

def converter(fastq):
SeqIO.convert(fastq, "fastq", "tfsq_fasta.txt", "fasta")


converter('rosalind_tfsq.txt')
```


# 7. Read Quality Distribution http://rosalind.info/problems/phre/

```python
from Bio import SeqIO

def create_files(path_to_file):

with open('rosalind_phre.txt', 'r') as f:
threshold = f.readline()
lines = f.readlines()

with open('rosalind_phre_1.txt', 'w') as f:
f.writelines(lines[:])

def average(l):
return sum(l) / float(len(l))

def qthreshold(threshold, fastq):
handle = SeqIO.parse(fastq, "fastq")

belowthreshold = 0
for record in handle:
if average(record.letter_annotations["phred_quality"]) < int(threshold):
belowthreshold += 1

return belowthreshold

if __name__ = '__main__':
create_files('rosalind_phre.txt')
qthreshold(threshold, 'rosalind_phre_1.txt')
```

# 8. Read Filtration by Quality http://rosalind.info/problems/filt/

```python
from functools import reduce


def get_incorrect_phred(path):
with open(path, 'r') as f_read:
threshold, percentage = map(int, f_read.readline().split())

a = f_read.readlines()
filtered = 0

for i in range(3, len(a), 4):
qualities = [ord(char) - 33 for char in a[i].strip()]
filt = reduce(lambda x, y: x + (y >= threshold), qualities, 0) / len(qualities) * 100
filtered += filt >= percentage

return filtered


get_incorrect_phred(input())
```

# 9. Base Quality Distribution http://rosalind.info/problems/bphr/

```python
def quality_distribution(path):
with open(path) as fr:
threshold = int(fr.readline())

a = fr.readlines()
low = 0
for i in range(len(a[1].strip())):
qualities = sum(ord(a[j][i]) - 33 for j in range(3, len(a), 4)) / (len(a) // 4)

low += qualities < threshold

return low

quality_distribution('rosalind_bphr.txt')
```

# 10. Base Filtration by Quality http://rosalind.info/problems/bfil/
```python
from Bio import SeqIO

def Base_Filtration_Quality(data):
records = []
with open(data, "r") as f:
t = int(f.readline().strip())
for record in SeqIO.parse(f, "fastq"):
phred = record.letter_annotations["phred_quality"]
start, end = 0, len(phred)
while phred[start] < t:
start += 1
while phred[end-1] < t:
end -= 1
print(record[start:end].format('fastq'))

if __name__ == "__main__":
data = input()
Base_Filtration_Quality(data)
```
Loading