DL
https://stepik.org/course/135003/promo?search=2085495338
https://stepik.org/course/125587/promo?search=2085495348
https://stepik.org/course/4852/syllabus
Решаю задачи по физике, математике. Пишу посты по естественным и точным наукам, а также программированию.
DL
https://stepik.org/course/135003/promo?search=2085495338
https://stepik.org/course/125587/promo?search=2085495348
https://stepik.org/course/4852/syllabus
matplotlib
https://devpractice.ru/matplotlib-lesson-1-quick-start-guide/
_____________________________________________
Смотрела стили графиков тут https://www.data-to-viz.com/caveats.html
событие - это точка начала, точка конца, они соединены горизонтальной линией, линии разнесены по горизонтали (order by date_start)
Точки, соединенные линиями https://r-graph-gallery.com/connected_scatterplot_ggplot2.html
Библиотека для работы со временем https://r-graph-gallery.com/191-manage-date-data.html
График можно сделать интерактивным https://r-graph-gallery.com/163-interactive-area-chart-plotly.html
__________________
Здравствуйте, Дмитрий. По поводу того как можно отображать события в виде горизонтальных линий (где по оси х - время).
Входные данные - это время начала и конца события и его название. Можно все сделать "в лоб": написать функцию, которая, предобработав входные данные, будет рисовать эти горизонтальные линии (geom_point, geom_segment), разнося их по вертикали.
А нет ли для этого уже готовых решений? Не буду ли я тут "изобретать велосипед"?
__________________
https://timeline.knightlab.com/#overview
import sys sys.setrecursionlimit(1500)
Any recursive function can be made to iterate (into a loop) but you need to use a stack yourself to keep the state.
Normally, tail recursion is easy to convert into a loop:
A(x) {
if x<0 return 0;
return something(x) + A(x-1)
}
Can be translated into:
A(x) {
temp = 0;
for i in 0..x {
temp = temp + something(i);
}
return temp;
}
Other kinds of recursion that can be translated into tail recursion are also easy to change. The other require more work.
The following:
treeSum(tree) {
if tree=nil then 0
else tree.value + treeSum(tree.left) + treeSum(tree.right);
}
Is not that easy to translate. You can remove one piece of the recursion, but the other one is not possible without a structure to hold the state.
treeSum(tree) {
walk = tree;
temp = 0;
while walk != nil {
temp = temp + walk.value + treeSum(walk.right);
walk = walk.left;
}
}
https://github.com/davetang/human_phenotype_ontology/blob/master/README.md
https://www.taylorfrancis.com/books/mono/10.1201/b10967/introduction-bio-ontologies-peter-robinson-sebastian-bauer
m = [8, 4, 6] res = ''for i0 in range(m[0]+1): res += str(i0) for i1 in range(m[1]+1): res += str(i1) for i2 in range(m[2] + 1): res += str(i2) print(res) def recursion(iter_num, iter_val, res): if iter_num < len(m): if iter_val <= m[iter_num]: res += str(iter_val) res = recursion(iter_num + 1, 0, res) return recursion(iter_num, iter_val + 1, res) else: return res else: return res print(recursion(0, 0, ''))
2.3) да нет нет
2.17) бактерий на k-ом шаге будет 2^k n - 2^k k. Отсюда видно, что через n шагов все бактерии будут съеден
2.18) как? 99*2 только если сразу попадется правдивей
2.19)
s = input() n = int(input()) alphabet = s.split(' ') def cycle(res, k): if k > 1: new_res = [] for r in range(len(res)): for i in alphabet: new_res.append(res[r] + i) return cycle(new_res, k-1) else: return res for i in cycle(alphabet, n): print(i)
import copy import math def permutations(my_set, perm): if len(my_set) > 0: res = [] for s in my_set: new_my_set = copy.deepcopy(my_set) new_my_set.remove(s) for j in permutations(new_my_set, perm + str(s)): res.append(j) return res else: return [perm] def lenn_sets(my_set, res, k): if k > 1: new_res = [] for r in range(len(res)): for i in my_set: new_res.append(res[r] + i) return lenn_sets(my_set, new_res, k-1) else: return res n = 6r1 = permutations(list(range(1,n+1)), '') my_set2 = ['+', '-'] r2 = lenn_sets(my_set2, copy.deepcopy(my_set2), n) f = open('sign.txt', 'w') f.write(str(int(math.factorial(n)*math.pow(2, n)))+'\n') for r_1 in r1: for r_2 in r2: l = '' for i in range(n): l += r_2[i] + r_1[i] + ' ' f.write(l.replace('+', '')+'\n') f.close()
s = input() def complementary(a, b): if (a == 'A' and b == 'T') or (a == 'T' and b == 'A') or (a == 'G' and b == 'C') or (a == 'C' and b == 'G'): return True else: return False res = [] for i in range(1, 6): if complementary(s[i - 1], s[i]): j = 1 while j < i: if complementary(s[i - 1 - j], s[i + j]): res.append([i-j, 2 * (j+1)]) j += 1 else: breakfor i in range(6, len(s)-5): if complementary(s[i - 1], s[i]): j = 1 while j < 6: if complementary(s[i - 1 - j], s[i + j]): res.append([i - j, 2 * (j+1)]) j += 1 else: breakfor i in range(len(s)-5, len(s)-1): if complementary(s[i - 1], s[i]): j = 1 while j < len(s)-i: if complementary(s[i - 1 - j], s[i + j]): res.append([i - j, 2 * (j+1)]) j += 1 else: breakfor r in res: print(''.join(str(r[0])) + ' ' + ''.join(str(r[1])))
import re import rosalind_lib f = open('splc.txt', 'r') strings = re.findall(r'(>Rosalind_[0-9]+)\n(([A-Z]+\n)+)', f.read()) rna = strings.pop(0)[1].replace('\n','').replace('T', 'U') introns = {} for s in strings: intron = s[1].replace('\n','').replace('T', 'U') rna = rna.replace(intron,'') print(rosalind_lib.rna_to_protein(rna))
t = '010's = '0111010100001'print(s.find(t)) - first position
def substring_positions(s,t): res = [] for i in range(len(s) - len(t) + 1): flag = True for j in range(len(t)): if s[i + j] != t[j]: flag = False break if flag: res.append(str(i)) return res
def kmp(s,t, limit = 1): # building prefix table pt for s # it's i-th element shows, how many steps go backward on s # if there will be a mismatch with t string pt = [0] for m in s[1:]: j = pt[-1] while j > 0 and m != s[j]: j = pt[j-1] if m == s[j]: j += 1 pt.append(j) # walk through the s res = [] j = 0 # number or symbols matched with t for i in range(len(s)): while j > 0 and s[i] != t[j]: j = pt[j - 1] if s[i] == t[j]: j += 1 if j == len(t): res.append(i - j + 1) if len(res) == limit: return res j = 0 return res
import sys def chem_recorder(data_set): while len(data_set) > 0: new_data_set = set() for add_chem in data_set: if add_chem not in chem_in_cell: chem_in_cell.add(add_chem) if add_chem in chems_lines: counter = 0 for chem_line in chems_lines[add_chem]: chem_line[0].remove(add_chem) if len(chem_line[0].difference(chem_in_cell)) == 0: new_add = chem_line[1].difference(chem_in_cell) new_data_set = new_data_set.union(new_add) chems_lines[add_chem].pop(counter) counter += 1 data_set = new_data_set.copy() all_lines = sys.stdin.readlines() in_cell = all_lines.pop(0) chem_in_cell = set(in_cell.strip().split(' ')) xxx = set(in_cell.strip().split(' ')) chems_lines = {} # 'chem' => [[{left_line1}, {right_line1}], [{left_line2}, {right_line2}]]for line in all_lines: line = line.strip() l1 = line.split('->') left_line = set(l1[0].split('+')) right_line = set(l1[1].split('+')) not_in_cell_chem = left_line.difference(chem_in_cell) if len(not_in_cell_chem) > 0: for nic_chem in not_in_cell_chem: if nic_chem in chems_lines: flag = 0 for chem_line in chems_lines[nic_chem]: if chem_line[0] == not_in_cell_chem: chem_line[1] = chem_line[1].union(right_line) flag = 1 break if flag == 0: chems_lines[nic_chem].append([not_in_cell_chem, right_line]) else: chems_lines[nic_chem] = [[not_in_cell_chem, right_line]] else: # gote all chems chem_recorder(right_line) chem_recorder(xxx) print(' '.join(chem_in_cell))
import sys import math def norm(str1, str2): return math.fabs(int(str1) - int(str2)) def check_perfect(s): len_s = len(s) loops_tops = [] for i in range(1, len_s): if norm(s[i], s[i - 1]) == 1: loops_tops.append(i) if len(loops_tops) == 0: return False for start in loops_tops: step_right = 0 step_left = 1 move = True while move: right = int(s[start + step_right]) left = int(s[start - step_left]) if (right == 9) or (left == 9): move = False elif norm(left, right) != 1: move = False else: s[start + step_right] = '9' s[start - step_left] = '9' if ((start + step_right + 1) >= len_s) or ((start - step_left - 1) < 0): move = False step_right += 1 step_left += 1 new_s = [x for x in s if x != '9'] len_new_s = len(new_s) if len_new_s == 0: return True else: if len_new_s == len_s: return False else: return check_perfect(new_s) def check_perfect_if_one_hole(s): len_s = len(s) if len_s == 1: return True holed_tops = [] for i in range(2, len_s): if norm(s[i], s[i - 2]) == 1: holed_tops.append(i - 1) for hole in holed_tops: s1 = s.copy() del s1[hole] if check_perfect(s1): return True loops_tops = [] for i in range(1, len_s): if norm(s[i], s[i - 1]) == 1: loops_tops.append(i) if len(loops_tops) == 0: return False for start in loops_tops: step_right = 0 step_left = 1 move = True while move: right = int(s[start + step_right]) left = int(s[start - step_left]) if (right == 9) or (left == 9): move = False elif norm(left, right) != 1: if (start + step_right + 1) < len_s: if norm(int(s[start + step_right + 1]), left) == 1: s1 = s.copy() del s1[start + step_right] if check_perfect(s1): return True if (start - step_left - 1) > -1: if norm(right, int(s[start - step_left - 1])) == 1: s1 = s.copy() del s1[start - step_left] if check_perfect(s1): return True move = False else: s[start + step_right] = '9' s[start - step_left] = '9' if ((start + step_right + 1) >= len_s) or ((start - step_left - 1) < 0): move = False step_right += 1 step_left += 1 new_s = [x for x in s if x != '9'] len_new_s = len(new_s) if len_new_s == len_s: return False else: return check_perfect_if_one_hole(new_s) s0 = sys.stdin.readline() s0 = s0.replace('\n', '') s1 = s0.replace('U', '2') s2 = s1.replace('A', '1') s3 = s2.replace('G', '5') s4 = s3.replace('C', '6') s = list(s4) lens = len(s) if lens % 2 == 0: if check_perfect(s): print('perfect') else: print('imperfect') else: if check_perfect_if_one_hole(s): print('almost perfect') else: print('imperfect')
Hint:One could notice that the previous Dynamic Programming solution resembles the solutions for problems with bracket sequences. We could see a perfect string as a correct bracket sequence and we check the correctness of bracket sequences using stack!
import sys def complementary(a, b): if (a == 'A' and b == 'U') or (a == 'U' and b == 'A') or (a == 'G' and b == 'C') or (a == 'C' and b == 'G'): return True else: return False def go_stack(str): stack = [] for i in str: if len(stack) > 0: if complementary(stack[-1], i): stack.pop() else: stack.append(i) else: stack.append(i) return stack s = sys.stdin.readline().strip() stack = go_stack(s) len_stack = len(stack) if len_stack == 0: print('perfect') else: if len_stack % 2 == 0: print('imperfect') else: stack.pop(int((len_stack - 1)/2)) stack2 = go_stack(stack) if len(stack2) == 0: print('almost perfect') else: print('imperfect')
import collections def twin(km): return Seq.reverse_complement(km)def kmers(seq,k): for i in xrange(len(seq)-k+1): yield seq[i:i+k]def fw(km): for x in 'ACGT': yield km[1:]+xdef bw(km): for x in 'ACGT': yield x + km[:-1] def build(fn,k=31,limit=1): d = collections.defaultdict(int) with open('tests/1', 'r') as f: main_string = f.readline() for line in f.readlines()[2:]: line = line.strip()
for km in kmers(seq,k): d[km] +=1 seq = twin(seq) for km in kmers(seq,k): d[km] += 1 d1 = [x for x in d if d[x] <= limit] for x in d1: del d[x] return d def get_contig_forward(d,km): c_fw = [km] while True: if sum(x in d for x in fw(c_fw[-1])) != 1: break cand = [x for x in fw(c_fw[-1]) if x in d][0] if cand in c_fw: break if sum(x in d for x in bw(cand)) != 1: break c_fw.append(cand) return c_fw def get_contig(d,km): c_fw = get_contig_forward(d,km) c_bw = get_contig_forward(d,twin(km)) c = [twin(x) for x in c_bw[-1:0:-1]] + c_fw s = c[0] + ''.join(x[-1] for x in c[1:]) return s,c def all_contigs(d): done = set() r = [] for x in d: if x not in done: s,c = get_contig(d,x) for y in c: done.add(y) done.add(twin(y)) r.append(s) return r