Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 4 Karsten Hokamp, PhD Genetics TCD, 01/12/2015.

Slides:



Advertisements
Similar presentations
Course A201: Introduction to Programming 10/28/2010.
Advertisements

Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Sequences A sequence is a list of elements Lists and tuples
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
 1 String and Data Processing. Sequential Processing Processing each element in a sequence for e in [1,2,3,4]: print e for c in “hello”: print c for.
Python programs How can I run a program? Input and output.
Lists in Python.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
MCB 5472 Assignment #6: HMMER and using perl to perform repetitive tasks February 26, 2014.
Computer Programming for Biologists Class 8 Nov 28 th, 2014 Karsten Hokamp
Chapter 7 Lists and Tuples. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Data Structures.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Working on exercises (a few notes first). Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.
Built-in Data Structures in Python An Introduction.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
10. Python - Lists The list is a most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
1 CSC 221: Introduction to Programming Fall 2011 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
CS105 STRING LIST TUPLE DICTIONARY. Characteristics of Sequence What is sequence data type? It stores several objects Each object has an order Each object.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
GE3M25: Computer Programming for Biologists Python, Class 5
1 CSC 221: Introduction to Programming Fall 2012 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 10 Lists 1.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
SEQUENCES:STRINGS,LISTS AND TUPLES. SEQUENCES Are items that are ordered sequentially and accessible via index offsets into its set of elements. Examples:
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Python Programing: An Introduction to Computer Science
Computer Science 101 Python Lists. Literals, Assignment, Comparisons, Concatenation Similar to the behavior of strings so far a = [1, 2, 3] b = range(1,
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Python Files and Lists. Files  Chapter 9 actually introduces you to opening up files for reading  Chapter 14 has more on file I/O  Python can read.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
String and Lists Dr. José M. Reyes Álamo.
Java for Beginners Level 6 University Greenwich Computing At School
Containers and Lists CIS 40 – Introduction to Programming in Python
Chapter 10 Lists.
GE3M25: Data Analysis, Class 4
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python I/O.
Introduction to Python
Bryan Burlingame Halloween 2018
Chapter 10 Lists.
8 – Lists and tuples John R. Woodward.
Data Structures – 1D Lists
MongoDB Aggregations.
Microsoft Excel 101.
String and Lists Dr. José M. Reyes Álamo.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Sequences Introduction to Lists List Slicing
Python Lists.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CISC101 Reminders Assignment 2 due today.
CHAPTER 4: Lists, Tuples and Dictionaries
Bryan Burlingame Halloween 2018
Topics Sequences Introduction to Lists List Slicing
Python Lists.
Python Lists.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python List.
Introduction to Computer Science
Presentation transcript:

Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 4 Karsten Hokamp, PhD Genetics TCD, 01/12/2015

Trinity College Dublin, The University of Dublin Overview List, tuple, set Exercises Weekly task

Trinity College Dublin, The University of Dublin Recap Branching if … : elsif : else : Comparisons x > 1 File I/O

Trinity College Dublin, The University of Dublin Recap Calculate sequence lengths from a file with Fasta-formatted DNA entries Input: fasta_seqs.txt on website Output as ID and length: chrI chrII chrIII chrIV chrIX

Trinity College Dublin, The University of Dublin Recap >chrI actcaactcatcacctcatcatcaactcatc tgtgcggcgtaatacgatatagcactacgac … tgaagagccccacgactcagc >chrII tgggtagataatagagtatatatagtatata … ttagagccagtagtacgcagaccataca >chrMito ttagaatgcctaggccatcagcgcacatcat … gagatagga

Trinity College Dublin, The University of Dublin Lists: Ordered collection of variables bases = list(seq) Indexed just like strings bases[0] == seq[0] Explicit creation: columns = [1, 9, 10, 12] nucleotides = [ 'a', 'c', 'g', 't' ]

Trinity College Dublin, The University of Dublin Lists vs strings:

Trinity College Dublin, The University of Dublin Exercise: 1.Create an empty list called 'dna1' 2.What happens if you try to access dna1[0] ? 3.Create a variable 'seq' containing a DNA string 4.Create a list 'dna2' from the DNA string 5.Print the first element from dna2 6.Print the last element from dna2

Trinity College Dublin, The University of Dublin Modifying list elements: Special methods for list objects 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'  Find out more through help() function Accessing specific elements: elem = bases[2] Modifying specific elements: bases[2] = 'A'

Trinity College Dublin, The University of Dublin Exercise: 1.Copy dna2 into dna1 2.Change the last element of dna1 to an 'n' 2. What does dna1.clear() do? 3. What's the difference between append and extend? 4. Try to duplicate the list dna2 5. Add an 'n' to the end of dna2 6. Remove the last element from dna2 7. Sort dna2 8. Reverse the order of dna2

Trinity College Dublin, The University of Dublin Built-in Functions for Lists: all(), any(), len(), max(), min(), sorted(), sum(), zip()  Find out more using help()

Trinity College Dublin, The University of Dublin Exercise: 1. Create a list of numbers: nums = list(range(1,101)) 2. Calculate the number of elements with len() 3. Calculate the sum of all elements with sum() 4. Print the largest and smallest element 5. Print the list in reverse order 5. What does zip do?

Trinity College Dublin, The University of Dublin Tuples: Just like lists, but can't be changed Use of round brackets during creation bases = tuple(seq)

Trinity College Dublin, The University of Dublin Set: Similar to lists, but only shows unique elements  Compare the following seq = 'aatcgcgactacgcac' bases1 = list(seq) bases2 = set(seq)

Trinity College Dublin, The University of Dublin Exercise: Read in a DNA sequence in FASTA format from a file Print out a count of all the letters found in the sequence Tip: use set()

Trinity College Dublin, The University of Dublin Exercise: - Read in a file with numbers - Report the line count - Report the min and max number - Calculate the average of the numbers

Trinity College Dublin, The University of Dublin Exercise: - Read in a file with probe ids, gene ids, fold- change and p-values, separated by tab - Report the line count - Report the min and max fold-change - Calculate the average of the fold-change

Trinity College Dublin, The University of Dublin Exercise: - Read in a file with probe ids, gene ids, fold- change and p-values, separated by tab - Print the header into a new file - Print all the lines with absolute fold-change > 2 and p-value <= 0.05 into that file

Trinity College Dublin, The University of Dublin Weekly task: Read in a DNA sequence in FASTA format from a file Prompt the user for a short motif Split the sequence at the sites that match Print the fragment lengths in sorted order