0% found this document useful (0 votes)
45 views8 pages

02-11-22-Lab-5-MS21212.ipynb - Colaboratory

The document contains code that analyzes DNA sequences. It counts the unique characters and dinucleotide combinations. It calculates the counts of each mononucleotide and dinucleotide in the sequence. Finally, it identifies the maximum occurring mononucleotide and dinucleotide.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

02-11-22-Lab-5-MS21212.ipynb - Colaboratory

The document contains code that analyzes DNA sequences. It counts the unique characters and dinucleotide combinations. It calculates the counts of each mononucleotide and dinucleotide in the sequence. Finally, it identifies the maximum occurring mononucleotide and dinucleotide.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.

ipynb - Colaboratory

print('Welcome to Introduction to Computer course')

#2) Python3 program for explaining


# use of list, tuple, set and
# dictionary

# Lists
l = [1,2,3]

# Adding Element into list


l.append(5)
l.append(10)
print("Adding 5 and 10 in list", l)

# Popping Elements from list


l.pop(0)
print("Popped one element from list", l)
print()

# Set
s = set()

# Adding element into set


s.add(5)
s.add(10)
print("Adding 5 and 10 in set", s)

# Removing element from set


s.remove(5)
print("Removing 5 from set", s)
print()

# Tuple
t = tuple(l)

# Tuples are immutable


print("Tuple", t)
print()

# Dictionary
d = {}

# Adding the key value pair


d[5] = "Five"
d[10] = "Ten"
print("Dictionary", d)

# Removing key-value pair


del d[10]
print("Dictionary", d)
https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 1/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

#3) Python program for implementation of Bubble Sort


def bubbleSort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):

# Last i elements are already in place


for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
# Driver code to test above
# creating an empty list
arr = []
# number of elements as input
n = int(input("Enter number of elements : "))
# iterating till the range
for i in range(0, n):
ele = int(input(" enter your index number "))

arr.append(ele) # adding the element

print(" your created array is " , arr)

bubbleSort(arr)

print ("Sorted array is:")


for i in range(len(arr)):
print (arr[i], end =" ")

Welcome to Introduction to Computer course


Adding 5 and 10 in list [1, 2, 3, 5, 10]
Popped one element from list [2, 3, 5, 10]

Adding 5 and 10 in set {10, 5}


Removing 5 from set {10}

Tuple (2, 3, 5, 10)

Dictionary {5: 'Five', 10: 'Ten'}


Dictionary {5: 'Five'}
Enter number of elements : 6
enter your index number 1
enter your index number 6
enter your index number 3
enter your index number 8
enter your index number 3
enter your index number 4
your created array is [1, 6, 3, 8, 3, 4]
Sorted array is:
1 3 3 4 6 8

https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 2/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

a=input("Please enter DNA bases: ")


#a='ATGAGCTGGATTGAACGAATTAAAAGCAACATTACTCCCACCCGCAAGGCGAGCATTCCTGAAGGGGTGTGGACTAAGTGTGATAG
s=set(a)
mono=list(set(a))
sp=3
print(" "*sp)
print("number of unique character" , len(s))
print("All possible mononucleotides are ",mono )
inp = list(a)
for base in list(set(inp)):
count_base = inp.count(base)
if count_base == 0:
print("Not found.")
else:
print ("Count of ", base," is: ", count_base ,";" , end=' ')
sp=3
print(" "*sp)

di = []
for char1 in s :
for char2 in s :
di.append(char1 + char2)

print("All possible dinucleotidesare ",di)


print(f'there are {len(di)} combinations.\n')

for dinucleotide in di:


count = a.count(dinucleotide)
print("count is " + str(count) + " for " + dinucleotide,';' , end=' ')

monocounts = {}
for char in mono :
count = 0
for i in a:
if char == i :
count += 1
monocounts[char] = count
print("Count of respective mononucleotides" , monocounts)
sp=3
print(" "*sp)

dicount = {}
for char in di :
if char in a :
dicount[char] = a.count(char)
print("Count of respective dinucleotide ",dicount)
sp=3
print(" "*sp)

print(f'Maximum occuring mononucleotide is: {list(monocounts.keys())[list(monocounts.value


print(f'Maximum occuring dinucleotide is: {list(dicount.keys())[list(dicount.values()).ind
https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 3/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

# the above truncated code is


"""print(f'Maximum occuring mononucleotide is: {list(monocounts.keys())
[list(monocounts.values()).index(max(monocounts.values()))]} -
{max(monocounts.values())} times')
print(f'Maximum occuring dinucleotide is: {list(dicount.keys())
[list(dicount.values()).index(max(dicount.values()))]} -
{max(dicount.values())} times')"""

Please enter DNA bases: ATGAGCTGGATTGAACGAATTAAAAGCAACATTACTCCCACCCGCAAGGCGAGCATTCCTG


number of unique character 8
All possible mononucleotides are ['g', 't', 'a', 'A', 'c', 'T', 'C', 'G'] Count of g
is: 71 ; Count of t is: 53 ; Count of a is: 34 ; Count of All possible
dinucleotidesare ['gg', 'gt', 'ga', 'gA', 'gc', 'gT', 'gC', 'gG', 'tg', there are 64
combinations.

count is 16 for gg ; count is 17 for gt ; count is 11 for ga ; count is 1 for g


Count of respective dinucleotide {'gg': 16, 'gt': 17, 'ga': 11, 'gA': 1, 'gc': 23,
Maximum occuring mononucleotide is: G - 212 times
Maximum occuring dinucleotide is: GC - 67 times

Please enter DNA bases:


ATGAGCTGGATTGAACGAATTAAAAGCAACATTACTCCCACCCGCAAGGCGAGCATTCCTGAAGGG
GTGTGGACTAAGTGTGATAGCTGCGGTCAGGTTTTATACCGCGCTGAGCTGGAACGTAATCTTGAG
GTCTGTCCGAAGTGTGACCATCACATGCGTATGACAGCGCGTAATCGCCTGCATAGCCTGTTAGATG
AAGGAAGCCTTGTGGAGCTGGGTAGCGAGCTTGAGCCGAAAGATGTGCTGAAGTTTCGTGACTCCA
AGAAGTATAAAGACCGTCTGGCATCTGCGCAGAAAGAAACCGGcgaaaaagatgcgctggtggtgatgaaag
gcactctgtatggaatgccggttgtcgctgcggcattcgagttcgcctttatgggcggttcaatggggtctgttgtgggtgcacgtttc
gtgcgtgccgttgagcaggcgctggaagataactgcccgctgatctgcttctccgcctctggtggcgcacgtatgcaggaagcact
gATGTCGCTGATGCAGATGGCGAAAACCTCTGCGGCACTGGCAAAAATGCAGGAGCGCGGCTTGCC
GTACATCTCCGTGCTGACCGACCCGACGATGGGCGGTGTTTCTGCAAGTTTCGCCATGCTGGGCGA
TCTCAACATCGCTGAACCGAAAGCGTTAATCGGCTTTGCCGGTCCGCGTGTTATCGAACAGACCGT
TCGCGAAAAACTGCCGCCTGGATTCCAGCGCAGTGAATTCCTGATCGAGAAAGGCGCGATCGACAT
GATCGTCCGTCGTCCGGAAATGCGCCTGAAACTGGCGAGCATTCTGGCGAAGTTGATGAATCTGCC
AGCGCCGAATCCTGAAGCGCCGCGTGAAGGCGTAGTGGTACCCCCGGTACCGGATCAGGAACCTG
AGGCCTGA

number of unique character 8 All possible mononucleotides are ['g', 't', 'a', 'A', 'c', 'T', 'C', 'G'] Count
of g is: 71 ; Count of t is: 53 ; Count of a is: 34 ; Count of A is: 172 ; Count of c is: 47 ; Count of T
is: 149 ; Count of C is: 177 ; Count of G is: 212 ;
All possible dinucleotidesare ['gg', 'gt', 'ga', 'gA', 'gc', 'gT', 'gC', 'gG', 'tg', 'tt', 'ta', 'tA', 'tc', 'tT', 'tC', 'tG',
'ag', 'at', 'aa', 'aA', 'ac', 'aT', 'aC', 'aG', 'Ag', 'At', 'Aa', 'AA', 'Ac', 'AT', 'AC', 'AG', 'cg', 'ct', 'ca', 'cA', 'cc', 'cT',
'cC', 'cG', 'Tg', 'Tt', 'Ta', 'TA', 'Tc', 'TT', 'TC', 'TG', 'Cg', 'Ct', 'Ca', 'CA', 'Cc', 'CT', 'CC', 'CG', 'Gg', 'Gt', 'Ga',
'GA', 'Gc', 'GT', 'GC', 'GG'] there are 64 combinations.

https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 4/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

count is 16 for gg ; count is 17 for gt ; count is 11 for ga ; count is 1 for gA ; count is 23 for gc ;
count is 0 for gT ; count is 0 for gC ; count is 0 for gG ; count is 27 for tg ; count is 9 for tt ; count
is 4 for ta ; count is 0 for tA ; count is 11 for tc ; count is 0 for tT ; count is 0 for tC ; count is 0 for
tG ; count is 8 for ag ; count is 10 for at ; count is 8 for aa ; count is 0 for aA ; count is 5 for ac ;
count is 0 for aT ; count is 0 for aC ; count is 0 for aG ; count is 0 for Ag ; count is 0 for At ; count
is 0 for Aa ; count is 43 for AA ; count is 0 for Ac ; count is 40 for AT ; count is 29 for AC ; count is
45 for AG ; count is 17 for cg ; count is 15 for ct ; count is 8 for ca ; count is 0 for cA ; count is 6
for cc ; count is 0 for cT ; count is 0 for cC ; count is 0 for cG ; count is 0 for Tg ; count is 0 for Tt ;
count is 0 for Ta ; count is 20 for TA ; count is 0 for Tc ; count is 22 for TT ; count is 37 for TC ;
count is 65 for TG ; count is 0 for Cg ; count is 0 for Ct ; count is 0 for Ca ; count is 30 for CA ;
count is 0 for Cc ; count is 40 for CT ; count is 39 for CC ; count is 63 for CG ; count is 0 for Gg ;
count is 0 for Gt ; count is 0 for Ga ; count is 63 for GA ; count is 1 for Gc ; count is 42 for GT ;
count is 67 for GC ; count is 35 for GG ; Count of respective mononucleotides {'g': 71, 't': 53, 'a':
34, 'A': 172, 'c': 47, 'T': 149, 'C': 177, 'G': 212}

Count of respective dinucleotide {'gg': 16, 'gt': 17, 'ga': 11, 'gA': 1, 'gc': 23, 'tg': 27, 'tt': 9, 'ta': 4, 'tc':
11, 'ag': 8, 'at': 10, 'aa': 8, 'ac': 5, 'AA': 43, 'AT': 40, 'AC': 29, 'AG': 45, 'cg': 17, 'ct': 15, 'ca': 8, 'cc': 6, 'TA':
20, 'TT': 22, 'TC': 37, 'TG': 65, 'CA': 30, 'CT': 40, 'CC': 39, 'CG': 63, 'GA': 63, 'Gc': 1, 'GT': 42, 'GC': 67,
'GG': 35}

Maximum occuring mononucleotide is: G - 212 times

Maximum occuring dinucleotide is: GC - 67 times


https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 5/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

#5)a) storing the data and calculating avg marks


name =[ 'adrian', 'jasuz', 'jeffrey', 'michael', 'piotr']
maths =[55,75,81,79,85]
biology =[65,64,79,59,81]
chemistry =[90,95,58,80,78]
physics =[88,96,82,65,80]

i= int(input('enter the index num: '))


a= maths [i] + biology[i] + chemistry[i] + physics[i]
avg_marks=a/4
print(f'avg_marks of {name[i]} is {avg_marks}')

#5)b) subject wise performance

sub = str(input('enter the subject for performance '))

if(sub == "maths") :
maths_total= maths [0] + maths [1] + maths [2] + maths [3] + maths [4]
performance_maths = maths_total/5
print('performane in maths', performance_maths)
elif (sub == "biology"):
biology_total= biology [0] + biology [1] + biology [2] + biology [3] + biology [4]
performance_biology = biology_total/5
print('performance in biology', performance_biology)
elif (sub == "chemistry"):
chemistry_total = chemistry [0] + chemistry[1] + chemistry[2] + chemistry[3] + chemistry
performance_chemistry = chemistry_total/5
print('performane in chemistry', performance_chemistry)
elif (sub == "physics"):
physics_total = physics [0] + physics [1] + physics [2] + physics [3] + physics [4]
performance_physics = physics_total/5
print('performance in physics', performance_physics)
#5)c) using dict
Adrian ={'Maths': 55,'Biology': 65 ,'Chemistry': 90 ,'Physics': 88 }
Jasuz ={'Maths': 75,'Biology': 64,'Chemistry': 95 ,'Physics': 96}
Jeffrey ={'Maths': 81,'Biology': 79,'Chemistry': 58,'Physics': 82}
Michal={'Maths': 79,'Biology':59,'Chemistry': 80 ,'Physics': 65}
Piotr ={'Maths': 85,'Biology': 81,'Chemistry': 78,'Physics': 80}
def average(subject):
x=( Adrian [ subject ]+ Jasuz [ subject ]+ Jeffrey [ subject ]+ Michal [ subject ]+Pio
print ( f' class average of { subject } is {x}')

average('Maths')
average('Biology')
average('Chemistry')
average ('Physics')

https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 6/7
3/1/22, 1:07 PM 02-11-22-Lab-5-MS21212.ipynb - Colaboratory

enter the index num: 2


avg_marks of jeffrey is 75.0
enter the subject for performance maths
performane in maths 75.0
class average of Maths is 75.0
class average of Biology is 69.6
class average of Chemistry is 80.2
class average of Physics is 82.2
11s completed at 1:07 PM
check

https://colab.research.google.com/drive/1r745sBGbyBEF4PXkhTK0R5kMvHBzfBel?authuser=1#scrollTo=-zv5m6MNPovJ&printMode=true 7/7

You might also like