File Input and Output July 2nd, 2015. Inputs and Outputs Inputs Keyboard Mouse storage(hard drive) Networks O utputs Graphs Images Videos(image stacks)

Slides:



Advertisements
Similar presentations
Parts of a Computer.
Advertisements

Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
The Binary Numbering Systems
Computer Science 111 Fundamentals of Programming I Files.
Simple Java I/O Part I General Principles. 2 Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 13 Strings and File I/O  Read Bishop, Chapter 9.  Lab #13 and Homework #13 due next week.
TERMS TO KNOW. Programming Language A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. Each language has.
Python programs How can I run a program? Input and output.
©Brooks/Cole, 2003 Chapter 2 Data Representation.
An Introduction to Textual Programming
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
3. Multimedia Systems Technology
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Text and Graphics September 26, Unit 3.
Basic File Input and Output Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 7 Files.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
R packages/libraries Data input/output Rachel Carroll Department of Public Health Sciences, MUSC Computing for Research I, Spring 2014.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
Database Management Systems (DBMS)
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
Files Tutor: You will need ….
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Simple Java I/O Part I General Principles. Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for.
09/06/ Data Representation ASCII, Binary Denary Conversion, Integer & Boolean data types.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
EET 2259 Unit 13 Strings and File I/O
Topic: File Input/Output (I/O)
Fundamentals of Python: First Programs
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Topics Introduction Hardware and Software How Computers Store Data
Chapter 7 Text Input/Output Objectives
Digital Electronics Jess 2008.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Part I General Principles
Binary Files.
Python I/O.
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Fundamentals of Programming I Files
Topics Introduction Hardware and Software How Computers Store Data
Fundamentals of Data Structures
Fundamentals of Python: First Programs
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Spreadsheets, Modelling & Databases
Topics Introduction to File Input and Output
EET 2259 Unit 13 Strings and File I/O
General Computer Science for Engineers CISC 106 Lecture 03
Topics Introduction to File Input and Output
ASCII and Unicode.
The Data of Visualization
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

File Input and Output July 2nd, 2015

Inputs and Outputs Inputs Keyboard Mouse storage(hard drive) Networks O utputs Graphs Images Videos(image stacks) Text files Statistical results

Keyboard Input The simplest input is reading in lines from the user print (“Please enter a number: “) x = scan() Print (“Your number is “ + x)

Inputs and Outputs Entering data on your own is time consuming Large amounts of Data already exist in files MATLAB, R, and Python all provide the ability to read data from files (as well as write data to files)

The basics of File Input and Output File Input and Output are the bread and butter of data manipulation and generation File Code New File

Part 1: File Types Text Files Images Excel Files FASTA files Other

Text Files A lot of data comes in the form of of spreadsheets in text files (.txt or.csv extension) Generally the easiest to manipulate

Image files Images are stored as spreadsheets, where each pixel is represented by an X and Y co- ordinate and a range of values for the intensity of the pixel These values depend on what type of file the image is

Binary and Grayscale Binary Image  Represented as either Boolean (TRUE, FALSE) or numerical (0,1) Grayscale Image  Represented with a range of numerical values (usually between 0 and 255)

Binary and Grayscale BinaryGrayscale

Color images Color images can be thought of as a stack of 3 images (red, blue, green) The intensity of each color is represented as a number between 0-255

Color images

Common I/O themes File type – The type of file the data will be saved as. Data type – The type (or mode) of the data (integers, strings, characters) Separator: What separates the data from each other; in text files, this is often a,

Reading a file Most programming languages have functions that “read” files. You generally have to specify the type of file being read, or the computer will not know how to interpret what it's looking at

Reading a File Reading data into a program can often times be difficult and frustrating Can sometimes take more time than the rest of the coding! It's important to understand the subtleties and nuances that is specific to each language

“Data Preparation” When working with any type of spread-sheet like files (e.g., excel): easier to export the data as a text file Image files can be converted from one type to another with relative ease. How you want to manipulate an image will determine in what format you want to save the image as.

Character Encoding Used to represent all of the characters in a form computers can understand it There are different types of character coding, the most common being Unicode Modern operating systems are likely to use UTF- 8 or Unicode files

Character Encoding If character encoding differs between your data and what a computer uses to view the data, your text files can look like gibberish. Character Encoding can be changed using programming language specific functions

Reading a File R  read.table()  read.csv  scan() Python .read()  open()  readline() Matlab  importdata()  fscanf()  fopen()

File Output Generating a file is an easier process than reading in a file Stored data can be written to a file of your choosing, whether it's an image, text file, etc. write(x, file = “C:\Program Files\R\data.txt”)C:\Program write(x, file = “data.txt”, sep = “,”)

The Working Directory The working directory can be thought of as the area that the programming language currently points to When reading or writing files, if a full path name is not given, the program will automatically look in the working directory to read or write a file

Part 2: Pipelines A way of structuring code that makes it simple to work with Simply, a pipeline is a chain of processes (such as functions) arranged so that the output of one process is the input to the next process

Part 2: Pipelines Sequence Data Find Start Codon Convert to Amino Acids Save Amino Acid File

Functions findstart <- function(fullseq, codons = c("atg", "taa", "tag", "tga")){ startposition <- sapply(codons, function(x){start(matchPattern(x, fullseq))}) return(substr(sequence, startposition, length(fullseq)) } AminoSequence ← function(sequence){ amino ← *lots of code and a library of amino acid sequences* return(amino) }

Functions simplesequence ← scan(“simplesequence.txt”) sequenceTwo ← findstart(Thesequence) AminoSeq ←AminoSequence(sequenceTwo) write.file(AminoSeq, file = “Amino.txt”)

Pipelines Structuring your code into functions can help ease the readability of your code and allow you to reuse functions for similar processes Pipelines are excellent for automatic processing of a large amount of data sets