http://wiki.bi.up.ac.za/wiki/index.php?title=Special:NewPages&feed=atom&limit=50&offset=&namespace=0&username=&tagfilter=Centre for Bioinformatics and Computational Biology - New pages [en]2022-01-18T05:26:11ZFrom Centre for Bioinformatics and Computational BiologyMediaWiki 1.23.13http://wiki.bi.up.ac.za/wiki/index.php/AboutAbout2019-08-08T06:21:23Z<p>Johann: </p>
<hr />
<div>Black Mamba is a discussion group hosted by the Centre for Bioinformatics and Computational Biology.<br />
<br />
The aim of the discussion group is to expose people to a wide variety of different topics ranging from biology to mathematics and computer sciences. Post-graduate studies often require individuals to focus on only certain topics relevant to their field of study. This creates a situation where many people have very specialised skill sets. With a trend towards cross disciplinary research it has become more important than ever that scientists have an understanding of not only their field of research but also surrounding fields.<br />
<br />
The group does not function on a student-teacher dynamic. Each week is chaired by the most knowledgeable person in the topic being discussed. This person's role is to influence and steer discussion, not necessarily teach the group.<br />
<br />
Open discussion is actively encouraged. With no one person knowing all there is to know about any topic it becomes important that everyone in the group actively interacts to ensure that topics are explored in as wide a scope as possible.<br />
<br />
'''Topics that have been discussed by the group:'''<br />
* Git<br />
* Databases and SQL<br />
* Python basics<br />
* Machine Learning<br />
* Pipeline creation (nextflow and snakemake)</div>Hstrydomhttp://wiki.bi.up.ac.za/wiki/index.php/PythonPython2019-06-20T06:11:45Z<p>Hstrydom: /* Conditionals */</p>
<hr />
<div>=== Variables ===<br />
==== Declaration and typing ====<br />
'''Keyword:''' Declaring variables, variable assignment, boolean values, integers, floats, strings, lists, dictionaries (ordered dictionaries, default dictionaries), tuples, sets, mutable and immutable data types, variable typing.<br />
<source lang="python"><br />
####<br />
# Boolean variables can only contain one of two values: True or False<br />
# Boolean values are annotated by using the "bool" keyword<br />
a: bool = True<br />
####<br />
<br />
####<br />
# Integers are variables that contain any positive or negative whole number<br />
# Integers are annotated using the "int" keyword<br />
# Floats are variables that contains any positive or negative decimal<br />
# Floats are annotated using the "float" keyword<br />
a: int = 15<br />
b: int = -23<br />
<br />
c: float = 6.4<br />
d: float = -9.5<br />
####<br />
<br />
####<br />
# Strings are variables that contain text<br />
# Strings are annotated using the "str" keyword<br />
a: str = "This is a string"<br />
b: str = 'Strings can be enclosed using single quotes'<br />
<br />
# Initializing an empty string:<br />
a = ""<br />
####<br />
<br />
####<br />
# Lists are collections of other variables<br />
# Lists are annotated using the "list" keyword<br />
a: list = ["Some string", 15, 9.6, True]<br />
<br />
# Initializing an empty list:<br />
a = []<br />
####<br />
<br />
####<br />
# Sets are lists that cannot contain duplicate values<br />
# They also do not keep the order of the variables<br />
# Sets are a lot faster than lists when looking for specific values<br />
# Sets are annotated using the "set" keyword<br />
a: set = {"Some string", 15, 9.6, True}<br />
<br />
# Initializing an empty set:<br />
a = set()<br />
####<br />
<br />
####<br />
# Tuples are lists that cannot be changed after being created<br />
# They are useful when returning multiple values from a function<br />
# Tuples are annotated using the "tuple" keyword<br />
a: tuple = ("Some string", 15, 9.6, True)<br />
<br />
# Because tuples cannot be changed there is no point in initializing an empty one<br />
####<br />
<br />
####<br />
# Dictionaries work of Key - Value pairs<br />
# Keys can be any immutable type - integers, floats, strings and tuples<br />
# Dictionaries do not keep the their order<br />
# Dictionaries are annotated using the "dict" keyword<br />
a: dict = {"A": "Some string", "B": 15, "C": 9.6, "D": True}<br />
<br />
# Initializing an empty dictionary:<br />
a = {}<br />
####<br />
</source><br />
<br />
==== Casting ====<br />
'''Keywords:''' Casting<br />
<source lang="python"><br />
# Only certain operations can be performed on certain types of variables<br />
# Changing between types of variables is called "casting"<br />
a: str = "15"<br />
<br />
b: int = int(a) # b = 15<br />
c: float = float(b) # c = 15.0<br />
d: str = str(c) # d = "15.0"<br />
</source><br />
<br />
==== Mathematical operations ====<br />
'''Keywords:''' Operators, string concatenation, list concatenation<br />
<source lang="python"><br />
####<br />
# Integers and floats support most arithmetic operations<br />
a = 15<br />
b = 6<br />
<br />
c = a + b # c = 21<br />
c = a - b # c = 9<br />
c = a * b # c = 90<br />
c = a / b # c = 2.5<br />
<br />
# There are some special operators:<br />
# modulus (%) returns what is left after division<br />
# floor division (//) throws away the decimal place<br />
c = a % b # c = 3<br />
c = a // b # c = 2<br />
####<br />
<br />
####<br />
# Strings only support 2 mathematical operators<br />
# The addition (+) is used to concatenate strings<br />
# The multiplication (*) returns multiples of a string<br />
a = "Hello"<br />
b = "World"<br />
<br />
c = a + b # c = "HelloWorld"<br />
c = a * 3 # c = "HelloHelloHello"<br />
####<br />
<br />
####<br />
# Lists, tuples can be added to each other<br />
# It concatenates the collections together<br />
a = ["Hello", 15]<br />
b = [9.6, True]<br />
<br />
c = a + b # c = ["hello", 15, 9.6, True]<br />
####<br />
<br />
####<br />
# You can use "mathematical shorthand" to make some code more readable<br />
# Shorthand is supported for all operators and works with strings, numbers, lists and tuples<br />
a = 12<br />
b = "Hello"<br />
c = "World"<br />
<br />
a = a + 6 # Normal way<br />
a += 6 # Shorthand gives the same result<br />
<br />
b = b + c # Normal way, c = "HelloWorld"<br />
b += c # Shorthand gives the same result<br />
####<br />
</source><br />
<br />
==== Modifying collections ====<br />
'''Keywords:''' Collections, lists, tuples, dictionaries, sets<br />
<source lang="python"><br />
####<br />
# LISTS<br />
# You can add values to a list by using the append() method:<br />
a = []<br />
<br />
a.append("Hello")<br />
a.append(15)<br />
a.append(True)<br />
<br />
print(a) # a = ["Hello", 15, True]<br />
####<br />
<br />
####<br />
# SETS<br />
# You can add values to a list by using the add() method<br />
# A list of values can be added to a set by using the update() method<br />
a = set()<br />
b = [15, 9.6, True]<br />
<br />
a.add("Hello")<br />
a.update(b)<br />
<br />
print(a) # a = {"Hello", 15, 9.6, True}<br />
####<br />
<br />
####<br />
# TUPLES<br />
# Tuples cannot be added to, they do not change<br />
####<br />
<br />
####<br />
# DICTIONARIES<br />
# You can add a new value pair by assigning the key to a value<br />
a = {}<br />
<br />
a["A"] = "Hello"<br />
a["B"] = 15<br />
a["C"] = 9.6<br />
a["D"] = True<br />
<br />
print(a) # a = {"A": "Hello", "B": 15, "C": 9.6, "D": True}<br />
####<br />
</source><br />
<br />
=== Conditionals ===<br />
'''Keywords:''' Logical operators, and, or, not, in, if statement, if else, else if, try catch blocks, exception handling.<br />
==== If statement ====<br />
<source lang="python"><br />
# If statements are used when you want to do something when a condition is met<br />
# The if or elif part occurs when the condition returns true<br />
# The else part occurs when none of the previous conditions returned true<br />
a = 12<br />
b = 15<br />
<br />
# The example below will return "Did the elif" because b > a<br />
if a > b:<br />
print("Did the if")<br />
elif b > a: # Condition returns true<br />
print("Did the elif")<br />
else:<br />
print("Did the else")<br />
<br />
# The operators available:<br />
# > < >= <= ==<br />
# != (not equal) can be used or the keyword "not"<br />
<br />
# If you want to create more complex conditions you can make use of "and", "or" and "in"<br />
# And requires that all conditionals return true<br />
# Or requires that one of the conditionals return true<br />
# In returns true if a certain value is found inside a collection<br />
a = [15, 9, 6]<br />
b = 6<br />
<br />
if 15 in a:<br />
print("Found it")<br />
<br />
# Would not run the code inside the if statement<br />
if (15 in a) and (b > 9):<br />
print("The item is in the list and 6 > 9")<br />
<br />
# Would run the code inside the if statement<br />
if (15 in a) or (b > 9):<br />
print("The item is in the list or 6 > 9?")<br />
<br />
# You can have calculations and function calls inside conditions:<br />
if (15 + 2) > b:<br />
print("17 > 6")<br />
</source><br />
<br />
==== Try except ====<br />
<br />
=== Loops ===<br />
=== Functions ===<br />
=== Classes ===</div>Hstrydom