Skip to content

Notes and code from a May 2018 course on Python and the shell

Notifications You must be signed in to change notification settings

acorg/2018-cambridge-python-course

Repository files navigation

An idealistic Python course

The below will be expanded on during the course. It's far from complete.

Attendees

  1. Alison Sutherland
  2. Ana Mosterin
  3. Christine Hirschberger
  4. Daniel Fabian
  5. Divya Venkatesh
  6. Eppie Jones
  7. Gabby Montejo-Kovacevich
  8. Gabriel Jamie
  9. Maanasa Raghavan
  10. Miruna Rosu
  11. Pier Maisano Delser
  12. Sam Wilks
  13. Stefan van der Vliet
  14. Tali Veith

Description of course, aims, beliefs, etc.

Broad range of students in the class. Help each other. Many of you came at this with no background & taught yourselves (e.g., Sam, Eppie). Be generous. Close the gaps. Make yourselves into a little community. Self support, teach, etc.

Solve problems just over the horizon of what you can do without programming.

This is a course for the beginners. If you're not a beginner, you're expected to help others.

It's actually really great to know nothing and to have no background. There is no stronger position. No one assumes things about you, there are no dumb questions, you can learn without acquiring bad habits.

Let's have an appointed village idiot in each class. Whose job is to ask all possible questions.

Let's have a note taker in each class. Take notes in markdown, push them into our class repo github (which is what you're looking at now).

Course aims

Turn you into programmers (or better programmers).

Get you using the shell (more or less) efficiently.

Get rid of fear.

Show you how to help yourselves.

Show you what's possible - breadth not depth. There are lots of moving parts to understand - let's not get hung up on too many of them. The idea is to get you programming and then give a broad sweep of what's possible.

Get you "over the hump" and turn you into someone who, when faced with a data problem, thinks "I can write a quick script to solve that problem". And then does!

General comments on programming

We're all piecemeal in our knowledge because this is not our job. That's ok. It means within a short amount of time of starting you will know things that (more experienced) others will not, and that, in reverse, people who overall know much less than you will know more about some aspects than you do. = don't be arrogant, help one another.

I only know things piecemeal because I never really made computers my job. You'll always be piecemeal too. It means you'll always have holes, people will always know more than you do. It means you'll complement others and vice versa. Be humble, be useful.

Information processing is fundamental. Evolution shapes us to efficiently process information. Now we've reached the point where a species can build machines that simulate other machines and write programs to run on them to process information however we like. It's quite extraordinary. Working with information is somehow so fundamental. It's like math, only even more general.

Programming gives you a tool that you can use to make other tools.

Programming is really pretty simple

It's all just common sense. Think about how you would do something in the real world, then do that in the computer.

Things that make programming seem hard are: weird names, weird details, frozen accidents.

Programming is often dressed up to look harder than it is. People with knowledge making themselves seem important and protecting their positions.

There are very few control flow things (if/then/else, loop).

There are very few data structures.

All programming languages are (more or less) the same.

Almost all programs start & grow in the same way. From something very simple. From an itch. They always look complex when you arrive late, after many incremental rounds of development.

I have to look things up all the time.

Do these things immediately

  • Make a github account.
  • If you're on OS X, install brew.
  • Then
    • brew install python3 git
  • Install a text editor. E.g. sublime text. Learn how to use it!

Topics

Python

  • Variables.
  • Whitespace (in indentation) is important!
  • Data structures - scalars, lists, tuples, dicts, etc.
  • Control flow.
  • Classes.

Some simple tasks

  • Reading CSV.
  • Reading FASTA.

Jupyter notebooks.

The shell

Is a programming language too, just like Python and can be used interactively or via commands saved in a file.

The shell is extremely powerful, allowing you to do all sorts of things to data without any (real) programming.

Shell metacharacters, loops, variables.

For OS X people, set the option key to send whatever it is...

Navigating on the command line: C-a, C-e. Use M-. and TAB.

Environment variables: PATH.

Shell tools:

  • echo
  • cat
  • less
  • grep
  • cut
  • awk
  • sed
  • perl
  • tr
  • test
  • make
  • parallel and many more.

Manual pages: e.g., man cut

Redirection: |, <, >, stdin, stdout, stderr.

Tip: let the filesystem do (some of) the work.

Testing

Importance of testing!

Difference between scripts and libraries. This split is good for testing.

Version control

Miscellaneous

BioPython

Regular expressions

Make files

argparse

screen / tmux

Something about markdown.

Online notebooks with pelican.

Plotting with matplotlib, plotly, dash.

Other python modules.

Links

About

Notes and code from a May 2018 course on Python and the shell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published