Log in to StudySoup
Get Full Access to MSU - CSE 6613 - Class Notes - Week 7
Join StudySoup
Get Full Access to MSU - CSE 6613 - Class Notes - Week 7

Already have an account? Login here
Reset your password

MSU / Computer Science and Engineering / CSE 4613 / How to store a matrix into a program?

How to store a matrix into a program?

How to store a matrix into a program?


School: Mississippi State University
Department: Computer Science and Engineering
Course: Bio-computing
Professor: Andy perkins
Term: Fall 2016
Cost: 25
Name: week6: notes from matrix, gene expression, etc on Python
Description: All examples worked on class on how to operate with dictionary and lists and loops on Python. Detailed information and step per step on each code.
Uploaded: 09/23/2016
9 Pages 150 Views 1 Unlocks

September 19, 2016 

How to store a matrix into a program?


1) Suppose you want to store a matrix into a program. So basically you create a list of lists.  2) Ask to print a number in a specific location of a matrix. So, matrix [row] [column]

It will print 9 on the keyboard.  

3) The problem happens when you do a matrix with a bunch of zeros. It is called sparse  matrix, matrix with lots of zeros. The problem is that if you need to do many calculations  you will end up with more zeros.  

What happens when you do a matrix with a bunch of zeros?

The problem it  We also discuss several other topics like Why does sex categorization matter?

occupies memory  

because in this case it  

will store 24 numbers  

in which only 4  

matters. Because  

zeros are irrelevant.  

Matrixes are important in molecular biology because you can store a matrix with sequence  similarities, like the ones produced by Clustal Omega.

4) Trying to find a number on the matrix from your keyboard.  

Why does matrix be important in molecular biology?

So you can tell that same matrix above you have 1 in the  

positions (1,0), (4,2) and (0,4). And put these positions on a  


So, dict = {(1,0):1, (4,2):1, (0,4):1}

That means that (row:col) has 1.  

Then you can ask what number it is on:  Don't forget about the age old question of What is the meaning of blood types?

Dict = (row, col)  

However, because you did not define what numbers you have  

on other positions at first it will give you an error.  

You can use dict.get ((row,col), number) where number  Don't forget about the age old question of What does x-direction mean?

turns to be the missing number you want it to be. So it this  

case I want that the positions I didn’t insert a number become  

zero and so all other positions, using same code, if they had a  

number described before, they still have same number (1).  

Dic.get = let you treat a dictionary as a matrix.  

So number can be a number or a string. It does not matter.  If you want to learn more check out What are archaea called extremophiles?

Same thing can be done on your  

interpreter. So there, you can turn  

your matrix in a dictionary and just  

input where the numbers that are not  

zero are.  

Dictionary.get((row,col), number)  

can also be use on your interpreter.

Doing the same code, but asking to print the numbers on the same line.  

Turning your matrix in a dictionary is a good way to save memory on your computer. If you want to learn more check out What is a measurement of how much quantity demanded will change in response to a change in the price of a product?


*** When you have a list you can use codes to work on the  

list of comprehension. For example, imagine you have a list  

and you want to multiply all your numbers from your list by  


You can do the same thing using a loop, “for num in a:  

num*2…”  Don't forget about the age old question of What is the meaning of recombinant dna?

If you want a list of that, you just append the number.

If you do a*2 instead of a[index]*2, instead of multipliying each number from a, it will make 2  copies of a. .................................………………………………………………………

Back to your matrix…  

Build a matrix.  

When you write matrix = [0*5], it means that you have a matrix with 5 zeros in one line. When you write matrix = [[0*5]*5], it means you have a matrix with 5 zeros in 5 lines.  


Imagine you have a matrix where each line represents a single gene and each column gives you  expression of different samples from that same gene. You input file will look like this:  

So, first same steps as always:

Imagine you can take the average of these numbers and print it in a dictionary

**Dictionary can be treated as lists, with same  

commands. For example, if you have 2 dictionaries  

and one is equal to the other one and you change one,  

because both have same ID, the other one will change  


So if you want to change one without affect the other  

you need to save copy.

September 21, 2016 

**Observations about assignment 4 – working on lists.  

When you create lots of sequences, you cannot relate the lists opening each one. For example: Names= [‘a’, ‘b’ , ‘c’]

Ids = [40, 60, 80]


For index in range (0, len(names))

Print (names[index] + ids[index])

Don’t do it:  

For name in names OR for id in ids: because it has no way to relate both lists as they were associated to each  other.  


1) Imagine you want to create a dictionary where you will store gene names and sequences that must be  inserted from the keyboard.

In this dictionary of tuples, key will be the gene name and the value the sequence.  

Make sure the no repeated gene name or sequence occurs.


1) Fasta have a particular way to save the gene sequences, in which the same sequence is break into  multiple lines you it can make it easier to the user see a long sequence. For example:  

2) Imagine you want to compute the GC content for each sequence.  

a. Open to read your fasta file (fasta extension).  

b. Read one line one at the time

c. Print only the gene names. This is important to know how many genes you have and who are they. d. If you want to count the number of genes you could do just “count+=1”

e. Printing the entire sequence with the gene name:  

In the bad way:

Another way:  

The best way, by using dictionary:

Remember, the order of your genes will always change.  

f. Printing the GC content

g. Printing the GC content in an out file:

h. Printing your dictionary keys in order.  

Need to turn it into a list first!

Thinks that might be on the test:  

1) Suppose a dictionary exists that contains GC content for many different genes, with gene name  for the key. Print the GC content for the gene1.  

Note the dictionary was already made. The content was already calculated. Give just the code  to print! Only the print code.  


Print (gcdict[‘gene1’])  

2) Suppose everything from the first question was already done, replace the value of Gene 1 to  0.5.


gcdict[‘Gene1’] = 0.5

3) Given the genes bellow that were in the worked dictionary from the first question, give me all  genes with a GC content of 0.5.

Gene1 0.5

Gene2 0.1

Gene3 0.3

Gene4 0.5

Gene5 0.1

Gene6 0.7


For k, v in gcdict.items( ):

If v==0.5:


4) From the question above. If a code is given to print the genes with GC content of 0.1, how the  keyboard would print it?  

(gene2, gene5)

5) What about GC content of 0.7?

(gene6, )  

***don’t forget the comma!!!

Page Expired
It looks like your free minutes have expired! Lucky for you we have all the content you need, just sign up here