Friday, January 31, 2014

So you're attending your first Python users group meeting / meetup

Full HouseCongratulations! You have decided to attend your local Python users group (PUG) meeting (or "meetup" in the Meetup parlance), putting yourself on a path for success in mastering Python, and programming in general. Here are a couple of tips to help you arrive prepared and ready to participate.


The most important thing to bring to a PUG meeting is yourself and your enthusiasm. If you're in a rush and don't have time to set up your laptop or anything else, don't worry, just attend! You will be welcome regardless of your technical and personal background. The global Python community expects an atmosphere of respect and welcoming at each event, especially for newcomers.

Bring a laptop

Each PUG will arrange its meetings differently. DCPython, for example, tended towards mostly presentations while I was a member. In contrast, OCPython has had less formal meetings where there's more interaction and audience participation. Be prepared. Bring a laptop just in case.

Prepare your laptop for Python

Everything in this section should be considered optional but very helpful. Try to get your laptop set up before the meeting. Don't fret if you can't or don't have time, though!. Wi-Fi access can't be guaranteed at a lot of venues, so it will be extremely helpful if you have all your software downloaded, and, if possible installed and configured, before the meeting.

If you get stuck with any of the tasks below, don't fret, and do attend anyway! You will find other attendees willing to troubleshoot and get you un-stuck, I promise. The Python community is among the friendliest and eager to help.

Know how to open your terminal emulator

Most Python programs are invoked via the command line (typically by issuing a command that looks like "python <>"). Learn how to access the terminal emulator/command line for your laptop's respective operating system, such as PowerShell for Windows, Terminal for OS X, or GNOME Terminal for Linux.

Make it easy to get to the terminal emulator by putting a shortcut to it on your desktop, dock, or launcher. Oftentimes the presenter will assume you already have your terminal open and at the ready.

Configure your terminal emulator to your liking ahead of time. For example, I find the default font size in OS X's Terminal too small and the colors too pastel to the point of being illegible. Finding the right places to change these settings to suit your style (and eyesight) can take some time, so get them fixed ahead of time. You won't want to be fiddling with these settings while the presenter's nuggets of advice go flying by.

If you're unfamiliar with working on the command line, see Zed Shaw's Command Line Crash Course.

Have a working Python installation

If you have a Mac or a Linux laptop, the good news is you already have Python installed; proceed onward.

If you're a Windows user, you have a little work ahead of you. First, download a Python installer from the Python website. Just grab the latest version (Python 3.4 at time of publication), run the installer (double click the installer file), and go through the dialogs (you can trust the defaults).

The final step is to put Python on the PATH so that you can run Python from your command line. Here is a howto for Windows 7 users. (Note: instead of using "Python27" use a number matching your download, for example "Python34" if you downloaded and installed Python3.4)

You can verify you put Python on your path by opening PowerShell, typing in "python", and pressing the Enter key. If you see a prompt that looks like ">>>" you're good to go. If instead you get an error that "python" isn't found, try going back through the steps of setting your path. If you get stuck here, ask for assistance at your meeting, show your helper this blog post, and they should be able to get you back on track.

Have a text editor or IDE installed and configured

Python programs are plain text files with .py extensions. While you could use Microsoft Word (heaven forbid) to open and edit the files, you should use a specialized tool for editing code. If you're new to programming, you'll probably do fine starting with a good text editor that provides syntax highlighting and help with formatting your code correctly. If you're on Linux, you probably already have a decent editor like Gedit installed. If you're on Mac OS X try something like Sublime Text. If you're on Windows, try Notepad++.

If you have some experience in programming in other languages or have the interest in investing more time upfront, you can install and get started using an integrated development environment (IDE). If you don't yet have a favorite IDE for Python development, try PyCharm or Ninja IDE. IDEs provide not just a text editor but also a debugger, a test runner, an interactive console, and some form of project management, among other tools. Again, if your a newbie, just stick to getting a good text editor set up before attending the meeting.

Have pip installed

pip allows you to easily download and install other Python software libraries (called "Python packages") from the Internet. All you have to do is open your terminal, type in "pip install <PACKAGE_NAME>", and press Enter, and pip will fetch the package from the Internet and install it for you. pip can come in quite handy if you would like to try out any packages mentioned or shown in tutorials during the meeting.

If you installed Python 3.4 or newer, you already have pip installed. Proceed onward!

If you have Python 3.3 or older (including Python 2.7), you will not have pip installed by default (unless you used an alternative Python distribution like Anaconda). You can check whether or not you have pip installed by typing in "pip" on your command line and hitting the Enter key. If you get an error that the pip command cannot be found, you will need to install pip.

The pip documentation describes how to install pip. The easiest method uses the script. If this fails for you, you may need to try one of the alternative install options.

This may be a more difficult step for Windows users. First, make sure that Python is on your PATH (see "Have a working Python installation" above). Next, download the script by right-clicking the link, selecting "Save As", and designating a location to save it, such as your "Downloads" directory. Next, open PowerShell and use the cd command to move to your download directory (e.g., "cd $HOME\Downloads". Finally, in PowerShell, run python

After the installation of pip completes, you should be able to access pip from the command line by typing in pip and hitting Enter. Again, if you get stuck, show this blog post to someone at the meeting and he or she should be able to help you.

Bring some extra equipment (optional)

In an ideal PUG event, organizers will have time and resources to set up the event area with ample access to power, Wi-Fi, and the like. If your local PUG is new or just getting started, though, the organizers may have a hard enough time just finding a location to meet, let alone have time to prep the area for lots of tech. Here's some equipment that you can bring along that could help everybody have a better experience.

  • A wireless hotspot device
  • Display dongles, adapters, and cables
  • Power strips
  • Business cards

Have a good time; let others have a good time

PUG meetings are social events, not formal meetings. Some may run on tight schedules because they pack a lot of content in, however, don't confuse that structure with formality. Everyone attends PUG meetings first and foremost to share in the joy of the Python programming language. Unless you're presenting (and usually even if you are), you don't need to dress up; just come in something comfortable and inoffensive.

Do conduct yourself appropriately at the meeting, and err on the side of professionalism. The PyCon Code of Conduct provides a good set of guidelines. If another attendee behaves inappropriately towards you or makes you feel uncomfortable or unwelcome, do feel free to confront the attendee on her or his behavior directly or otherwise raise the issue with the PUG's organizers immediately.

On behalf of your local PUG, we look forward to seeing you soon!

Thursday, December 6, 2012

Putting syntax-highlighted code into presentation slides or documents

Brogramming with Tom

Want to include syntax-highlighted code in your presentation? A project called Pygments provides a very helpful tool for this. First, you need to install Pygments:

  • If you're on OS X and use MacPorts, you can fetch it with
    sudo port install py27-pygments
  • If you're on Ubuntu/Debian, you can get it with apt-get with
    sudo apt-get install python-pygments
  • Or you can fetch it on any platform using pip* with
    sudo pip install pygments

Installing Pygments will also install a command line utility called pygmentize**. We can use this tool to help us format code for use in a presentation or document with the following steps

  1. Open the terminal and do
    pygmentize -f rtf <PATH_TO_CODE_FILE> | pbcopy
    if you're on OS X, replacing <PATH_TO_CODE_FILE> with the actual path to your file of interest (use xsel -b instead of pbcopy if you're on Linux, or clip if you're on Windows). This will copy a colorized markup of your code to your clipboard.
  2. Paste the contents of the clipboard to your document or slide
    • This should be as simple as using Edit → Paste (COMMAND + V on OS X, CTRL + V on anything else)
    • If you're using PowerPoint, you instead need to use Edit → Paste Special (CTRL + COMMAND + V shortcut on Mac Office) and select "Formatted Text (RTF)". Also, you may need to create a new text box first, as the default text box will unhelpfully try to insert bullet points for you. Alternatively, you can just remove the bullet points by highlighting all the code and clicking the bullet point button (sometimes having to do this multiple times...)

That's it! pygmentize can parse files in a wide number of programming languages, as well as output in many different formats; for example, if you use LaTeX/Beamer, you can get TeX output by using -f tex. You can look at the Pygments documentation on lexers and formatters to see the full list of languages and output formats Pygments and pygmentize support.

* Don't have pip? Go get it!
** If you installed with MacPorts, you'll probably have to use pygmentize-2.7 instead of pygmentize.

Saturday, September 10, 2011

In remembrance of September 11, 2001

American Flag picture - photo of the American Flag

Today, I set aside some time from preparing for my defense to read through the New York Times' tribute to September 11, 2001, and reflect upon what that day and the events which have followed mean to me. I did not expect to feel so profoundly moved as I read through the stories, and in particular, I could not help but feel struck afresh with anguish and cry as I carefully paged through the moving slideshow of the rise and fall of the towers of the World Trade Center.

Still, other articles reminded me of my core belief in our country — in the people of our country. In spite of the willful erosion of personal privacy and civil liberties and civil tongues, in spite of the tragic sacrifice of human lives both domestic and foreign, in spite of ongoing anti-intellectualism, in spite of continuing sexual, religious, and racial intolerance, in spite of a bitterly polarized political climate, in spite of our continued mismanagement of our environment — in spite of all this, I still believe that the story of the United States of America is one of hope. If ever there were a country to break pre-conceived notions, to defy intolerance, to unite for a greater good, to show that change can be for the better, to overcome adversity, then it must be ours.

Ten years ago, I stood with friends in an undergraduate dorm room and watched the World Trade Center towers collapse and the Pentagon smolder. Now, here I stand to defend my Ph.D., and I can not help but feel grateful for all the opportunities I've had thanks to having a life here in the USA. I am not always proud of our country's actions, but I am proud of what our country stands for: truth, liberty, and justice for all. Our story is marked by tragedy and marred by missteps, but it is, indeed, the story of hope. I will always remember.

Tuesday, August 9, 2011

The bog of eternal singlehood: college towns beyond college

Life in a college town

As I apply for jobs, many of which, for better or worse, are at academic institutions, I keep having a nagging feeling tugging at the back of my mind, like the tantrum-throwing three year old desperate for that Yo Gabba Gabba doll tears at her parent's arm in aisle 14 of the local Target. This pressing thought which brings me so much strife: I'm just not sure if I can take living in yet another land-grant college town.

Don't get me wrong—there are many great things about living in a college town. Life is generally quite pleasant and quiet, save football weekends. The cost of living is usually fantastic. They also tend to be family friendly, with quaint little farmers' markets and little local restaurants and shops. They also tend to be fairly progressive and open-minded, and support culture and art to a greater extent than you'd expect from such a small population.

Yes, for many people, a college town is a rather idyllic place. There is a specific subpopulation in these college towns, however, for whom the experience becomes utterly hopeless. This subpopulation: those who move to college towns, are not college-aged, and arrive without a significant other. Meet those requirements, and you're basically hosed until you escape. It is the bog of eternal singlehood.

I mean, let's take an honest look at the candidates in the dating pool in a college town for those who already hold one or more higher education degrees:

  • College kids: I'm sorry, did you not see the word "kids" there?
  • Grad students: Emotionally unstable semi-adults who incorrectly concluded that the panacea to their life problems was to get yet another degree.
  • Postdocs: Does the sound of frantic typing as they try to finish their latest lit review during the act of love-making turn you on?
  • Junior faculty: Ah, the less youthful, less healthy, more stressed versions of postdocs. Yes, I'm sure you had a good reason behind that choice...
  • Staff: They probably arrived there because of a significant other; if they are single at this point, they're looking for an opportunity to flee, not to stay.
  • Hipster/Hippie Townies: It's okay, so long as their friends never find out they're sleeping with you. Oh wait, it's a small college town...
  • Folk in the surrounding countryside: don't be surprised if you're viewed an over-educated, heathen, pinko socialist who never learned how to do anything actually useful (all of which could be accurate assessments)
  • People in the nearest city... five hours away: They're already pairing up with equally smart, young, attractive, better-paid competition that had the foresight to not force the issue of a long-distance relationship on the first date.

As a consolation, you will find great friends, for whom your sad, lonely, single self will serve as a reminder of why they need to stay committed to their own relationships.

With complete seriousness, I've found a tremendous amount of personal growth in the college towns I've inhabited for the past twelve years, and certainly, the quality of friends I've found in them has been unsurpassed. I admit that location is really only one part of the whole romantic equation.

Anyway, we'll see what the future brings. Maybe I'll finally join the young guns in a big ol' city, myself. Or maybe I'll find the the one who breaks the mold. Or maybe it'll just be the status quo, but hey, there are far worse bogs out there!

Friday, April 29, 2011

Let's talk: designing inter-cellular circuits through synthetic biology

True phone

Thursday, GenBioOrg brought in Prof. Ron Weiss to speak about his work in designing biological circuits, and this crazy, sometimes hyped field of synthetic biology. Prior to Prof. Weiss's talk, while I could appreciate the idea of synthetic biology, I mostly regarded it as a somewhat foolish pursuit, on account of the amount of fundamental biology we still just do not know. In many ways, my field of computational systems biology relies on building and testing models from "Swiss cheese knowledge", where gaps prevail (e.g., protein-protein interaction networks built from yeast-two-hybrid studies with high false-positive rates, or microarray analysis suffering from from the high-dimensionality, low-sample conundrum). Thus, whatever decries the prematurity of systems biology goes doubly so for synthetic biology, for which systems biology provides a central strut. The rationale is, if you don't understand it, how can you manipulate it? Of course, as I've learned repeatedly (but have failed to generalize), "You don't need to understand the internal combustion engine to drive a car."

Well, Thursday afternoon, Prof. Weiss deftly reminded me of this reality through his combination of humility-tempered optimism, his impressive collection of proofs-of-concept, and his insight for possible applications. He presented a number of intriguing biological circuits in his talk, but I felt most excited by his work on pattern formation through synthetic inter-cellular signaling networks (behind a Nature paywall, sorry). In this work, Weiss and his colleagues created a population of "receiver" bacteria cells, which had a genetic circuit that would cause cells to fluoresce (light up green) at a moderate concentration of a molecule called acyl-homoserine lactone (AHL).

To make the receivers fluoresce within a specific concentration of AHL, Weiss and colleagues actually made the receiver cells fluoresce (i.e. "be on") by default. They then created two AHL-detection circuits with very different input thresholds: a high-detection circuit which activates in the presence of large amounts of AHL, and a low-detection circuit which activates in low amounts or in the absence of AHL. Weiss and colleagues wired both detectors to the same output: when activated, they repressed ("turned off") fluorescence. If you're familiar with electronics, you'll see that Weiss and colleagues constructed a NOR gate, where the inputs are "high AHL" and "low/no AHL". If you're a programmer, you might think of the condition for fluorescence as

if not (ahl_level > high_threshold) and not (ahl_level < low_threshold):

Weiss and colleagues then developed "sender" cells containing a circuit that caused synthesis and secretion AHL when exposed to tetracycline. When a colony of sender cells was placed in the middle of a "lawn" of receiver cells and exposed to tetracycline, the sender cells emitted AHL, which then diffused as a radial gradient from the colony, resulting in a concentric ring of fluorescence around the sender colony, but not immediately touching it, like a bullseye. That is right by the sender colony, the AHL was highest, and so the high-detection AHL circuit shut off fluorescence and left those cells dark. A little further out, the levels of AHL that diffused from the senders was at a more moderate amount, so the high-detection and the low-detection circuits remained off, allowing those cells to fluoresce. Beyond those cells, the levels of AHL were too low, and though the high-detection circuit remained off, the low-detection circuit turned on and repressed the fluorescence, again.

Colony of sender cells, fluorescing red, placed in a lawn of receiver cells. The sender colonies secrete signaling molecule AHL, which diffuses through the media. Receiver cells a sufficient distance from the colonies will receive enough AHL to fluoresce green, while those too near or too far will receive too much or to little AHL, respectively, remaining dark. [Image obtained from Ron Weiss with permission, modified by CDL to include labels.]

While this makes for pretty pictures, taxpayers rest assured: glowing cells are only the proof of concept. This research has major implications for practical applications, for example, in stem cell research, tissue engineering, and bioengineering.

As a high school student, I felt incredibly excited to learn the answer to the question, "How can a ball of indistinguishable cells turn into a brain, limbs, skin, etc.?" The answer, as those of you with some developmental biology background know, is "Through protein gradients," and more specifically through transcription factors and their co-activators and co-repressors. Beginning with your mother's egg cell, there already existed protein gradients which pre-determined the regions that formed your head, or your feet, or your inner organs, and as your zygotic cells divided, these protein gradients begot even more protein gradients, in a beautiful choreography perfected through billions of years of evolution. This research by Prof. Weiss and his colleagues demonstrates that synthetic biology may provide a means to not only guiding stem cells (either derived from an embryo or returned to their embryo-like stage) through the difficult process of differentiating into other cell types when cued by specific protein concentrations, but also the means to create colonies of cells capable of producing protein gradients. Through a successful combination of these sender-recipient circuits, we could achieve multiple types of differentiated cells, and maybe even self-organizing tissues, all from the same culture of stem cells.

Likewise, this research has important implications in mixed cell cultures. For example, the liver is primarily composed of cells called hepatocytes, which perform most of the functions of the liver, such as detoxification, lipid homeostasis, and blood plasma production. However, by culturing hepatocytes together with another cell type found in the liver, called liver sinusoidal endothelial cells (LSECs), the hepatocytes maintain their "liver-ness" far better than when cultured alone. Weiss's research implies that we may some day be able to develop synthetic "surrogate" cells to support cells that are characteristically difficult to maintain ex vivo by providing important intercellular signals.

In terms of bioengineering applications, such as biodiesel or pharmaceutical production, a major stumbling block has been the difficulty in engineering biological systems with the biochemical capacities necessary to carry out each step necessary to manufacture a complex molecule. Weiss's research suggests growing practicality in molecule manufacturing by designing chains biological pathways that exist in separate organisms, much as the case for deep-sea vents ecosystems.

Two other profound discoveries that Weiss presented were completely counterintuitive to me: adding complexity to a biological circuit tends to 1) bring about more digital (on/off) behavior rather than analog (continuous gradient from low to high) behavior, and that coupling components tends to reduce noisiness in the circuit rather than increase it. Although I do not have time to recapitulate Prof. Weiss's demonstrations of these emergent behaviors, I encourage you to browse through his publications yourself.

The last two points I'd like to note from Prof. Weiss's talk are the following quips, which I found particularly encouraging (paraphrasing). First:

Computational simulation is absolutely central to synthetic biology. We are beyond the point where we can design biological circuits through intuition alone. —Prof. Ron Weiss
This statement makes me feel validated for pursuing a background in computational biology. Second:
We've been working on a project for eight years now that we still haven't published results from. We're very close, though. It will be just another year or so. At least, that's what I tell my graduate student. And the graduate student that takes the project after she graduates. And the one after she graduates. —Prof. Ron Weiss
Researchers with careers as illustrious as Prof. Weiss's can come in and dazzle us grad students with tales of field-changing success, and I think this gives unreasonable and unwarranted expectations of how our own research paths should go. Certainly in my case I've felt that because I've struggled, I must not be successful, because it rarely seems the successful people struggled. It's refreshing to see an admirable figure in his field open up and show vulnerability by admitting that, even to this day, he has his struggles.

To summarize, here are my takeaway thoughts from Prof. Weiss's talk:

  • The time for synthetic biology research is now.
  • Researchers can engineer cell-cell communication, beginning the era of human-designed mixed cell cultures.
  • Even excellent researchers struggle.