Welcome to Software Carpentry Etherpad!
This pad is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents.
Use of this service is restricted to members of the Software Carpentry and Data Carpentry community; this is not for general purpose use (for that, try etherpad.wikimedia.org).
Users are expected to follow our code of conduct: http://software-carpentry.org/conduct.html
All content is publicly available under the Creative Commons Attribution License: https://creativecommons.org/licenses/by/4.0/
Software Carpentry Workshop - April 27th-28th 2017
Attendance (please add your name):
Byron Smith (Instructor, <bsmith89@gmail.com>)
Chris Gates (Instructor): cgates@umich.edu
Abby Wicks WSU Biological Sciences
James Block Cancer Biology/ MD/PhD
Chase Hellmer
Kendall Muzzarelli
Anna Boegehold
John Butts
Kiran Koya - wsu med school - surgery
Corey Krabbenhoft - WSU Biological Sciences
Nikita Deshpande - Dept of BIological Sciences
Jonathan Greenberg- WSU SOM MIB PhD
Stephen Barr
Ben Kuiper
Elisabeth Steel
Cynthia Kalita
Allison Mitchell -WSU SOM Cancer Biology Program
Larry Grossman
Justyna Resztak (Center for Molecular Medicine and Genetics)
Ashley Anderson - WSU Schol of Medicine Department of Microbiology, Immunology, and Biochemistry
Bob Akins SOM BMB
Matt Fountain
Patrick McLaughlin (Department of Biological Sciences)
Rayanne Burl - School of Medicine, Center for Molecular Medicine and Genetics
Stephanie Gladyck
Aya Attia - WSU med School - Center of medical genetics and genomics CMGG
Michael Salsaa
Cristiano Petrini
Rupali Gadkari
Andrew Winters
Will Close
Vanesa Ramseyer
prasanna
Neeraja Purandare
Day 1 (04.27.17) UNIX SHELL
See https://swcarpentry.github.io/shell-novice/ for lessons covered and additional resources
Instructions to setup data for Intro to Shell
-------------------------------------------------
Move the file to your Desktop and unzip it (usually you can just double click on the file and it will unzip)
Bash (good for more simple tasks)
$ is the prompt-after completing commmand, prompt returns
cd means change directory essentially just clicking on folder
pwd means print working directory shows me where file is located
dashes after words or change in color indicate the word is a folder; no dash after word or no change in color means the word is a file
spacing is important they matter
can do multiple flags at once within one command
man means manual tells you what a command means and how to utilize it
use cd to move up within directory as well eg type cd followed by root path (path with slashes)
cd followed by .. means go to the directory before me so don't have to do so much typing
~ represents /Users/ashleyanderson/ (the home folder) to get to it cd ~
if you start typing something and press tab, terminal will fill in the rest of command
hitting the up arrow reveals the last command entered continue to hit arrow will continure to get previous commands
. before words indicates special file (essentially a hidden file that has been revealed)
ls -l the l means long gives you more info about about files
clear after prompt clears all previous commands and responses
mkdir means make directory allows you to create a new folder/directory or file if you put .txt or something like that behind it
^ means hit control key
rm -r removes a directory and everything in that directory very dangerous tool
rm -r -i so that computer will check with you before it deletes stuff
mv allows you to change name of file/directory and move files into another directory
to open txt files from terminal type nano and name of txt file
cp means copy
to get out nano hit control X and hit enter
cd / also allows you to go up a level in directory like cd..
wc means word count if you want to just focus on line count do wc -l
* means everything in the folder (actually is a wild card-substitutes for anything computer attempts to give results by pattern matching
can * to find files with letters in common
control c is an undo stops everything stops what it's doing and returns your command prompt to you
cat is short for catenate and is a way printing contents of file
sort allows you to sort files in folder
> is a way to move things eg sort -n -r length.txt > length.sorted.txt means you want to take the results of the sort and place them in a new file which comes after the synbol
to access pipe command hit shift and the straight down line with dash key
if you create a nano (text) file and write commands into it you can then in terminal type bash followed by the name of the file and you have just created a new command that you can use
history in command line gives all your previous commands history | tail gives you your last 10 commands
Python by way of jupyter (for complicated analysis or where you want to use code someone else has written)
in terminal typing python lets computer
have to be in data folder you want to analyze and then type jupyter notebook on command line and jupyter web browser
shift Enter and control Enter lead to completion of task
can make python scripts like you would nano scripts by typing python then scriptname.py
when reading python start from top and move to bottom
type (word) identifies to you what type of object/number it is
python/jupyter uses 0 index meaning first item in list numbered 0
use square brackets to direct position in something, if you're trying to perform a function requires parentheses
to import functions/data packages from somewhere else type import followed by name of package
dir followed by name of package will tell you all functions in that function
once you have imported a package to utilize any of it's functions have to write package name.followed by the function name
to identify what line something is on in an input, hit escape followed by l
when renaming something have to remember to write new name in quotation marks eg ""
del is a way to delete objects froml lists; also splicing your list around the object you want to remove is another way to get rid of something
on kernel menu hit restart to completely clear definitions from variables that were assigned
Using python to analyze tabular data
import pandas
csv stands for comma separated variables
. after a name of object indicates the name that comes after that period belongs to that object
.to_name allows you to save a file somewhere else
.ix means index and is a way to retrieve data from the table from whatever row/column the .ix follows; you follow this [row, colum] with rows and columns being numbers or words depending on what's in the table
== means equivalent to/equals
can pick and choose specific rows/columns data (data.continent == 'Africa', data.gdpPercap_1952 > 3000
Python Day 2
to recall/bring in data into particular package use command .read_(file type)
./ means within this directory I want follwed by file you want to open
index in python can be used as a noun to tell the computer how you want to organize your data; it can also be used a verb telling the computer you want to recall certain data by indexing by a certain column/row
%matplotlib inline results in a feature turning on that allows your plots to show up in your jupyter/python web browser
import matplotlib.pyplot as plt is way for you to import data and rename it at the same time
for blank in blank is way to create loops; indents are a way to create loops to break loop unindent; using range( ) before a loop tells the computer how many things you want
def means defining a function; parentheses surround arguments; return tells computer that we want the answer of the function that follows it otherwise no value will be returned as an output for you to view
a single = means assignment; == means equivalent to you
!= means not equal to
can do if, if else, and else statements
Gitmo
version control software (helpful for grad documents when keep creating multiple versions of document)
Git commands: git followed by
init means to initialize respository for where you want new document stored,
status shows the status of document/folder you're tracking changes for
add alllows files to be added to git for version control
commit allows you to write a note summarizing what you wrote and changes that have been made at this point in time
config --global followed by some aspect of under git control eg git config --global user.name "Ash And"
log allows you to view all revisions that have been made to document
reset allows you to change the current state of the repository to a previous state without changing the origninal file that began the repository
checkout allows you to change the current state of the repostiory to a different state and changes the original file that began the repository; checkout HEAD gives you the most recent saved file in your repository
can add/commit multiple files at same time
short hand form of commit: commit -m "commit message here" and press enter; another shorthand for committing: commit -m "commit message here" file.txt
latex is a text editor for writing papers and being able to access them with nano
re-launching terminal will bring it back to default
remove everything before the "$" type: PS1="$ "
ls = list to show what is in your current directory
ls –F = shows what is a directory and what is a file
Captialization matters (case sensitive); spacing is important as well
ls -G color codes directories
for help on windows type: ls --help
cd .. allows you to move up one level in the directory
cd ~ sends you back to the home directory
to set home directory in windows, in cmd type: setx HOME "%USERPROFILE%"
@bioesteel (DOS) Day 1 notes (warning, I am verbose...):
Intro to Shell:
Shell is a program that allows you to interact with other programs
-Bash Shell is a common shell, there are all sorts of different ones, and once you understand Bash, you can translate that to others
The way Shell operates: input a command, Shell reads evaluates and then prints (my interpretation)
READ
EVALUATE
PRINT
- cd .. uses relative path to advance to the current folder's home
- autofil with TAB
- CHALLENGE: Use TAB to avoid typing ALL THE THINGS
- Bash sheel records history (like MATLAB, use the up arrow from your command line, allows you to repeat a variation of a previous command)
- Bash history is not specific to your current session; history is preserved forever; may need to clear out periodically, but probably the reason that we can reproduce workflows... can cut out junk commands that didn't work and recover the ones that did
Pair Exercise 1:
- Execute the commands shown and figure out what each does from the data-shell directory
- command ls -1 : made the file listing into a vertical listing, rather than a 2 column horizontal listing
- command ls -F puts slashes after directories to indicate that those are folders
- command is -G flags the folders with a color (default perhaps is blue?)
- command ls -a we now have to pay attention to anything in the directory that starts with a dot. by convention, files that start with a dot are "special files" (traditionally the "hidden files"). If you can't see a file you are expecting using ls, it's probably hidden
- command ls -l is a long listing "Long format" display that describes some of the file properties including last date modified
- clear clears window
- can stack a commands options ex. ls -FG rather than -F -G
- mdkir (adds a folder to the current path)
- nano draft.txt (creates .txt file and opens it)
- CTRL + O tells you how many lines you wrote, prompts FILENAME save!
- CTRL + X exits from text file
- rm draft.txt removes file
- rmdir removes directory
- rm -r (IT IS POSSIBLE TO DELETE ALL OF YOUR DATA. BE CAREFUL! particluarly if you are using * wildcard)
- Shell Syntax:
- command_name [OPTIONS] [stuff]
- Other things that you may want to do:
- change filename ---> mv draft.txt second_draft.txt
- mv [first input second input]
- Ex: mv second_draft.txt thesis ((moves second_draft.txt to the thesis folder)
- if last input argument
- move file
- change file type
- change directory name
- mv CAN ACCIDENTALLY OVERWRITE FILES!
- cd molecules
- wc cubane.pdb ((wc = word count; default prints [1 2 3 4] outputs
- ^missed which each of these outputs mean!
- Lines:Words:characters (thx!)
- wc -l * ((returns lines with all the files in the directory (* = wildcard)
- could use * to define file type
- ex. wc -l *.pdb
- take away: shell pattern matches for you, reduces workload; can further specify with wildcard based on a second detail like a letter or other pattern shared by multiple files in the directory
- ex: wc -l *ethane.pdb
- ex: wc -l *t*
- returns all the files containing t
- ? and answer: cannot stack wildcards because they are used as an OR, so the suggestion that could be looked into is using the find command when constructing a boolean (? perhaps that's the right terminology)
- sort through redirection example:
- REDIRECTION syntax is > (like a pointer or roadmap sign to a new place)
- wc -l * > length.txt
- cat length.txt
- Will allow you to view file contents from bash window
- i think to finish out this example, we still need to add another option in order to sort the contents of length.txt
- Go figure, sort command is SORT =)
- Ex: sort length.txt returns contents by numerical order of line number (9 methane.pdb...) least to greatest
- but if we want to sort specifically numerically specify sort with the option -n
- further, if you want it in reverse order use -r
- cat prints the contents of a file
- Example provides us two important ideas:
- shell is proposed of focused programs (commands), and tie them together in a sequence to achieve
- provide inputs, get an output, then use output to another input
- piping would be a preferential way to do this, which is going to IN-LINE all of the commands that we just performed by eliminating the need to create intermediate files (this is like the MATLAB equivalent of creating "function functions"
- piping syntax I (vertical line)
- programming ---> piping
- Scripting! Woooooo! Filetype: sh
- Example: take your piped optimized code and you can make your own "function file" using nano, then when you are operating out of the bash shell, you can type in bash script_filename.filetype
- history
- if your $ command line changes to > this is a prompt to complete the command with all argumental syntax (similar to what command line looks like in native command prompt window)
- Common errors/problems:
- caching
- naming --- Use a good name, don't use spaces or special symbols except for underscores when naming
- (^^^Good computing practice)
- (a third one I couldn't hear) Off by one (i think) =)
- Remember to try using TAB to autofill! and up arrow for last commands!
- How many people here know MATLAB? I am writing my notes with some commentary tying to equivalent of MATLAB...
you can use either -l -h or can stack them simply with -lh --> both give you same response
mkdir name = makes new directory in current folder
for Windows users, you can use Notepad++ to create .txt documents (execute using $notepad draft.txt)
rm filename = deletes files
rm -i filename = deletes file after confirming with you
rm -r directory = deletes directory
rm -r -i = deletes directory after confirming with you
rmdir directory = deltes directory but notifies you about contents first
cd molecules/
ls -l
ls -l -h
wc cubane.pdb #tells you stuff about the file. first number is the line counts, second is the word count, and last is the character count.
wc -l cubane.pdb #tells you about the line count of the files
wc -l cubane.pdb ethane.pdb methane.pdb octane.pdb #tells you the line count for all the files listed
wc -l * #give me the line count for everything in this directory. asterisk is a wildcard, that give you zero or more characters to match.
wc -l *.pdb #give me the line count for all the files that end in .pdb
wc -l p*.pdb #give me the line count for all the files that start with p and end in .pdb
wc -l *ethane.pdb #give me the line count for all the files that have *ethane.pdb
wc -l *t* #give me all the files with a t in it.
wc -l *t* *o* #give me anything with a t or an o. lists the files so it will list them twice if they have both of the wild card characters.
wc -l * > length.txt #run the command and put the output into a file named length.txt
cat length.txt #cat prints the content of a text file.
control C #will exit you from the command you are running.
##when making file/directory names, keep them simple, avoid spaces, and avoid special characters. Use underscores, dashes, dots.
sort length.txt #will order the rows in the file
sort -n -r length.txt #switched the order
sort -n -r length.txt > length.sorted.txt #made a new file with the sorted stuff
head length.sorted.txt #shows you the top 10 lines. very useful for large files to get a look at them. however, this file only has a couple of lines.
head -n 2 length.sorted.txt #I want the head (top) of the file and I only want the first two lines.
head -n 2 length.sorted.txt > length.sorted.head.txt
tail -n 1 length.sorted.head.txt #shows you the bottom
##PIPING. Connects commands so you don't make any intermediate files.
wc -l *.pdb | sort -n -r | head -n 2 | tail -n 1 #by piping with the |, it takes the output from one command and uses it in the subsequent command.
nano biggest_file.sh #put wc -l *.pdb | sort -n -r | head -n 2 | tail -n 1 in the nano thing. Save. Exit. Now you have a made a bash command!
bash biggest_file.sh #this gives you the same output as above! so you just made a file to do that command.
recap @ 1130: wc *.pdb > length.txt
sort -n -r length.txt (r for reverse numeric sort)
redirected: sort -n -r length.txt > length.sorted.txt
found the first 2 lines of the header: head -n 2 length.sorted.txt > length.sorted.head.txt
also found last line of file using "tail" prompt: tail -n 1 length.sorted.head.txt
Doing all of this finally gave us the answer we were looking for - what file has the most lines? A: Octane.pdb w/ 30 lines
Pipe command [ | ] connects commands - no intermediate files
$ wc -l *pdb | sort -n -r | head -n 2 | tail -n 1
does same thing as we did but more simply
PS1="$ " #clears stuff infront of dollor shell
ls -F # flags which ones are directories
ls -G # colors directories
cd../.. # go two driectories back or up
clear #clear history
. # means current directory
.. # parent directory
.file # means its a hidden file.
nano file.txt #creates a new text file.
rm -r # remove directory and recursuviley remove everything in the directory.
rm -r -i # removes files interactively.
mv # you can move a file to another directory
# can also rename the file.
# you can accidentally overwrite files by this command.
wc filename #gives how many lines and characters are in a file
wc -l filename # gives lines in the file
wc -l filename1, 2, 3 # gives lines for all of the files
wc -l * # wildcard makes lines of all files
cat #print a file contents without opening.
sort -n #sort by numeric order
sort -n -r #sort by reverse order or high to low
head # show top 10 lines
tail #show bottom 10 lines
head/tail -n number # specify how many number you want to see.
########Piping############
| is pipe command meaning take the output from previous command and use it as input for next command.
wc -l *.pdb | sort -n -r | head -n 2 | tail -n 1 # will take out put from one command and use it as input of next command and give you final output
Save the whole line in file.sh
and type bash file.sh
Python - Day 1
Instructor: Byron Smith <bsmith89@gmail.com>
Instructions to test your Python installation:
-----------
Download https://bsmith89.github.io/2017-04-27-wsu/setup/swc-installation-test-1.py
and https://bsmith89.github.io/2017-04-27-wsu/setup/swc-installation-test-2.py
and move to your Desktop
On the command line move to your Desktop (cd ~/Desktop),
and then run the following command:
python swc-installation-test-1.py
if you do not have any errors, next run:
python swc-installation-test-2.py
and put a red sticky up if you have any errors.
Download and unzip example data:
http://swcarpentry.github.io/python-novice-gapminder/files/python-novice-gapminder-data.zip
@bioesteel Workshop Python notes:
- Once everything is installed and passed error checks:
-
- from bash shell command line: type "jupyter notebook"
- should open up a chrome (or default internet browser tab), into jupyter
- using python as a server, but running locally through Jupyter notebook
- Upper right tab of Jupyter, click 'new' dropdown menu and select Python 3 to open up a new script
- Python could be used like a calculator from the command line, can save variables, and store calculations in variable names
- TypeError refers to data type mismatch when performing an operation
- Type Error description provides the unsupported operand between the data types attempted, (example between an int and str data type, integer versus string)
- (unrelated question to discussion: why the number result from operations involving 10 and 3.14 had a longer format shown than the second calculation performed between 3.1215 and 12.22
- ANSWER: This was a data type situation. diam was auto assigned as a floating point , so when multiplying a floating point against an integer, the .00000....0002 was the result of a floating point operation and the resulting precision is limited to the machine epsilon of your machine you are working on! This is important depending on how precise you need your calculations to be.
- python starts index at 0 in constructs! =O
- len is python function that will return the length of the input
- Python syntax:
- function(inputs)
- storing lists in python uses square brackets, and when indexing into a list you do so by using brackets after the variable name. remember that indexing in python starts at 0!!
- can also use colons to select more than one element within a list
- Slice notation example : our_first_list[2:] #this is a shortcut for using len
- Why would we want to use Python with our research?
- Repititive calculations, and being able to use open source functions and apply it to my analysis rather than having to write complicated logic ourselves
- bioinformatics uses Pearl or Python
- Can import open source code by importing libraries
- autofill = tab competion
- example: import math
- and to use a function within the library or package, must use math.function_name; that way if there is a similar function name in a different library
- NameError means the variable has never been defined
- Line numbers for each row in your cell can be added by highlighting the cell, hit escape, and hit the L button
- can index into string variables waaaaay easier than Matlab,
- Ex:
- a_string = "this is a very long string"
- a_string[10] #this will return 'v' and remmeber that spaces are included and index begins at 0
- list structures in Python can contain more than one data type
- indexing remains same
- remember than you can reassign a structure's context at a particular index and it will persist
- Example: our_first_list[1] = 'Charles'
- our_first_list[-1] = 'Alan'
Python Day 1 - Anna's Notes imported from a word doc so sorry about formatting and stuff that might make sense to me but not to other people! (thank you!)
· Jupyter notebook – enter “jupyternotebook” in terminal and it will open up a web browswer – do not try to dothis in Python! need JN to run python
· in jupyter notebook – to printtext, use quotes “hello world” but if want to print variables, use parenthesis
o print: “Hello World”
o print(variable)
· run cells w/ shift or cntrl enter
· Different variables are differenttypes:
o numeric, string, type
· type() tells you the type of avariable
o integers vs float
· syntax for lists is squarebrackets []
· python starts w/ 0 when listing,so first thing in list is the 0th item, not the 1st
o called “0 indexed”
o len( ) = length of list
· use parenthesis to call afunction
· square brackets = list to indexto
· Work from inside out with scripts
· Remember tab completion in Pythonas well!
· dir for directory, helpfor…additional info
· can import libraries w/ “import”
· to get line numbers – hit“escape” and then “l”
· If you want to call somethingthat’s defined in the library – need to call it specificall from lib
o ex math.cos(math.pi)
§ Can’t just call “pi” if undefined
· Strings are like lists of letters– can call stuff out and index like a list
o all characters count – spaces, tabs, etc
· our_first_list[0] = 'Charles'
o can change the value of something in your list by using the abovecode
o can replace w/ another string! our_first_list[0] = a_string
· REMEMBER THAT WHEN YOU BRACKET,IT’S UP TO BUT NOT INCLUDING THE RIGHT HAND NUMBER
o 0-2 = 0,1
· pandas package to work with .csvfiles
· index_col = to bring up columnsby name instead of column number
· Double equal sign == when pulling up specific colums
o data[data.continent == 'Africa']
§ pulls up only data for Africa
· Can also do great than or lessthan qualifiers:
o data[data.gdpPercap_1952 > 1000]
· Can combine:
o data[(data.gdpPercap_1952 > 3000) & (data.continent =='Africa')]
Python - Day 2
Attendance:
Elisabeth Steel (first! lol)
Anna Boegehold - WSU Biological Sciences
Kiran Koya - med school -Surgery dept
John Butts - WSU Biological Sciences
Ashley Anderson - WSU Schol of Medicine Department of Microbiology, Immunology, and Biochemistry
James Aretakis - WSU Biological Science Grad
Corey Krabbenhoft - WSU Biological Sciences
Allison Mitchell
Chase Hellmer
Ben Kuiper - School of Medicine - MIB
Matt Fountain WSUSOM - MIB
Ashley Anderson
Corey Kra
Vanesa Ramseyer WSUSOM CMMG
bob akins
Cynthia Kalita - WSUSOM CMMG
Stephanie Gladyck - WSUSOM CMMG
Justyna Resztak
cdNikita Deshpande
Larry Grossman (SOM)
Aya Attia
Stephen Barr-Schol of Medicine:BMB
Kendall Muzzarelli - WSU School of Medicine -MIB
Rayanne Burl - School of Medicine, Center for Molecular Medicine and Genetics
prasanna-School Of Medicine- MIB
Cristiano Petrini
Neeraja Purandare-School of Medicine CGG (CMMG)
Abby Wicks-WSU Biological sciences
Will Close (Microbiology, Immunology, Biochemistry)
Remember to set the correct working drive before opening Jupyter Notebook!
Can take notes directly in your code in jupyter notebook by using the pound sign (#) before the text you don't want the program to run as code
can hit shift+tab to pull up a help version in anew window while cursor is in the parenthesis, for example like in "matplotlib.pyplot.plot()" using shift+tabl will bring up help on arguments for creating a plot in this library
If you're getting an error in your syntax- maybe you're using ( ) instead of [ ] or vice versa! I may be speaking from experience.
Python magic to get plots to show in-line in jupyter notebook: %matplotlib inline
- Otherwise, your plot won't generate, or you'd have to use other code to get the plot to show
Remember to work from the inside out when nesting things in parenthesis and brackets
Read error messages! Very helpful in Python because will pinppoint exactly what is wrong!
simple boolean expressions from this link https://www.eskimo.com/~scs/cclass/notes/sx3c.html
<= less than or equal
> greater than
>= greater than or equal
== equal
!= not equal
#elif adds an additional condition onto the code
#if statement formats: if only, if else, if, elif gets tested, then if that's not true then else gets tested
#elif can only be here if it's directly in line with an "if" before
#can do any number of elif statements after an if, and the first one it matches will end the fucntion
Tab fill description for object-oriented programming:
it's like predictable text, if you don't know the name of an option to define, start typing and try hitting tab, and then you get a list of
options that are available if you are on the right track with what the name of the option name starts as
- Ex: if you try tab fill with matplotlib.py... then you will see a little drop down GUI that shows you different options available, you can cycle through that with hitting tab again, and then hit enter when you find your desired option name, type dot, and then continue with your command.
- OR
- another thing we did was assign a variable or handle in advance of the code block we made for plotting,
- we did this by:
- import matplot.lib.pyplot as plt
- #this makes matplotlib.pyplot as an object we can refer
- #example: plt.plot(x, autralia_gdp)
Jupyter Environment hotkeys:
- go to Help Keyboard Shortcuts in the jupyter environment
- hit ESC
- for modifying cells in the environment:
- to add: hit a
- to delete: hit d
- to change indentations
- highlight code block and hit TAB(to tab forward)
- highlight code block and hit SHIFT + TAB (to tab backwards)
Commenting code in Python:
# symbol ahead of your description
Loops in Python:
Example:
- names = ['Theis', 'Lacks', 'Johnson', 'Carver', 'Watson']
- for name in names:
- print(name)
- print() #adds a line between each entry in the name variable
- counters in for loops in order to index into variable in for
- Example:
- i = 1 #counter
- for name in names:
- print(i, name)
- i += 1 #counter
- Example Pair exercise:
- Challenge: how do you use a for loop to count how many entries was in your names variable
- i = 1 #counter
- for name in names: #name is a new variable that is then referred to within the for loop
- print(i, name)
- i += 1 #counter equivalent to i = i + 1
-
- print("The last name was", name) #demonstrates that the scope of the name
- #variable created in the for line persists after the for loop ends
-
- i = i - 1 #lazy way to change your counter index to make up for the fact it started as 1 versus 0 =)
- print("The number of names in the list was",i)
- Question that I overheard:
- Can we use a function that was written and saved outside of the current notebook?
- Yes! Use the import command
- Follow up question, does it have to be in current directory? and is it a .py file type?
Pro tips from Byron:
- don't use lower case L as a variable name because it looks like 1 (one!!
- counter += 1 #short cut for counter = counter + 1
- other shortcuts:
- -=, *=, /=
- Develop skills to interpret Error Messages! (true story, it helps!)
Functions
- Syntax:
- def function_handle(input)
- # if you wish to store your return in a variable
- #example:
- Kelvin = function_handle(input) #here your output is stored in the variable name Kelvin
- Wrapping functions (or in MATLAB this is called Function Functions, I hate that name, wrapping is the proper term)
- Example
- In: celsius_to_kelvin(farenheit_to_celsius(212))
- Out: 373.15
- Example with shorter function names:
- In: f2c = fahrenheit_to_celcius #assign a different handle
- c2k = celsius_to_kelvin #shorter handle
- c2k(f2c(212)) #function wrapping
- Out: 373.15
Logical statements
- Example
- # if else code block:
- some_variable = 4
- if (some_variable == 4):
- print("Yep, it's four.")
- else:
- print("Hmmmmm...no, not four.")
- Example2:
- # logical statements nested in for loop
- some_numbers = [1,2,3,4,5] # range(1,6)
- for n in some_numbers:
- if (n == 4):
- print("Yep, it's four.")
- else:
- print("Hmmmmm...no, not four.")
- Conditional operators:
- operator "Definition"
- == "is equal to"
- != "not equals"
Example3:
# logical statements nested in for loop
# if elif else code block (could also have multiple elif statements between if else to have multiple checks)
some_numbers = [1,2,3,4,5] # range(1,6)
- for n in some_numbers:
- if (n == 4):
- print("Yep, it's four.")
- elif(n > 4):
- print("Woooooh, hold up!")
- else:
- print("Hmmmmm...no, not four.")
- Example4:
- #compound conditional example
- #logical statements nested in for loop
- n = 6
- # n = 10 # run this example as to test the second elif
- if (n == 4):
- print("Yep, it's four.")
- elif(n > 4) and (n < 10):
- print("Woooooh, hold up!")
- elif(n == 10):
- print("this is getting ridiculous")
- else:
- print("Hmmmmm...no, not four.")
- # nested if statements
- n = 4
- #n = 5
- if n == 4:
- print("Yep, it's four.")
- else:
- print("Unforunately not 4.")
- if n > 3:
- print("...greater than 3, at least.")
Git - Day 2
LaTeX (but is pretty heavy - maybe not for begginers) and Markdown (maybe preferred) were the suggested languages for working in Git
guide for Markdown for Github: https://guides.github.com/features/mastering-markdown/
Open
@bioesteel Git notes:
configuration sequence
- to commit a file to your Git after it has been initialized
- git add instructions.txt
- git status (this will return to your screen information that includes:
- (1) your working tree
- (2) any files in this working tree that need to be committed or it will tell you that no files exist in the qeue to commit
- "working tree is clean"
- a.) if you do have a file there to commit,
- type git commit
- type git add filename.txt
- this results in the file opening
- then you type a message for the change (this helps track changes to files)
- to inline add a message while committing:
- $ git commit -m "Garlic RULEZ!" instructions.txt
- $git diff <hexadecimal git address> (i.e. you only have to put in the first 5-6 letters/numbers of the cached file)
- $git
- Byron's Breakdown on 3 states of Git
- 1. State of File \ <-----\
- 2. Staging Area ^checkout^
- \ ^ I was trying to replicate Byron's chart on board, modify if I got the
- commit | description mixed up! Thanks!
- / |
- 3. Stack of Edits -----------------^
$git checkout HEAD #most recent commit (i think, this may not be accurate)
$git HEAD~1 #most recent -1 commit (one before most recent, again, please check for accuracy)
more notes from Byron: allowing branching in your git collaborations is useful for developing in case you want to try to two different approaches to a coding strategy; multiple branching within a git collaboration
Googledocs/Dropbox is great for collaborating, but if you are coding, git may be useful in order to track for version control and git also is preferable for branching
GitHub.com
using github:
create a repository in your github account, and copy and paste the HTTPS address
.........I have fallen off the boat, my notes are lost to the deep sea of the etherwebsgit
AGB Git Notes imported from Word so mind formatting changes:
Git
· can help you keep track ofdifferences in updating versions of the same document
· $ git config--global user.name "Anna Boegehold"
· $ git config--global user.email "annaboegehold@gmail.com"
· $ git config--global color.ui "auto"
· $ git config--global core.editor "nano -w"
· $ git init
· Initializedempty Git repository in /Users/annaboegehold/Desktop/guacamole/.git/
· $ ls
· $ ls -a
· . .. .git
· $ git status
o current status of my repository
· To commitsomething to registry, can start by making a txt doc in nano
o nano file name.txt
o create and save file
o remember to look at file contents use “cat”
· $ git addinstructions.txt
· $ git status
· On branchmaster
·
· Initial commit
·
· Changes to becommitted:
· (use "git rm --cached<file>..." to unstage)
·
· new file: instructions.txt
· 2 stages tosaving in git:
o 1 – add
o 2 – commit using “git commit”
§ this will openup nano
§ here you canadd message to yourself or others on what you did w/ the changes
· Save and commit file and you will get a prompt telling you what was changed (files,lines added, subtracted, etc.)
Double check using "git status" to make sure you have nothing to add