owned this note changed a year ago
Linked with GitHub

Intro to Python Day 5

2.2 Review Day 4 answers: questions?

3.7 regexone notes: questions?

´
(Anastasiia, Umea): Hi! Is it possible to define constant parts (let's say a sequence) and then use variables in regex instead of printing the same constant parts many times (especially if they are long - it takes a lot of time)? If yes, how to do it? Maybe you can show an example/or just comment it. Thanks a lot!
e.g. I have AAAAATTTTTCTCCCCCCCCCCT as a constant part
and i have AAAAATTTTTCTCCCCCCCCCCTTATATATTATAT my seq which should match
and AAAAATTTTTCTCCCCCCTGGGCGCGCGGCGCGCGGCGC which should not
how to write regex?

3.8 Exercise 1, discuss code: questions?

4.16 Putting is_chess_square in your code

4.20 A: Fix is_chess_square

I don't get how the funcition solves the problem

(LuzMa, Upps):1. If a function needs a module can import it within the function?
2. Can a function A call another function B that is defined somewhere else in the code, is it not recommended?

4.23 Questions about today’s theory?

question from wednesday(sorry, a bit late): what is sys.argv
Reminder: Anastasiias question above

R: I hope that helped!

(Anastasiia, Umea): Hi! Is it possible to define constant parts (let's say a sequence) and then use variables in regex instead of printing the same constant parts many times (especially if they are long - it takes a lot of time)? If yes, how to do it? Maybe you can show an example/or just comment it. Thanks a lot!
e.g. I have AAAAATTTTTCTCCCCCCCCCCT as a constant part
and i have AAAAATTTTTCTCCCCCCCCCCTTATATATTATAT my seq which should match
and AAAAATTTTTCTCCCCCCTGGGCGCGCGGCGCGCGGCGC which should not
how to write regex?

could you please copy-paste your code! THANKS :~)

R: Hmm, Anastasiia was not the only one copy-pasting :-)

import re

def get_std_pattern():
  """
  Get the string that is part
  of all the other regexes
  """
  return "AAAAATTTTTCTCCCCCCCCCCT"


assert get_std_pattern() == "AAAAATTTTTCTCCCCCCCCCCT"

def does_match_to_std_pattern(s):
  r = re.compile(get_std_pattern())
  return bool(r.match(s))

assert does_match_to_std_pattern("AAAAATTTTTCTCCCCCCCCCCT")
assert does_match_to_std_pattern("AAAAATTTTTCTCCCCCCCCCCTTTTTTTTTTTTTT")
assert not does_match_to_std_pattern("TTTTTTTTTTTTAAAAATTTTTCTCCCCCCCCCCT")
assert not does_match_to_std_pattern("TTTTTTT")

J: Sidenote: You can also use variables when creating the regular expression, as the expressions are just text stings.
Examples:

  common_seq = "AAAAATTTTTCTCCCCCCCCCCT"
  # the following matches if common_seq is at the beginning:
  r = re.compile("^"+common_seq)
  # the folowing matches if common_seq is followed by G or C:
  q = re.compile(common_seq+"[GC]")

R: More questions?

5.4 Evaluation

  • Using welcoming and inclusive language
  • Focusing on what is best for the community
  • Showing empathy towards other community members

What:

​​​​ * All you would like to share!
  • Need guidance? Share a good thing and a thing that can be improved on the course, course material, the teachers together/individually, etc.

Prefer Google forms? Use https://docs.google.com/forms/d/e/1FAIpQLSdoUvYpr4jSLkNtuH6y_K7pNMvU5FJGuipKLl4lWYGAGCHhLQ/viewform?usp=sf_link

Select a repo