New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

week 8: all given about functions, OS, Sys and Glob

by: Marina Notetaker

week 8: all given about functions, OS, Sys and Glob CSE 6613

Marketplace > Mississippi State University > Buttler Hall > CSE 6613 > week 8 all given about functions OS Sys and Glob
Marina Notetaker
GPA 4.0

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

All material needed for next assignment (5), plus information of functions for next quiz and detailed information about Sys and Glob.
Andy Perkins
Class Notes
25 ?




Popular in Bio-computing

Popular in Buttler Hall

This 8 page Class Notes was uploaded by Marina Notetaker on Sunday October 9, 2016. The Class Notes belongs to CSE 6613 at Mississippi State University taught by Andy Perkins in Fall 2016. Since its upload, it has received 2 views. For similar materials see Bio-computing in Buttler Hall at Mississippi State University.


Reviews for week 8: all given about functions, OS, Sys and Glob


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/09/16
October 3rd, 2016 Subroutines or Functions 1. It defines some for your program, making it easier for your program. For example: you want to find the biggest number from 3 numbers or a list. You could do something like this: However, if you want to test other three numbers you would need to write the code again. So it is not the best way to do it. Another to do it without writing the codes all over again is defining a name of whatever you are going to do and between ( ) you call the program what it should do. So: I am defining the name of the program “biggestofthree” and telling it that whatever it is going to do, it will use the variables a,b and c. I am not going to print anything. Iwill onlyprint whenever Idefine what will be the variables representing a, b and c. - It will only run when you called it. - Structure: Def ‘name of program’ (variable or what is going to read): Test program in which you can call it whatever Return - Return is the way you are asking the program to do it again whenever you called it to print by defining another character or to do it again if it is a loop or list 2. Advantages of functions: a. Once youdefine yourprogram,itiseasiertounderstand whatever yourprogramisdoing.Forexample: it is finding the biggest number of three. b. It can be used again without changing the code, or without repeating the codes, so it is less work and less probability or re-writing the code wrong. Once it works it will always work. 3. Using functions to work on lists. Another example: You want to find the average of a list of numbers. You need to create a list. -Be careful how you name things: Def ‘name of function’ (call anything, is what you will test): Variable you testing, can be avg, sum, multiples, etc – try to not call your variable with same number as your function’s name. Return ‘your variable name’. So, when you want to test you call your ‘some list’ and you tell ‘test name’ = ‘functionname(some list)’ Print (‘test name’) *Your variable could be a dictionary = { }, or a set = { }, or a matrix = [ [ ] [ ] ]… The thing is your are just defining the name of your program. The rest of the program is prettymuch the same as we were doing before. - One example for the test: compute the area of a circle. a. Build the objective called ‘circle’ b. Circle.r = radius c. Circle.a = area d. Circle.c = circumference A = (3.12 r)**2 We can make it in 3 functions: 1.find area by given radius 2.find radius by given circumference 3.find circumference by given radius Or we can make it in a single function, like in the circlearea2, in which you find the area by given a circle circumference. 4. Using function to analyze fasta files (assignment 5). From a given fasta file, print the gene ID, start and stop codon, length of gene and GC content. Start, stop codons and GC content should be given by using function. October 5 , 2016 Getting arguments passing through the command file (keyboard) 1. IMPORT SYS For example, opening your python and you want to write a program called “” and put some numbers after that. How can you make it run this program? a. There is a module called SYS b. Import Sys: it is kinda link to the operator system, so how the program interacts to your system. *Notice, for that you need to create a file called on your interpreter first and the program should run at the same location where your interpreter python is located. In my case at the folder Bio-informatics. The command Print (sys.argv) will print a list of sys which will be the name of the program and each numbers (that are strings once they become a list) together. 1.1 Writing a program that add the numbers together. Remember SYS make everything as a list, so treat it as list! It is called command line arguments. Note,it shouldstart at 1because[0] isthenameofyour program on the list. List turns everything as string, so you need to float it! Float (listname [index]) It is not that useful doing mathematical operations by this method. But it can be used to get a name of a text file. For example, you want to call a file to use its numbers that are like in list. In the usual way would be: By using Sys command would be: How you write at your command file: Python + program name where SYS is imported + name of your file You could write other files names, but if they don’t exist it won’t make anything. 2. Using more than one file It goes to 1 to the length of sys.argv The file that is going to open is whatever list you will make part of sys.argv, that will be what you will type after your python program name. So your sys.argv can be numbers, strings, lists or even files that will all become a list and work in your program. When you say index, it goes in a loop for each “character” from your sys.argv. Note, it will open each list file and sum each numbers from same list. It is not going to sum all together. 3. Using more than one file without typing files names – GLOB -Import Glob -No need to do command line (give the name of the files after python program name) -Length starts at zero because you don’t have the program file name anymore on your built list -total length is the length of file names ‘len(filenames)’ -print the same thing as using the SYS, but you don’t need to call by the test files names. -useful: RNAseq analysis or data that come through sequencing machine, it puts the information on different files and at some time you need to combine the files so you can work on them. 4. Using GLOB to build a matrix using files with list of numbers -Advantage: you don’t need to type all files’ names neither know their names. -make the lists with same length. You can just add zeros to make them with same length. **It reads each line and put it in a matrix *** If you want to associate your data with your file name, you can turn exp into a dictionaryand print it as k, v. Note: - glob get the files for numerial or alphabetical order but you are not always sure what woul be the order of the file that is getting in - glob will just get the files where your python is. but if you want to get a file from other folder, you can say: - glob.glob('c:\\Users\\mitie\\desktop\\bio-informatics\\*.txt') - if you use windowns, you need to do \\ because in python already have a function for \. - glob is useful when you want to get all files from a folder and use it and build a list of files and you do whatever you need to do 5. OS MODULE os.remove( ‘filename.txt’ ) – use to remove a file, but it is not useful because once removed you never get it back again. Subroutines or Functions – PART II EXAMPLE 1: Write a function that take a DNA sequence as input and output a list of codons, so break the 3 letters and turn it into a list. Define what is codons from any DNA. Ways to print it: 1. Something = function-name(how ever you call your DNA) Print (something) 2. Give the something = sequence Print (function-name (something)) It does not matterhow youwill call yourDNAsequence. EXAMPLE 2: Write a function that take a DNA sequence as input and output a list of possible reading frames. The reading frame is when you shift over a site and then on. Reason to do that is not always that we know where a reading frame start because it might not have a start or stop codon to identify. ATTATTATTGAT TTATTATTGAT TATTATTGAT *rf-1 = it is to tell that the first reading frame becomes at the zero position on the sequence instead of 1. Other way to do it without asking each reading frame at a time. EXAMPLE 3: You can print all codons and associate two functions. Not so recommended if you want to work all individually.


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.