Looks like no one added any tags here yet for you.
Variables and Data Types
# Strings and numbers
name = "GirlyPop"
age = 16
is_excited = True
Think of variables as cute little containers where you store data. Python supports different data types like numbers, strings (text), and booleans (true/false).
Lists and Dictionaries
# List: storing multiple values
outfits = ["Dress", "Jeans", "Sweater"]
print(outfits[0]) # Prints: Dress
# Dictionary: key-value pairs
wardrobe = {"top": "blouse", "bottom": "skirt"}
print(wardrobe["top"]) # Prints: blouse
Lists are like shopping bags; you can store multiple items, and dictionaries are your fashion closet where each item has a label!
Loops
# For loop
for outfit in outfits:
print(outfit) # Prints each outfit in the list
# While loop
count = 0
while count < 3:
print("GirlyPop Power!")
count += 1
Loops help you repeat tasks, like scrolling through Instagram, but with control. for
loops go through lists, and while
loops keep going until you say "stop."
Functions
Functions are like reusable routines. You write them once, and then you can call them anytime—like your fave skincare routine.
def get_outfit(day):
if day == "Monday":
return "Blazer and Jeans"
elif day == "Friday":
return "Party Dress"
else:
return "Casual Look"
# Call the function
today_outfit = get_outfit("Monday")
print(today_outfit) # Prints: Blazer and Jeans
Conditionals
weather = "sunny"
if weather == "sunny":
print("Sunglasses on, GirlyPop!")
elif weather == "rainy":
print("Time for rain boots!")
else:
print("Just go with the vibe.")
Conditional statements (if
, elif
, else
) help you make decisions. Think of it as "Should I wear this today or not?" logic.
Importing Libraries
Python has built-in libraries (like your fave apps) that make life easier. For bioinformatics, you’ll probably use numpy
, pandas
, or biopython
.
import numpy as np
# Create an array (think of it as a table of data)
data = np.array([1, 2, 3, 4])
print(data) # Prints: [1 2 3 4]
File Handling
# Writing to a file
with open('outfits.txt', 'w') as file:
file.write("Dress, Jeans, Sweater")
# Reading from a file
with open('outfits.txt', 'r') as file:
print(file.read()) # Prints: Dress, Jeans, Sweater
Python can read and write files. It’s like opening a document, reading it, and writing your own notes!
Object-Oriented Programming (OOP)
Python allows you to create your own classes. Think of it as designing your own wardrobe structure, where each piece of clothing is a unique object.
class Outfit:
def __init__(self, type, color):
self.type = type
self.color = color
def describe(self):
return f"{self.color} {self.type}"
# Creating an object
my_outfit = Outfit("Dress", "Pink")
print(my_outfit.describe()) # Prints: Pink Dress
Numpy
import numpy as np
# Create a matrix (like a protein sequence matrix)
protein_matrix = np.array([[1, 0, 0], [0, 1, 1], [1, 0, 1]])
print(protein_matrix)
numpy
is a super popular library for numerical data and arrays. You'll use it for bioinformatics to handle protein sequences or perform computations.
pandas
import pandas as pd
# Create a DataFrame (like a bioinformatics dataset)
data = {'Gene': ['BRCA1', 'TP53', 'EGFR'], 'Expression': [9.5, 8.3, 7.1]}
df = pd.DataFrame(data)
print(df)
scikit-learn
is where the magic of machine learning happens! You'll use this for predictive models, like identifying drug targets.
from sklearn.linear_model import LinearRegression
# Simple linear regression
X = [[1], [2], [3]] # Input values
y = [1, 2, 3] # Output values
model = LinearRegression()
model.fit(X, y)
print(model.predict([[4]])) # Predicts: 4
Bioinformatics Tools (BioPython)
BioPython is designed for computational biology tasks like handling protein or DNA sequences.
from Bio.Seq import Seq
# Create a DNA sequence
dna_seq = Seq("AGTACACTGGT")
print(dna_seq) # Prints: AGTACACTGGT
# Transcribe DNA to RNA
print(dna_seq.transcribe()) # Prints: AGUACACUGGU