´
(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?
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?
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?
What:
* All you would like to share!
Prefer Google forms? Use https://docs.google.com/forms/d/e/1FAIpQLSdoUvYpr4jSLkNtuH6y_K7pNMvU5FJGuipKLl4lWYGAGCHhLQ/viewform?usp=sf_link
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
![image alt](https:// "title") | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | Emoji list | ||
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing