Following on from Python data structure learned by chemoinformatics, I will explain "conditional branching" with the theme of lipidomics (comprehensive analysis of lipids). We will mainly explain practical examples of chemoinformatics, so if you want to check the basics, please read the following article before reading this article.
Pharmaceutical researcher summarized Python control statements
As ʻif conditional expression:, describe the processing when the conditional expression is satisfied on the next line. The next line of ʻif
starts writing with indentation of 4 single-byte characters.
Un = 0
if Un == 0:
print('saturated fatty acid')
else:
print('unsaturated fatty acid')
ʻElse is used to describe the processing when the conditional expression following ʻif
does not hold.
If you want to divide the condition more finely, you can describe the processing when another condition is satisfied by using ʻelif conditional expression:. By the way, ʻelif
is an abbreviation for "else if".
In the above program, if the variable ʻUn indicating the degree of unsaturation (the number of double bonds of fatty acids) is 0, it is output as
saturated fatty acid (saturated fatty acid), and ʻUn
is other than 0. If it is a numerical value, it is output as ʻunsaturated fatty acid` (unsaturated fatty acid).
It is possible to specify multiple conditions in the conditional expression part.
Cn = 18
Un = 0
if Cn == 16 and Un == 0:
print('palmitic acid')
elif Cn == 18 and Un == 0:
print('stearic acid')
else:
print('other fatty acid')
In the conditional expression after ʻif, ʻand
means something like "katsu".
If you want to use "or", use ʻor`.
You can use the ʻin` operator to determine if an element is in the list.
fatty_acids = ['FA 16:0', 'FA 18:0', 'FA 18:1']
if 'FA 16:0' in fatty_acids:
print('Palmitic acid is included')
else:
print('Palmitic acid is not included')
Finally, as an application, let's consider determining whether it is a saturated fatty acid or an unsaturated fatty acid from the chemical structure described in SMILES notation.
smiles_fa = 'OC(CCCCCCCCCCCCCCC)=O'
if smiles_fa.count('=') <= 1:
print('saturated fatty acid')
else:
print('unsaturated fatty acid')
Whether it is an unsaturated fatty acid or not can be determined by whether or not the carbon chain contains a double bond. Since the carboxylic acid moiety also has a double bond, the above program determines if there are other double bonds.
Here, I explained about conditional branching in Python, focusing on practical knowledge that can be used in chemoinformatics. Let's review the main points again.
--The if statement describes the processing when the conditional expression is satisfied after breaking the line as ʻif conditional expression: and indenting four half-width spaces. If you want to subdivide the conditions, you can also use ʻelse
and ʻelif. --You can also use logical operators such as ʻand
and ʻor in conditional expressions. --You can use the ʻin
operator to determine if the specified element is included in the array.
Next, the following article explains Python iterative processing.
Iterative processing of Python learned by chemoinformatics
Surprisingly few! ?? "Minimum" knowledge required for programming in a pharmaceutical company
Recommended Posts