100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Python Command Summary - Bio Informatics (B-KUL-U09B1B)

Rating
-
Sold
-
Pages
5
Uploaded on
10-02-2025
Written in
2023/2024

This is a summary of all the commands used on Python, together in one document. Command and what it does is clearly written. It also includes examples of how to use a particular command.

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
February 10, 2025
Number of pages
5
Written in
2023/2024
Type
Summary

Subjects

Content preview

Commando’s python
1. Go to jupyter notebook  log in
a. String = sequence of characters
b. Error: SyntaxError (eg. No “”) & NameError (eg. prin > print)

Print(‘x’) Printing a message to the screen
Print(“x”) x = argument
Print(“he said, ‘x’”)
Print(‘he said, “x”’) The function print() can take either a string or
a number (integer) as argument
#comments A comment will be ingored by the computer
\n New line
\t Tab
my_dna = “ATGC” Assigning a string (“ATGC”) to a variable
(my_dna) = Giving a name to something
print(my_dna) Output: ATGC
print(“my_dna”) Output: my_dna
Variable name are arbitrary Rules:
- Only letters, numbers and underscore
- Can not start with a number
- Con not use a word that is built in to
the Python language, eg. print
- Case sensitive
+ Concatenating string
My_dna = “AATT” + “GGCC”
Print (My_dna) Output: AATTGGCC
Upstream = “AAAA”
My_dna = upstream + “ATGC”
Print(My_dna) Output: AAAAATGC
The result of concatenating strings is itself a
string
len(“x”) Length of a sequence

dna_length = len(“AGTC”) (of
len(“varable”) Output: 4
print(dna_length) The return value of len() is a number (an
integer)
You can not use strings & integers mixed up in the same command: functions str() and
int()
str() String (argument)

Vb. print(“AT content is “ + Output: AT content is 4
str(at_content))
 at_content is a number Integer to string: when you need to
concatenate or format numbers as part of a
string
int() Integer (number)

Vb. int(‘4’) Int(expression) als expression een getal is

Vb. number = 3 + int(dna_length)
Print(number) Output: 9 (if dna_length = len(“AATCGA’) = 6)

, String to integer: when you receive numerical
input as a string and need to perform
numerical operations
Only usable with variables that are strings – methods that belong to the string type
x.lower() Lowercase
print(my_dna.lower()) Doesn’t change the variable, they
return an copy
x.upper() Uppercase
print(my_dna.upper()) Doesn’t change the variable, they
return an copy
x.replace(“x”,”y”) Replacing x by y

print(protein.replace(“v”,”y”) It returns a copy of the variable where
all occurrences of the first string are
replaced by the second string
Extracting part of a string (taking a substring)
x[1:6] Number 1 until 5 (incl. 1, excl. 6)
- Position starts at zero
- Inclusive start
- Exclusive stop
x[0:] From begin to end
Counting substring
x.count(‘y’) In take 1 argument (the substring), it returns
the number of occurrences of the substring in
the string
Vb. my_dna.count(‘X’) We will count how many times X is in the
variable ‘my_dna’
x.find(‘y’) Finding substrings
It takes 1 argument (the substring), it returns
the position of the first occurrence of the
substring in the string
vb. protein.find(‘p’) We will find the position where ‘p’ stands the
first time in the variable ‘protein’
- Of the output is -1: ‘p’ is not in protein
- The positions start counting at zero
Order of count() and find()
My_dna.count(“A”) ≠ A.count(my_dna)

Working with files
open(“x.txt”) Opening a file
- Argument = string
Vb. data_file = open(“data_2024.csv”)
NOT: my_file_name = “dna.txt”
My_contancts = #fout: read() werkt niet op strings
my_file_name.read()

NOT: print(data_file) #fout: print het bestandobject, niet de inhoud
x.read() Read the contents of the file
- x = file objects (not name of variable)
dna_file = open(“dna.txt”)
my_dna = dna_file.read()
x.rstrip(“y”) To remove a character
- my_file_contents = my_file.read()
my_dna = my_file_contents.rstrip(“\n”)
$8.71
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
margauxvanw

Get to know the seller

Seller avatar
margauxvanw Katholieke Universiteit Leuven
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
9 months
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions