Monday, November 18, 2013

How to print a large image on multiple pages, using Python!

I recently received a high-resolution image of a famous historical figure (details to come soon...). Naturally, my roommates and I wanted to print this famous person out and create a life-size cardboard cutout. Since I only have the capability to print on standard 8.5 x 11 inch paper, I needed a way to split the image onto multiple pages to print.

I found web-based tools that can do this, or you could use Photoshop or some other proprietary software, but I didn't find any good tools I could use on Ubuntu to maintain resolution. I whipped up a Python script that can do this, relying on the Pillow implementation of PIL (Python Image Library). You can download it from Github. Feel free to submit pull requests if you flesh it out further, as it is rather basic right now (it's licensed under GPLv3).

https://github.com/kylebarlow/image-splitter

Tuesday, May 21, 2013

Installing Ubuntu 13.04 Raring Ringtail on a MacBook Pro for Dual Booting

I recently installed Ubuntu onto my MacBook alongside OSX for dual booting, and learned a few lessons throughout the process. Below are the steps that I took. I have a MacBookPro 8,1 but these instructions might be applicable to other models as well. Be sure to also read the "official" Ubuntu installation guide. I also found a post by James Jesudason to be helpful.

These instructions are fairly sparse, but should help point you in the right direction if you are less experienced with any of the steps.

  1. Reduce partition size in the OSX "disk utility" tool. I dragged the partition size until I had enough free space left on the disk for my Ubuntu partition (I wanted 50gb but less should be ok). This took several hours.
  2. Install the rEFInd boot manager. I downloaded the most recent binary file (0.6.11) and ran install.sh, which worked without any other options. rEFInd was installed into the /EFI on my root filesystem.
  3. Install the ext4 driver in rEFInd. The driver is packaged with the binaries, but must be copied into /EFI/refind/drivers in order to be active. I had to create the drivers directory in /EFI with "sudo mkdir /EFI/refind/drivers" as it did not already exist. I then copied (as root) "ext4_x64.efi" from refind-bin-0.6.11/refind/drivers_x64 into the newly created drivers directory.
  4. Load the Ubuntu installer CD (must be the special Mac version of Ubuntu - labeled on that page as "64-bit Mac (AMD64) desktop image"). Instead of choosing to install Ubuntu, choose to try it out instead. Open up a terminal and run "ubiquity -b" and then proceed with the installation. Running with the -b flag tells Ubuntu not to install a bootloader, which won't be necessary as rEFInd can boot a kernel directly. During the install process, the default option should be to install in the disk free space, but you should verify this. I chose to manually create an ext4 partition for my root mount point and a 2gb swap partition instead of using the automatic option.
  5. After the installation finishes, select the option to continue to try Ubuntu. In the terminal, run something like "sudo blkid /dev/sda*". Look for the UUID corresponding to your Ubuntu root mount point.
  6. With Ubuntu still loaded off the LiveCD, find the /boot partition in your new install. This should probably be mounted somewhere in /media. In /media/.../boot, create a file called refind_linux.conf. Save the below options (from the rEFInd documentation), replacing the UUID with the one you noted in the last step corresponding to your Ubuntu install, into this file
    "Boot with standard options" "root=/dev/sda3 ro quiet splash vt.handoff=7"
    "Boot to single-user mode"   "root=UUID=1cd95082-bce0-494c-a290-d2e642dd82b7 ro single"
    "Boot with minimal options"  "root=UUID=1cd95082-bce0-494c-a290-d2e642dd82b7 ro" 
  7. When you restart, Ubuntu should automatically be detected and available to use in the rEFInd boot menu. You can make it the default boot option by setting default_selection in /EFI/refind/refind.conf accordingly
I modified these steps slightly from the ones that I took, so please let me know in the comments if you run into any problems. Hope this helps!

Tuesday, March 19, 2013

March madness python bracket generator

I created a simple python script to read in Nate Silver's march madness predictions and generate random brackets based on his given probabilities. This will give a diverse, non-deterministic, set of potential brackets as results. You can also run the simulation until you get a desired champion.

If you are interested in the script, it is available on GitHub.

Go bears...hopefully

Tuesday, April 24, 2012

Of mice and men: an Alzheimer’s cure for our murine brethren

ResearchBlogging.org

Alzheimer's Disease

Alzheimer's disease is the most common form of dementia, and is predicted to affect 1 in 85 people by the year 2050. And unlike stroke, prostate cancer, heart disease, and HIV, diseases in which we have made progress in treating, Alzheimer's disease has been increasing in prevalence as a cause of death. While this is probably partly due to the fact that we have been living longer and Alzheimer's is typically (but not always) a disease of the elderly, there is no denying that Alzheimer's is a disease in need of attention.

There are a few existing Alzheimer's treatments that can provide mild relief of symptoms, but none halt or even slow disease progression. Why have we not been able to come up with an effective treatment for this increasingly common disease? Here's one reason - we're not even sure what causes the disease!

A prime suspect in the disease are amyloid-beta proteins. These proteins may have accomplices that also cause Alzheimer's, but amyloid-beta proteins play a definite, if not starring role. Amyloid-beta proteins are misfolded chunks of another protein, creatively named APP for amyloid precursor protein. I use the word "chunks" because the bits of the protein that misfold and form aggregates are made up of pieces of a larger protein that gets cut up by enzymes, as shown below.

Wikipedia
What does the full-lenth amyloid precursor do as it's chilling outside the cell, all floppy and blue? (Note: proteins are not actually blue and cartoony as shown in the above figure. They are very tiny.) We don't even know that! We do know that when amyloid-beta begins to misfold, it aggregates with other proteins and that these aggregates probably cause neuron damage. Other neurodegenerative diseases such as Creutzfeldt-Jakob disease or Parkinson's are also linked to these aggregates of misfolded proteins, generally called amyloids.

Get out your tarp, because this might blow your mind: what we call protein "misfolding" in Alzheimer's and other diseases may actually be related to the normal activity of these proteins! What else besides protein misfolding and neurodegneration ties together Alzheimer's, CJD, and Parkinson's? We don't know what any of the precursor proteins in those diseases as their normal functions. It COULD (big emphasis on the could) be possible that some of these proteins are meant to be sometimes be folded in the amyloid state, and that these neurodegenerative diseases are caused by an upset in the natural equilibrium of "normally folded" and "misfolded" amyloid states. I plan to blog more on protein folding and amyloids but here's a teaser for another paper I will cover - amyloid proteins may help explain how memory works.

Now that I have not-definitively-at-all covered the background of Alzheimer's, let's get to the paper I want to talk about today. This paper, "ApoE-Directed Therapeutics Rapidly Clear Β-Amyloid and Reverse Deficits in AD Mouse Models," was published in March as a ScienceExpress article. This means that the editors of the journal Science thought it was important enough to rush out and publish online. Added bonus for overworked grad students like myself - ScienceExpress papers are short!

Punchline

The authors of this paper do something kind of amazing - they find a drug, bexarotene, that they can give to mice with Alzheimer's and almost immediately clear out the deposits of aggregated amyloid-beta protein that build up in the brains of people and mice with Alzheimer's. Even better - this drug is already FDA approved for the treatment of cancer. And as chemotherapy drugs go, its side-effects aren't that bad, so we know we can give it to humans relatively safely.

How amazing is this drug? The authors take images of brain slices from mice pre and post treatment. Aggregates of amyloid-beta can be visualized and counted by adding a florescent antibody. After only three days, the amount of aggregated protein in both the cortex and hippocampus of affected mice has decreased by nearly half, and the decrease continues for several weeks. This is great!

The authors also show that not only do the plaques that may cause the disease dissipate, the mice also experience restored memory and cognition, which would be an amazing result if it holds in humans. In mice, building nests is a social behavior that healthy mice can perform but that Alzheimer's-affected mice cannot. After treatment with bexarotene, nest-making ability in diseased mice was restored. Bexarotene treatment also restores the sense of smell in Alzheimer's mice, another great sign because humans with Alzheimer's also experience loss of smell.

How does the drug work? There is a protein called apoE naturally expressed in your neurons. This protein gets secreted out, attaches itself to amyloid-beta aggregates, and helps break down these aggregates. apoE encourages microglia, helper cells in your brain, to eat up through phagocytosis amyloid-beta aggregates and then to break down the aggregates. Everyone's brain, even in people with Alzheimer's, already makes apoE and breaks down amyloid-beta aggregates. Alzheimer's could be caused by an inability to break down amyloid-beta fast enough (like healthy people do), so making more apoE could reverse the disease.

So we have a cure for Alzheimer's right?

Right! ... for mice. Anyone who's ever read about an amazing cure for a disease found in mice already knows that this cure is not likely to work in humans. Although mice have versions of 99% of the proteins we have, we also share a majority of our genome with plants. And as much as I try, laying in the sun does not make me full, just sleepy and full of vitamin D, so simply sharing similar genes does not make me the same as a mouse or plant. It's particularly tricky to translate a therapy for a neurodegenerative disease from mice to humans, since we think so differently than they do, at least based on my conversations with mice.

A further complication are the mice we perform Alzheimer's research on. In order to do this research, scientists had to create mice that could serve as models for the human disease. This was done by inserting in human genes that cause Alzheimer's, creating an imperfect model. Mice models of disease do not show all of the symptoms that humans with Alzheimer's do and may in fact be better models for early stages of disease progression than late. If so, bexarotene may be able to be used as a preventative therapy, but not as a cure.

Even with these grains of salt in mind, I still found this paper very exciting. I look forward to seeing what the results of ongoing clinical trials of bexarotene as an Alzheimer's therapy in humans will be. With a little luck, this drug can succeed where so many other promising drugs in mice have failed and become a useful therapy in humans.  If a loved one of mine had Alzheimer's, I would be watching the clinical trial results very closely.

Reference:

Cramer, P., Cirrito, J., Wesson, D., Lee, C., Karlo, J., Zinn, A., Casali, B., Restivo, J., Goebel, W., James, M., Brunden, K., Wilson, D., & Landreth, G. (2012). ApoE-Directed Therapeutics Rapidly Clear  -Amyloid and Reverse Deficits in AD Mouse Models Science, 335 (6075), 1503-1506 DOI: 10.1126/science.1217697


Sunday, April 22, 2012

Dearth and taxes


Although I am quite fortunate to receive a stipend to help me get through graduate school, I wouldn’t exactly call my lifestyle luxurious. I consider rice and beans to be an easy, cheap, nutritious meal, but for some reason my non-grad student friends (let’s call them "real adults") think that it is strange for me to want to eat this dish continuously. Shouldn’t we all be restricting our meat intake, anyways?


A further financial complication arises from the fact that Uncle Sam feels that we grad students are responsible enough to manage our finances and pay our taxes without any help from him in the form of withholdings. This makes sense, because the tax code is not difficult at all to understand and we all have lots of free time to figure it out – NOT. Unfortunately, my school does not seem to provide much in the way of resources to help us decipher our fiduciary obligations.


In an effort to help future generations of grad students figure out their tax situation, below is some of the meager knowledge I have gained by searching through the intertubes and reading IRS pdfs. Note: I am not a "professional" in any sense of the term, so the usual legal disclaimer applies that you should not consider this to be tax advice; it is general information only. Also note that my first year funding comes from a NIH training grant. Different funding sources may result in different tax scenarios.

  • Grad students receiving scholarship money are not "self-employed" and do not need to pay the higher self-employment tax rate, even though there is at least one example of the IRS auditing a grad student and trying to get them to do so. This means that I am not currently contributing to social security or medicare and am just paying income taxes, which sucks because I think those programs are important.
  • "Taxable income" for me is the difference between box 5 and box 1 on my 1098-T tuition statement form. This is higher than my stipend because it includes money which pays for my health insurance, which should also be taxed. 1098-T forms can be viewed online at https://www.1098t.com
  • Scholarship income is not "earned income" and thus I cannot make any IRA contributions using my stipend.  See this forum thread and IRS publication 590 for details. The bottom-line from Pub 590: "Scholarship and fellowship payments are compensation for IRA purposes only if shown in box 1 of Form W-2"
  • Since there is no witholding from my stipend, I must make estimated tax payments quarterly, both to the IRS and to California's Franchise Tax Board.
Creative Commons License
Except where otherwise noted, content on What's Life by Kyle Barlow is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.