genome sciences 373 genome informatics · variable’s type python inputs.py1.1 2 import sys print...

32
Genome Sciences 373 Genome Informatics Quiz Section #2 April 5, 2016

Upload: others

Post on 18-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

GenomeSciences373GenomeInformatics

QuizSection#2April5,2016

Page 2: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Today• Localalignmentreview

• Debuggingstrategies

• Python:datatypesreview,input/output,if/else,forloops

Reminder:OfficehoursMondays4:30-5:30,Foege S-040

Page 3: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Additionalbackgroundquestion:statsandprobabilitybackground?

• Canyoudefineap-valuerightnow?

• Canyoudefinenullandalternativehypothesesrightnow?

• Areyoufamiliarwiththemultiplehypothesistestingproblem?

Page 4: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Scoreofamatch(ormismatch)

Addingagaptooneofthesequences

Page 5: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Localalignmentexample

G A G T A

0 ?

A

G

T

T

A

Lineargappenaltyd=-4

Page 6: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Localalignmentexample

G A G T A

0 0 0 0 0 0

A 0 ?

G 0

T 0

T 0

A 0

Lineargappenaltyd=-4

Page 7: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Localalignmentexample

G A G T A

0 0 0 0 0 0

A 0 0

G 0 ?

T 0

T 0

A 0

Lineargappenaltyd=-4

Page 8: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Localalignmentexample

G A G T A

0 0 0 0 0 0

A 0 0

G 0 10

T 0 6

T 0 2

A 0 ?

Lineargappenaltyd=-4

Page 9: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

G A G T A

0 0 0 0 0 0

A 0 0 10 6 2 10

G 0 10 6 20 16 12

T 0 6 6 16 30 26

T 0 2 2 12 26 25

A 0 0 12 8 22 36

Maximumscore

Localalignmentexample

Page 10: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

G A G T A

0 0 0 0 0 0

A 0 0 10 6 2 10

G 0 10 6 20 16 12

T 0 6 6 16 30 26

T 0 2 2 12 26 25

A 0 0 12 8 22 36

Localalignmentexample

GAGT-AAGTTA

Page 11: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Whenlocalandglobalalignmentsdiffer

Wewanttoaligntwosequences:AGTTAAGAGTATTA

Suboptimalglobalalignmentwith6gaps:-24

AGAGTATTAAGTTA

AGTTA

OptimalLocalAlignment:-4AGAGTATTA

Optimalglobalalignment4gaps:-16AGAGTATTA

TTAAG

Somanydeletions/insertionsmightbeimplausible

Page 12: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Reminder:thealignmentparametersareamodelofmutationalprocesses

• Whatkindsofmutations?

• Howdoweknowwhethertotrustthemutationsdescribedbyanalignment?

AGTTAAGAGTATTA

Page 13: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Debuggingyourcode

Page 14: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Bigpicturetipstokeepinmind

• Startsmall!Workinpieces!

• Regularprintstatementstocheckyourprogress

• Readerrormessages…

• Usetoyexamplestocheckyourwork

• Bepatient!

• Whentheabovefails,Google/StackOverflowmay behelpful...

Page 15: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Pythonerrortypes• ParseError =Syntaxerrors- lookforformattingproblems

• TypeError,ValueError =checkyourdatatypes

• NameError =checkyourvariablenames

• IndexError =checkyourlistindices

Page 16: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Debuggingworkflows

• Theclassic:texteditor+terminal

• RunchunksinaJupyter notebook

• IDEs:PyCharm,Spyder

Page 17: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Here’sabrokenprogram• Copyandpasteit,saveasstartCodon.py• What’sitdoing?

x = 'atggataccagg 'print "x is", x

start_codon = 'atg 'if start_codon = x[0:3]:

print 'Yes! 'else:

print 'No! '

Page 18: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Here’sabrokenprogram

x = 'atggataccagg 'print "x is", x

start_codon = 'atg 'if start_codon == x[0:3]:

print 'Yes! 'else:

print 'No! '

Page 19: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

There’sanotherproblem!x = 'atggataccagg 'print xprint "first 3 characters in x are", x[0:3]

start_codon = 'atg 'print "start_codon is ", start_codon

if start_codon = x[0:3]:print 'Yes! '

else:print 'No! '

Page 20: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

There’sanotherproblem!x = 'atggataccagg 'print xprint "first 3 characters in x are", x[0:3]

start_codon = 'atg 'print "start_codon is ", start_codon

if start_codon == x[0:3]:print 'Yes! '

else:print 'No! '

Page 21: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Let’slearnmorePython!

Programmingtime!

Page 22: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Takinginputfromtheterminalcommandline

pythoninputs.py applebanana

# This is inputs.pyimport sysprint sys.argvprint sys.argv[1]

[‘inputs.py’,‘apple’, ‘banana’]‘apple’

sys.argvcommandlinetext

Page 23: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

sys.argv onlycontainsstrings,sotogetnumbers,youneedtochangethevariable’stypepythoninputs.py 1.12

import sysprint sys.argvprint sys.argv[1]print type(sys.argv[1])print float(sys.argv[1])print int(sys.argv[2])print int(sys.argv[1])

[‘myscript.py’,‘1.0’, ‘2’]

Page 24: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

sys.argv onlycontainsstrings,sotogetnumbers,youneedtochangethevariable’stypepythoninputs.py 1.12

import sysprint sys.argvprint sys.argv[1]print type(sys.argv[1])print float(sys.argv[1])print int(sys.argv[2])print int(float(sys.argv[1]))

[‘myscript.py’,‘1.0’, ‘2’]

Page 25: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Onemoreexample

pythonminus.py3.31.1

import sysprint sys.argvprint sys.argv[1] – sys.argv[2]

[‘minus.py’,‘3.3’, ‘1.1’]TypeError: unsupported operand type(s) for -: 'str' and 'str'

Page 26: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Onemoreexample

pythonminus.py3.31.1

import sysprint sys.argvprint float(sys.argv[1])–float(sys.argv[2])

[‘minus.py’,‘3.3’, ‘1.1’]2.2

Page 27: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Review: If/else statementsx = 4

if x == 5:print 'x is 5!'

elif x == 6:print 'x is 6!'

else:print 'x is neither 5 nor

6!'

Page 28: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Review: If/else statements

x = 5y = 7

if x == 5:print 'x is 5!'if y == 7:

print 'x is 5 and y is 7!'else:

print 'x is 5 and y is not 7!'else:

print 'x is not 5!'

Note:Indentsareimportant!!

Page 29: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Review: If/else statements

x = 5y = 7

if x == 5:print 'x is 5!'if y == 7:

print 'x is 5 and y is 7!'else:

print 'x is 5 and y is not 7!'else:

print 'x is not 5!'

Ablock

Ablockinsideablock(nested)

Note:Indentsareimportant!!

Page 30: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Example

x = [ 1, 3, 2]

Fromalistxcontaining3numbers,printthenumberwiththesmallestvalue

smallest_value = x[0]

print smallest_value

Page 31: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print

Example

x = [ 1, 3, 2]

Fromalistxcontaining3numbers,printthenumberwiththesmallestvalue

smallest_value = x[0]if x[1] < smallest_value:

smallest_value = x[1]if x[2] < smallest_value:

smallest_value = x[2]print smallest_value

Page 32: Genome Sciences 373 Genome Informatics · variable’s type python inputs.py1.1 2 import sys print sys.argv print sys.argv[1] print type(sys.argv[1]) print float(sys.argv[1]) print