1 Essential Computing for Bioinformatics Bienvenido Vélez UPR Mayaguez Lecture 3 High-level Programming with Python Part III: Files and Directories Reference:

Slides:



Advertisements
Similar presentations
Introduction to Computing Using Python File I/O  File Input/Output  read(), readline(), readlines()  Writing to a file.
Advertisements

Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
Unicode, character sets, and a a little history. Historical Perspective First came EBCIDIC (6 Bits?) Then in the early 1960s came ASCII – Most computers.
CHARACTERS Data Representation. Using binary to represent characters Computers can only process binary numbers (1’s and 0’s) so a system was developed.
Working with Files CSC 161: The Art of Programming Prof. Henry Kautz 11/9/2009.
Introduction to Computing Using Python Chapter 6  Encoding of String Characters  Randomness and Random Sampling.
Python programs How can I run a program? Input and output.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 17 Reading and Writing Files 5/10/09 Python Mini-Course: Lesson 17 1.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
November 15, 2005ICP: Chapter 7: Files and Exceptions 1 Introduction to Computer Programming Chapter 7: Files and Exceptions Michael Scherger Department.
CIS 270—Application Development II Chapter 14—Files and Streams.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
Guide to Programming with Python Chapter Seven (Part 1) Files and Exceptions: The Trivia Challenge Game.
Data Representation and Storage Lecture 5. Representations A number value can be represented in many ways: 5 Five V IIIII Cinq Hold up my hand.
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
Lecture 06 – Reading and Writing Text Files.  At the end of this lecture, students should be able to:  Read text files  Write text files  Example.
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
File I/O Michael Ernst UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
File I/O Ruth Anderson UW CSE 160 Spring File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
Text Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Files Tutor: You will need ….
CIS 234: File Input & Output introduction. Data Storage Is Fundamental computers need to store data to work with it memory (RAM) is fast but transient.
1 CSC 221: Introduction to Programming Fall 2011 Input & file processing  input vs. raw_input  files: input, output  opening & closing files  read(),
Understanding Character Encodings Basics of Character Encodings that all Programmers should Know. Pritam Barhate, Cofounder and CTO Mobisoft Infotech.
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
8086/8088 Instruction Set, Machine Codes and Addressing Modes.
File I/O Ruth Anderson UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Lakshit Dhanda. Output Formatting Python has ways to convert any value to a string. 2 Methods repr() – meant to generate representations of values read.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
MARC: Developing Bioinformatics Programs Alex Ropelewski PSC-NRBSC Bienvenido Vélez UPR Mayaguez Reference: How to Think Like a Computer Scientist: Learning.
Kanel Nang.  Two methods of formatting output ◦ Standard string slicing and concatenation operations ◦ str.format() method ie. >>> a = “The sum of 1.
PERL SCRIPTING. COMPUTER BASICS CPU, RAM, Hard drive CPU can only use data in the register directly CPU RAM HARD DRIVE.
MARC: Developing Bioinformatics Programs Alex Ropelewski PSC-NRBSC Bienvenido Vélez UPR Mayaguez Reference: How to Think Like a Computer Scientist: Learning.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
THE CODING SYSTEM FOR REPRESENTING DATA IN COMPUTER.
Introduction to Programming
Topic: File Input/Output (I/O)
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Introduction to Programming
File I/O File input/output Iterate through a file using for
Variables and Expressions
Python’s input and output
Essential BioPython Retrieving Sequences from the Web
Introduction to Programming
Introduction to Programming
Ruth Anderson UW CSE 160 Winter 2016
Ruth Anderson UW CSE 160 Winter 2017
Ruth Anderson UW CSE 160 Spring 2018
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Reading and Writing Files
File IO and Strings CIS 40 – Introduction to Programming in Python
Lesson 08: Files Topic: Introduction to Programming, Zybook Ch 7, P4E Ch 7. Slides on website.
File I/O File input/output Iterate through a file using for
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
Lesson 08: Files Class Chat: Attendance: Participation
Introduction to Programming
Topics Introduction to File Input and Output
Bryan Burlingame 17 April 2019
CSE 231 Lab 5.
Topics Introduction to File Input and Output
Presentation transcript:

1 Essential Computing for Bioinformatics Bienvenido Vélez UPR Mayaguez Lecture 3 High-level Programming with Python Part III: Files and Directories Reference: How to Think Like a Computer Scientist: Learning with Python (Ch 11)

2 Outline Text Files Reading from Text Files Writing to Text Files Examples

3 Text Files Persistent (non-volatile) storage of data Needed when:  data must outlive the execution of your program  data does not fit in memory (external algorithms)  data is supplied in batch form (non-interactive) Files are stored in your hard drive Files are maintained by your computer’s Operating System (e.g. Linux, Windows, MacOS)

4 Examples of Text Files Word documents Html documents retrieved from the web XML documents FASTA files GENBANK file Text files contain a sequence of numbers that must be decoded using some standard in order to be converted to string form Examples of encodings: ASCII, LATIN1, EBCDIC, Unicode Check for more infohttp://en.wikipedia.org/wiki/Character_encoding

5 Reading From Text Files in file=" " infh=open(infile) line=infh.readline() while line: #do something with the line line=infh.readline() infh.close()

6 Summary of File Operations Table File methods Method Action read([n]) reads at most n bytes; if no n is specified, reads the entire file readline([n]) reads a line of input, if n is specified reads at most n bytes readlines() reads all lines and returns them in a list xreadlines() reads all lines but handles them as a XRangeTypea write(s) writes strings s writelines(l) writes all strings in list l as lines close() closes the file seek(offset [, mode]) changes to a new file position=start + offset. start is specified by the mode argument: mode=0 (default), start = start of the file, mode=1, start = current file position and mode=2, start = end of the file

7 Reading from Files II Structured Text Files def loadSequencesFromFile(filename): seq_dict={} infh= open(filename) for line in infh.xreadlines(): fields = line.split() code = fields[0] seq = fields[1] seq_dict[code] = seq infh.close() return seq_dict 4657 GCGTAT 5739 GGGGCCTAA 6123 TTTTACGTACGCGGGCC …

8 Writing to Text Files def storeSequenceComplementsFile(sequences, filename): ofh = open(filename,"w") for key in sequences,keys(): print >>ofh, key, sequences[key], complement(sequences[key]) ofh.close()

9 Exercises Write a function to generate a file of proteins corresponding to a file of sequences