<jupyter_start><jupyter_text>Mission statementI'd like to teach you * What I think is advanced Python* Give you my view on how to code (and how not to code)* Introduce you to     * code structure    * code testing    * code documentation* Show case some useful python modules (that you might know of or not)* \[ What you want to learn \]  Project show cases  pymzMLpymzML is an extension to Python that offers* easy access to mass spectrometry (MS) data that allows the rapid development of tools* a very fast parser for mzML data, the standard mass spectrometry data format* a set of functions to compare and/or handle spectra* random access in compressed files* interactive data visualization<NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>; pymzML v2.0: introducing a highly compressed and seekable gzip format, Bioinformatics, doi: https://doi.org/10.1093/bioinformatics/bty046T Bald, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>; pymzML - Python module for high-throughput bioinformatics on mass spectrometry data, Bioinformatics, doi: https://doi.org/10.1093/bioinformatics/bts066 |![](https://travis-ci.org/pymzml/pymzML.svg?branch=master)|![](https://ci.appveyor.com/api/projects/status/4nlw52a9qn22921d?svg=true)|![](https://readthedocs.org/projects/pymzml/badge/?version=latest)|![](https://codecov.io/gh/pymzml/pymzml/branch/master/graph/badge.svg)|![](https://img.shields.io/pypi/v/pymzML.svg)|![](https://pepy.tech/badge/pymzml)|![](https://img.shields.io/badge/code%20style-black-000000.svg)||:---:|:---:|:---:|:---:|:---:|:---:|:---:||[travis](https://travis-ci.org/pymzml/pymzML)|[appveyor](https://ci.appveyor.com/project/fufezan-lab/pymzml)|[rtd](http://pymzml.readthedocs.io/en/latest/?badge=latest)|[codecov](https://codecov.io/gh/pymzml/pymzml)|[pypi](https://pypi.org/project/pymzML/)|[pepy](https://pepy.tech/project/pymzml)|[black](https://github.com/psf/black)|  pyQmspyQms is an extension to Python that offers amongst other things* fast and accurate quantification of all high-res LC-MS data* full labeling and modification flexibility* full platform independenceLeufken, J., <NAME>., <NAME>., <NAME>., <NAME>., <NAME>., and <NAME>. (2017) pyQms enables universal and accurate quantification of mass spectrometry data. MCP, https://doi.org/10.1074/mcp.M117.068007|![](https://travis-ci.org/pyQms/pyqms.svg?branch=master)|![](https://ci.appveyor.com/api/projects/status/n4x2ug7h3ce4d49y?svg=true)|![](https://readthedocs.org/projects/pyqms/badge/?version=latest)|![](https://img.shields.io/pypi/v/pyqms.svg)|![](https://img.shields.io/badge/code%20style-black-000000.svg)||:---:|:---:|:---:|:---:|:---:||[travis](https://travis-ci.org/pyQms/pyqms)|[appveyor](https://ci.appveyor.com/project/fufezan-lab/pyqms)|[rtd](http://pyqms.readthedocs.io/en/latest/?badge=latest)|[pypi](https://pypi.org/project/pyqms/)|[black](https://github.com/psf/black)|  ursgalursgal - Universal Python Module Combining Common Bottom-Up Proteomics Tools for Large-Scale Analysis* Peptide spectrum matching with up to eight different search engines (some available in multiple versions), including three open modification search engines* Evaluation and post processing of search results with up to two different engines* Integration of search results from different search engines* De novo sequencing with up to two different search engines* Miscellaneous tools including the creation of a target decoy database as well as filtering, sanitizing and visualizing of results<NAME>., <NAME>.(2015) Ursgal, Universal Python Module Combining Common Bottom-Up Proteomics Tools for Large-Scale Analysis, Journal of Proteome research, 15, 788-.DOI:10.1021/acs.jproteome.5b00860*|![](https://travis-ci.org/ursgal/ursgal.svg?branch=master)|![](https://ci.appveyor.com/api/projects/status/hel9rowah1u3rfe1?svg=true)|![](http://readthedocs.org/projects/ursgal/badge/?version=latest)|![](https://badge.fury.io/py/ursgal.svg)||:---:|:---:|:---:|:---:||[travis](https://travis-ci.org/ursgal/ursgal)|[appveyor](https://ci.appveyor.com/project/fufezan-lab/ursgal)|[rtd](http://ursgal.readthedocs.io/en/latest/?badge=latest)|[pypi](https://badge.fury.io/py/ursgal/)|  a lasting name http://proteomicsnews.blogspot.com/2017/02/ursgal-combine-all-python-proteomics.html  Python beginner recap  Python basic type * int* float* str* list* tuple* set* dictHave been covered else where. Quick recap, what's the outcome of these lines ...<jupyter_code>a = 34 + 3.2
type(a)<jupyter_output><empty_output><jupyter_text>In the next cell the syntax is:a[start:stop:step]So if there is no start and stop as in the next example, everything is taken. If the step is negative, it is printed backwards.<jupyter_code>a = "Never odd" + " or even"
a[::-1]<jupyter_output><empty_output><jupyter_text>If stop contains a negative value as in the next example, the last 4 characters are not printed.<jupyter_code>a[:-4]<jupyter_output><empty_output><jupyter_text>If start contains a negative value, it starts in the back instead in the beginning.<jupyter_code>a[-4:]
a[-4:-1:2]<jupyter_output><empty_output><jupyter_text>In the next example a error is put out, as strings are unchangeable. Here a qucik summary of other data types1. List is a collection which is ordered and changeable. Allows duplicate members.2. Tuple is a collection which is ordered and unchangeable. Allows duplicate members.3. Set is a collection which is unordered, unchangeable, and unindexed. No duplicate members.4. Dictionary is a collection which is ordered* and changeable. No duplicate members.<jupyter_code>a[0] = 'n'<jupyter_output><empty_output><jupyter_text>The split function splits strings after the character in the brackets, which is empty in the following case, therefore after every space the string is splitted.<jupyter_code>a.split()<jupyter_output><empty_output><jupyter_text>The output is of the type list.<jupyter_code>type(a.split())<jupyter_output><empty_output><jupyter_text>In the following a dictionary is created. The first element are the keys, the second the values. They can be of ANY type!<jupyter_code>b = { (12,32): "Well done ... "}
b<jupyter_output><empty_output><jupyter_text>In the next cell we work with sets. As mentioned above sets are collections which are unordered, unchangeable, and unindexed. No duplicate members.The sets can contain any data type, but lists and dicts as these are mutableThey can be created with these brackets: {XXX} or with the command set(). In this command round () as well as square [] brackets can be used. In the following it is shown, how set unions can be created with this: | operator or with .union().<jupyter_code>x1 = {'foo', 'bar', 'baz'}
x2 = {'baz', 'qux', 'quux'}
x1 | x2
x1.union(x2)<jupyter_output><empty_output><jupyter_text>The operation x1 - x2 puts out the differences between those, meaning all elements that are in x1, but not in x2.<jupyter_code>set([12, 13, 14]) - set([13, 14, 15])<jupyter_output><empty_output><jupyter_text>The operator & gives the intersection.<jupyter_code>set([12, 13, 14]) & set([13, 14, 15])<jupyter_output><empty_output><jupyter_text>Python comparisons * \>* \>=* ==* <=* <* isHave been covered elsewhere. Quick recap, what's the outpcome of these lines ...<jupyter_code>a = 42
39.9 < a <= 42<jupyter_output><empty_output><jupyter_text>In the next example, the string is the same, but a is not the same as b, they are still different variables, but with the same content. That means a is not b but a contains the same (==) as b.<jupyter_code>a = "Nature is lethal but it doesn't hold a candle to man."
b = "Nature is lethal but it doesn't hold a candle to man."
print("a is b?", a is b)
print("a == b", a == b)<jupyter_output>a is b? False
a == b True<jupyter_text>In the following example it is shown, that in the if statement it is important, to not only write "if authentication" but to add "is True" to define exactly what the input should be like to pass the password. If not doing so, the password is not only given for authentication == True, but also for example for a filled list, as this is True per definition.<jupyter_code>def release_password(authentication=False):
    answer = "Not authenticated"
    if authentication:
        answer = "Here is your password"
    return answer
release_password(authentication=True)
release_password(authentication=[1])
release_password(authentication=[])<jupyter_output><empty_output><jupyter_text>Fix it<jupyter_code># thinking that objects eval to the same ensures equality is one major source of errors
def release_password(authentication=False):
    answer = "Not authenticated"
    if authentication == True:
        answer = "Here is your pasword"
    return answer<jupyter_output><empty_output><jupyter_text>Evaluating objects<jupyter_code>print("[] is True?", [] is True)
print("[1] is True?", [1] is True) 
print("[] == True?", [] == True)
print("[1] == True?", [1] == True) 
print("bool([]) == True?", bool([]) == True)
print("bool([1]) == True?", bool([1]) == True)<jupyter_output>bool([]) == True? False
bool([1]) == True? True<jupyter_text>Other operators  membership operators<jupyter_code>'dog' in 'Not sure I went out with the dOg'
'dog' in ('d0g', 'dOg', 'dog', 'dot')<jupyter_output><empty_output><jupyter_text>logical operators<jupyter_code>(1 is True)<jupyter_output><>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
<>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
C:\Users\miche\AppData\Local\Temp/ipykernel_18740/789980067.py:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
  (1 is True)<jupyter_text>What is the "or" operator in Python?In short, the Python or operator returns the first object that evaluates to true or the last object in the expression, regardless of its truth value. In this example, the Python or operator returns the first true operand it finds, or the last one. This is the rule of thumb to memorize how or works in Python.<jupyter_code>(1 is True) or (1 == True) 
# Does not have to be boolean operations ... though imho less readable
4 or 3<jupyter_output><empty_output><jupyter_text>Object references The id() command returns the id of a variable, which is not the same for another variable, even if they have the same content.<jupyter_code>a = "Test!"
id(a)<jupyter_output><empty_output><jupyter_text>In the following first the value, then the id of a and then b is printed with the format command.Short intro to the format command: using format() methodprint('I love {} for "{}!"'.format('Geeks', 'Geeks'))Output:I love Geeks for "Geeks!"  using format() method and referring a position of the objectprint('{0} and {1}'.format('Geeks', 'Portal'))Output: Geeks and PortalSo with format values can be put into the brackets and then be referred in the print statement with indices.But back to the id:When we define a to be b, then the value and id are the same. Once we change the value of one of them, both, value and id are not identical anymore, as the id changes when the value is changed.<jupyter_code>a = 0
b = a
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)  # True
print("Adding 1 to a..")
a += 1
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)<jupyter_output>a = 0  id:1759245723920
b = 0  id:1759245723920
a is b? True
Adding 1 to a..
a = 1  id:1759245723952
b = 0  id:1759245723920
a is b? False<jupyter_text>For dictionaries this is not the same. Here if we add a value, the dictionary id stays the same, the first value also stays the same, and only a value is added. That simply means that is is mutuable or in other words you can change it/its values.<jupyter_code>a = {13: 14}
b = a
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)
print("Adding 12 to a..")
a[12] = 12
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)<jupyter_output>a = {13: 14}  id:1759312542784
b = {13: 14}  id:1759312542784
a is b? True
Adding 1 to a..
a = {13: 14, 12: 12}  id:1759312542784
b = {13: 14, 12: 12}  id:1759312542784
a is b? True<jupyter_text>immutable vs mutable For lists its is the same as for dicts as both are mutable as described before.<jupyter_code>a = [0]
b = a
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)
print("Adding 1 to a..")
a[0] = 1
print("a = {0}  id:{1}".format(a, id(a)))
print("b = {0}  id:{1}".format(b, id(b)))
print("a is b?", a is b)<jupyter_output>a = [0]  id:1759312923392
b = [0]  id:1759312923392
a is b? True
Adding 1 to a..
a = [1]  id:1759312923392
b = [1]  id:1759312923392
a is b? True
{'fraction_non_alphanumeric': 0.14277856357064278, 'fraction_numerical': 0.03371051390853371, 'mean_word_length': 5.184159378036929, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 113, 'https://': 31, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '23', 'dir': 'jupyter-structured-clean-dedup', 'id': '395137', 'license': 'CC0-1.0', 'n_tokens_mistral': 4621, 'n_tokens_neox': 4241, 'n_words': 1414, 'path': 'notebooks/01.b_Recaps.ipynb', 'repo_name': 'MichelleEmmert/advanced_python_2021-22_HD', 'size': '12851'}