CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python...

72
CSE 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois, Chicago August 31, 2017 Theresa McCracken @McHumor.com

Transcript of CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python...

Page 1: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

CSE111Bio:ProgramDesignILecture2:PythonBasics&

IntrotoBioRobertSloan(CS)&RachelPoretsky(Bio)

UniversityofIllinois,ChicagoAugust31,2017

[email protected]

Page 2: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

ACTIVELEARNING&CLICKERS

Page 3: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

3

Didyou registeryourclicker?

Page 4: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Lecture:PartiallyPeerInstruction

• Posecarefullydesignedquestion– Solovote:Thinkforyourselfandselectanswer– Discuss:Analyzeprobleminsmallteams

• Practiceanalyzing,talkingaboutchallengingconcepts• Reachconsensus• Ifyouhavequestions,raiseyourhandandwewillcomeover

– Classwidediscussion:• LedbyYOU(students)– telluswhatyoutalkedaboutinyourdiscussionsthatyouthinkeveryoneshouldknow!

Page 5: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

WhyPeerInstruction?

• Yougettomakesureyouarefollowingthelecture.

• Igetfeedbackastowhatyouunderstand.

• It’slessboring!

• Researchshowsitpromotesmorelearningthanstandardlecture.

Page 6: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

DiscussionGroups

• Threepeopleeach• Adhocforfirstfewclassesuntilenrollmentsettles

• Mayassigngroupsfor5th or6th class onward

Page 7: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

DiscussionEtiquette

• It’sokaytonotknowthings– Ifyoualreadyknoweverything,you’rewastingyourtime

• It’snotacompetition

Page 8: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Example:Thebestdinosauris:

A.T-rex B.Raptor

C.TriceratopsD.Stegosaurus

E.Someotherdinosaur/Noclue

Page 9: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

DoingTheReadingMeans

• Youdothe“easy”partbeforeclass.– ReaditandanalyzeforYOURSELF!– IfIrephraseitforyou,whatpurposedoesthatserve?

• Traditionalclassstructuresoftenlooklike:

• Yougetverylittleopportunityfor“expert”feedback

FirstExposure

Lecture Textbook

ReadHardStuff

Assignment

SeeifYouKnowHardStuff

Exam

ShowKnowledgeMastery

Page 10: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

ActiveLearning

• Greateropportunityforexpert feedback!• Researchonhowpeoplelearn:

– Everyoneconstructstheirownunderstanding• Ican’tdumpunderstandingintoyourbrain

– Tolearn,YOUmustactivelyworkwithaproblemandconstructyourownunderstandingofit

Textbook Lecture Assignment Exam

ShowKnowledgeMastery

FirstExposure:Withresourcesand

Feedback

LearnHardStuff:Withteacherand

discussion

PracticeKnowledgeMastery

Page 11: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

DoesthismeanIhavetoshowuptoclass?

• Yes

• Willnotpenalizeanybodymissingduringfirstfewclassesandwilldropyourlowest3classparticipationscores

Page 12: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Registeryourclickeronlinesowecangiveyoupoints

• InBlackboard,onthesideofthecoursepage

• Yourvoteswillbesavedbeforeyouregister,justnotassociatedwithyou

Page 13: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

ABITMORERESYLLABUSETC.

Page 14: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Grading

SubjecttochangeatanytimeforanyreasonLabprogrammingassignments(lowest3dropped) 20%Labquizzes(lowest 2dropped) 5%

Programmingprojects 25%

Twomidterms,10%each 20%

FinalExam 20%

Lectureparticipation(clicker) 10%

Zybook reading/completion beforestartofclass 5%

Inaddition,topassCS111, onemustpassboththeprogrammingpartofthecourse(labsplusprogrammingprojects)andtheexampartofthecourse(midtermsplusfinal).

Page 15: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

WeeklyLabQuizzes

• Quick(2–5question)reviewofwhatwe’vebeencoveringinclass

• Youmustbeinlabtodothelabquiz

• OnBlackboard,solutionswillbeavailableonthedayfollowinglab

Page 16: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

ProgrammingAssignments

• Longerassignmentsthatgiveyouthechancetoputtogetherwhatwehavelearnedinacreativeway

• Giveyoupracticecreatingalongerprogram

Page 17: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

ProgrammingProjectLatePolicy• Youhavetwolatedaysthatwillbeautomaticallyappliedifyourlabislate.Noworkwillbeacceptedmorethan2dayslate.

• Tousealateday,youmustfilloutthelatedaysformonblackboardbeforetheassignmentisdue

• Thesooneryouturninthework,thesoonerwecangradeitandgetitbacktoyou

Page 18: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

CollaborationPolicy• Pleasedo

– Postontheforum– Talkwithclassmatesaboutassignments

• Pleasedon’t– Copysomeone’scode– Showsomeoneelseyourcode

• Goodruleofthumb:Waithalfanhourafterdiscussing,writecode/doproblem

Page 19: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Questions?

• Allofthisinfoandgradingpolicy,etc.,etc.,oncoursewebsite

Page 20: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

HowtoAceThisClass

• Dothereading• Attendclassandparticipateindiscussion• Startprogrammingprojectsearly• Gotolabsectionandaskquestions• Ifyougetstuck,postonpiazzaorcometoofficehours

• Havefun!

Page 21: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

HowdoIbecomeagreatcomputerscientist?

• Writealotofcode!

21

Page 22: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

SOMEBIOLOGY

Page 23: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure1.7,1.8

Page 24: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure1.10,1.11

Page 25: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,
Page 26: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

2626

RelevantTheories:Genes

• In1866Gregor Mendelpublishedhisexperimentsonpeaplants,demonstratingthatdiscretetraitsaretransmittedovergenerationsinapredictablemanner.(Section8.1,CoB)

• T.H.Morganin1915establisheschromosomesascarriersofheredity.(Section8.3,CoB)

• Theoryofheredity:traitsareaffectedbygenes,transmittedbetweengenerationsinapredictablemanner.

Page 27: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

RelevantTheories:Genes

Page 28: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Whatisachromosomemadeof?

Page 29: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.7

Page 30: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

GeneticElements• Gene: Functionalunitofgeneticinformation;genesareincellsandarecomposedofDNA

• Genome:entirecomplementofgenesincellorvirus

• Chromosome:maingeneticelement.Presenceofessentialgenesisnecessaryforageneticelementtobecalledachromosome

Page 31: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.6

• Aeukaryotecontainsawell-definednucleus,whereasinprokaryotes,thechromosome liesinthecytoplasminanareacalledthenucleoid.

Page 32: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

32

http://blogs.nature.com/freeassociation/tag/watson-and-crick

Copyright(c)HenryGrantArchive/MuseumofLondon

https://profiles.nlm.nih.gov/KR/

Page 33: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.3

• (a)EachDNAnucleotideismadeupofasugar,aphosphategroup,andabase.• (b)Cytosineandthyminearepyrimidines.Guanineandadeninearepurines.

Page 34: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

• Purines– adenine (A)– guanine (G)

• Pyrimidines– thymine (T)– cytosine (C)

• Pairing– A : T

• 2 bonds– C : G

• 3 bonds

DNA Pairing Rules

Page 35: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.4

• DNA(a)formsadoublestrandedhelix,and(b)adeninepairswiththymineandcytosinepairswithguanine.(credita:modificationofworkbyJeromeWalker,DennisMyts)

Page 36: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Whatisthis3¢ or5¢ stuff?

• theleadingcarbonattachestoaphosphate-P (5’)

• thelasttrailingcarbonisattachedtohydroxyl–OH(3’)

• base=A,C,G,T

DNAStructure

OH

O

PO4

base

CH2O

base

OPO

C

O–O

CH2

Page 37: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.5

• ThedifferencebetweentheribosefoundinRNAandthedeoxyribose foundinDNAisthatribosehasahydroxylgroupatthe2'carbon.

DNAandRNAStructure:Polymersofsugar,phosphate,andbase

Page 38: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

DNAisdoublestranded

38http://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/DNA_chemical_structure.svg/450px-DNA_chemical_structure.svg.png

Page 39: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Figure9.8

• ThetwostrandsofDNAarecomplementary,meaningthesequenceofbasesinonestrandcanbeusedtocreatethecorrectsequenceofbasesintheotherstrand.

• NucleotidesinDNAbackbonearebondedfromphosphatetosugarbetween3¢ &5¢ carbons

– DNAmoleculehas“direction”– complementarystrandrunsin

oppositedirection

AntiparallelStrands

Page 40: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

TheDoubleHelix

Onehelicalturn

(10basepairs)

Minorgroove

Majorgroove

Sugar–phosphatebackbone

3.4nm

Page 41: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

TheDoubleHelix

• SizeofDNAmoleculeisexpressedinbasepairs

• 1,000basepairs=1kilobasepair=1kbp• 1millionbasepairs=1megabasepair=1Mbp• E.coli genome=4.64Mbp• Eachbasepairtakesup0.34nmoflengthalongthehelix

• 10basepairsmakeup1turnofthehelix

Page 42: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

GenomeSizes

• Carsonella ruddii,160,000basepairs(bp)• porcine(pig)circovirus 1.7Kbp,ssDNA• cowpeamosaicvirus,9.4Kbp,ssRNA• phi29(Bacillus phage)19Kbp,dsDNA• humans?

Page 43: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

GenomeSizes

• Carsonella ruddii,160,000basepairs(bp)• porcine(pig)circovirus 1.7Kbp,ssDNA• cowpeamosaicvirus,9.4Kbp,ssRNA• phi29(Bacillus phage)19Kbp,dsDNA• humans?• Largestgenome:

(A)Human,(B)Fish,(C)Amoeba,(D)Floweringplant,(E)Don’tknow

Page 44: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

GenomeSizes

• Carsonella ruddii,160,000basepairs(bp)• porcine(pig)circovirus 1.7Kbp,ssDNA• cowpeamosaicvirus,9.4Kbp,ssRNA• phi29(Bacillus phage)19Kbp,dsDNA• Protopterus aethiopicus,130Gbp• Parisjaponica,150Gbp• Amoebadubia,

670Gbp

Page 45: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,
Page 46: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

SohowdowerepresentDNAonacomputer?

46

Page 47: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,
Page 48: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

PROGRAMS,PROCESSES,ALGORITHMS

Page 49: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Whichiscorrect?

A. Acomputerprogramistypicallyamoredetailedfleshingoutofthegeneralspecificationofanalgorithm

B. Analgorithmistypicallyamoredetailedfleshingoutofthegeneralspecificationofacomputerprogram

C. Computerprograms&algorithmsaretypicallystatedwiththesamelevelofdetail

Page 50: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Algorithm

• Analgorithm isamethodicalstep-by-stepproceduretoperformatask.– Typicallystatedinnaturallanguage(e.g.,English)thoughoftensomemathorprogramminglanguage-ish ismixedin

• Designofgoodprogramsofmoderatecomplexity(notWeek1ofCS111)startswithdescriptionofalgorithm;movesto(somewhatmoredetailed&precise)program

50

Page 51: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Programmingisacommunicationsandanalysisskill

• Ifyouwanttounderstandwhatyourtools(e.g.,Excel)canorcannotdo,youneedtounderstandwhattheprogramsaredoing

• Ifyouwanttosaysomethingthatyourtoolsdon’tallow,programityourself

• Ifyoucareaboutanalyzingdata…thenit’sworthyourwhiletounderstandhowtodoitatscale!

• KnowledgeisPower,Knowinghowprogramsworkispowerfulandfreeing

Page 52: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Asidetonon-CS-Majors:Process

• AlanPerlis– Oneofthefoundersofcomputerscience– Arguedin1961 thatComputerScienceshouldbepartofaliberaleducation:Everyone shouldlearntoprogram.

• Perhapscomputingismore criticaltoaliberaleducationthanCalculus

• Calculusisaboutrates,andthat’simportanttomany.• Computerscienceisaboutprocess,andthat’simportanttoeveryone.

Page 53: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Thus:ProgrammingisaboutCommunicatingProcess

• Aprogramisthemostconcisestatementpossibletocommunicateaprocess– That’swhyit’simportantthosewhowanttospecifyhow todosomethingunderstandablyinasfewwordsaspossible

– Andonereasonwhyweshouldstrivetomakeourprogramseasyforhumans toread

Page 54: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

COMPUTERS,DATA,SIZES

Page 55: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Whatcomputersunderstand• 0’sand1’s.

– Everything is0’sand1’s

• Computersareexceedingly stupid– Theonlydata theyunderstandis0’sand1’s– Theycanonlydothemostsimplethingswiththose0’sand1’s

• Movethisvaluehere• Add,multiply,subtract,dividethesevalues• Comparethesevalues,andifoneislessthantheother,gofollowthisstepratherthanthatone.

Page 56: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

KeyConcept:Encodings• Butwecaninterpret these

numbersanywaywewant.– Wecanencode informationinthosenumbers

• Eventhenotionthatthecomputerunderstandsnumbersisaninterpretation– Weencodethevoltagesonwiresas0’sand1’s

– Whichwecan,inturn,interpretasadecimalnumber

Page 57: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Usefulterminology

• 8bitbyteisfundamentalunitofmemory• 1byteisreallytinyunit.Moreoftensee:

– N.B.210,220,230,240,insteadofpowersof10(e.g.,1024bytekB)alsoused!See,e.g.,https://support.apple.com/en-us/HT201402

1kilobyte 1kB 103 bytes 1000bytes

1megabyte 1MB 106 bytes 1,000,000 bytes

1gigabyte 1GB 109 bytes 1billionbytes

1terabyte 1TB 1012 bytes 1trillionbytes

Page 58: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Unitstodataamounts• 1GBcanholdabout

– 250photos(Basedon12Megapixelcamera,e.g.,recentiPhone,andJPEG100%quality)

– 7–30minutesofvideo(dependingonquality,framespersecond,and720–1080p)

– 40,000pagesofsimpleWorddocs– 1/3ofthecompletegenomeofonehuman

• So1TBharddrivecanhold200hoursofvideoand10,000photoswithroomleftover(assumingvideoishigh-quality720p@30fps)or300people’scompleteDNA

Page 59: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

UnitstoFall2017$@amazon

• SeagateExpansion1TBPortableExternalHardDriveUSB3.0(STEA1000400)

• by Seagate• $ 54 99 Prime|FREEOne-Day

• (Pricesnowstable;costaboutthesameayearago;betyoucouldfinditfor$50ifyoushoppedaround)

Page 60: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Whatisacomputer?

• Adevicethatexecutesastoredprogram(sequenceofinstructions).

• Aprogramisaparticularwritingofarecipeinsomeparticularlanguage.(RecipeislikelytobeinEnglish orFrenchorArabicorHindi;programinaprogramminglanguage suchasC,Java,VisualBasic,orPython)

Page 61: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Allcomputersconsistof3components

• Memory–storesprogramanddata(information)– Primary:RAM(RandomAccessMemory)“memory”– Secondary:harddrive“storage”

• CentralProcessingUnit(CPU)– Control–fetchnextinstruction,decode it,executeit– ArithmeticLogicUnit–performsimple operationsondata(add,comparetwoforequality,etc.)

• Input/Output

Page 62: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Detour:Specsforacomputer

• Adsforcomputerstypicallygive:– SpeedoftheCPU(inGHz,say1.0-3.25)– AmountofRAMinGB– SizeofharddriveinGBorTB– Which“nice”I/Odevices(e.g.,retinadisplay)

• Interestingly,perceived speedtodayoftendependsheavilyonamountofRAM

Page 63: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Moore’sLaw

• GordonMoore,oneofthefoundersofIntel,madetheclaimthat(essentially)computerpowerdoublesforthesamedollarevery18months.

• Thishasheldtrueforover30years.– (Note:somethinktheendisfinallynear.)

• Goahead!Makeyourcomputerdothesamethingtoall2.9billionbasepairsofyourDNA!Itdoesn’tcare!Anditwon’ttakemuchtimeeither!

Page 64: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Solet’sstart!

64

Page 65: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

PYTHONBASICS

Page 66: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

RememberPythonfromlasttime

• We’lluseitforourfirst~1.5monthmission:• LearntowritefunctionsusedtoanalyzeDNA,thestuffuponwhichalllifeonearthisbuilt,andinparticulartosearchthroughahugesequenceofletterstofindabiologicallymeaningfulgene

Page 67: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

AfewwordsaboutwhyPython• Popular,widelyused(therearejobs!)

– Top5foroverallgeneraluse– #1or#2fordatascience/dataanalytics(withR)

• Easy(forhumans!)toread;easytowrite;easytolearn

• Candorealisticexamplesveryearlyon• Outstandingforexploratory,experimental,“getananswer”programming

• Twicethefunforhalftheannoyingsyntax!• It’swidelyusedinbiologyandscientificcomputing

Page 68: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Why?(cont.)

68

Afterall,therearethousandsoflanguagestochoosefrom!

•Relatively“nice”syntax•Emergingaslanguageofchoiceinmanyfields•Packagesforgraphics,audio,scientificcomputing,…

Python: print("HelloWorld!")

Java: classHelloWorld {staticpublicvoidmain(Stringargs[]){

System.out.println("HelloWorld!");}

}

Befunge:

Image:UniversityofFlorida

Page 69: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

HelloWorld…

69

C++: #include<iostream.h>main(){

cout <<"HelloWorld!"<<endl;return0;

}

Ook:

Page 70: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Python:Richersyntaxallowsgreaterexpressiveness!

70

def alifeSim(numGens,popSize,numToSelect,Network,inhibitorL):"""DoanartificiallifesimulationfornumGens generationswithpopSize organisms.""”

fitD={}#getinitialpopandcreatepopL of(fitness,org)tuplespopL=[]fororgincreateInitialPop(popSize,Network,inhibitorL):

fitness=org.getFitness()popL.append((fitness,org))fitD[hash(org)]=fitness

topL =getTopOrgs(popL,numToSelect)#gettoporgsfori inrange(numGens):

popL=[]forjinrange(popSize):

toReplicate=random.choice(topL)neworg =toReplicate[1].replicate()#getfitness

ifhash(neworg)infitD:fitness=fitD[hash(neworg)]

else:fitness=neworg.getFitness()fitD[hash(neworg)]=fitness

popL.append((fitness,neworg))topL =getTopOrgs(popL,numToSelect)print"gen:",i,":",topL[0]ifi%50==0:

fitD.clear()returntopL[0]

Learningtoprogramisabitlikelearninga

foreignlanguage!

Page 71: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

Spyder forPython

Page 72: CSE 111 Bio: Program Design I Lecture 2: Python … 111 Bio: Program Design I Lecture 2: Python Basics & Intro to Bio Robert Sloan (CS) & Rachel Poretsky(Bio) University of Illinois,

SpeakingofPython

• LabAssignment1duetonight,Thursdaybymidnight

72