Thursday, 25 August 2016

One laboratory, en suite sauna


In lieu of an actual proper scientific blogpost this week, here I recount a recent lab horror story that struck me. With thanks to my labmates sending me the freezer traces:
Sunday evening. Kicking back at home, something vaguely distracting on the telly. Doing the chores, which on this occasion included last minute packing in preparation for storing our belongings before leaving the country. Everything was all on track for a nice quiet and productive night in. Until a phone vibrates.
20:08, G: “Hello team. Freezer temp has alarmed at -59 just now. Anyone using it? Anyone around in lab?”
Hmm that's a bother. Hopefully someone's just pulling a long weekend shift, maybe came in to bank a long point in a time course and was just being a bit slow to close the freezer after. If that's the case then they'll close it and this will blow over. Let's just wait a while and see who's there...anyone?
20:15, D: “The other freezer in that room is reading -62, might just be hot in there”
Oh bugger, now they're both going. Luckily these alerts also go to a lab manager, he's a good guy, always on the ball, he'll sort it.
Except nope, no reply. Wait, is that it levelling out?
Hope indeed!
21:04, G: “sorry to report, there was no plateau - i think we have to do something tonight”
Double bugger, because guess who lives closest?
21:19, me: “I am nearby ”
21:20, me: “If emergency action is called for”
In I go, let's see how bad it is on the ground... And it's sweltering. No AC. No air movement. A small room with six giant -80s, all shrieking in concert if not in sync.
The blue ribbon rises as the sweat rolls down...
Running around, begging security for help, ringing managers, moaning on Whatsapp, come on come on, let's check the thermometer again...
Scorchio.
It would have kept rising except here I propped open the fire door from the freezer room into the neighbouring lab, corridor, and convinced security to come and open the fire door to outside for a moment, giving a few blessed minutes of relief.
It doesn't last. The fire alarm decides to join the chorus, and thus the external door must close.
We need to move this cursed muggy miasma of stale heat, but where to go, and how to get there? Enter our trusty friend, the humble wedge. Let's prop open another door into the lab next door, knocking the smug grin off its air-conditioned face.
The good news starts to filter in.
Down to 39.5ºC on the thermometer; still fit for a steam room, but going in the right direction – we just need to speed this up. Let's go lab rustling!
Now we've got some circulation. It's still hot as heck, like standing in front of a giant hairdrier, but at least it's moving.
And there was much rejoicing
22:58, D: “Second Alert cancelled, you are a hero Jamie”
23:06, T: “Jamie = hero 🏆”
23:08, G: “Good thing he's not leaving for Boston or something...”
23:09, G2: “Brilliant! Thanks Jamie!”
23:09, Me: “Room is 38 now, so I think I can go home”
Lauded in the Whatsapp group, my name will be rejoiced throughout the lab, and I get to go home to continue packing my belongings. All in a day's work, for The Postdoc That Lives Nearest The Lab!

Wednesday, 10 August 2016

Extracting sample names from Illumina FASTQ filenames

Another post in the vein of "minor analysis task and my solution": how to extract the sample name or identifier (i.e. what you called a given file in the samplesheet) from a list of Illumina FASTQ file names.

So you might have something that looks like this (which I've cobbled together from a couple of runs from different machines that I pulled off Basespace):
 
322_S18_R2_001.fastq.gz 
1c8_P6_act_S11_R2_001.fastq.gz
5c4_P8_res_S1_R1_001.fastq.gz


In this exercise, I wanted the first part of the IDs, which are what we labelled the actual samples with. In an ideal world this should be very easy: we could just use sed or cut to delete everything after the first instance of a character used in the text that Illumina appends to the sample name. However different people (or the same people at different times) use different naming conventions, which can often include underscores, the character that separates the string fields that get added.

Therefore what we need to do is not delete from say the first pattern, but from the nth pattern from the end, which turned out to be a slightly trickier problem (at least to one such as myself that doesn't find sed to be the most intuitive program in the world). Here's what I came up with:
sed 's/\(.*\)_\(.*_\)\(.*\)_/\1|\2/;s/|.*//' FilenameList.txt

What this does is find the third underscore to last (just before S[XX]_R[X].fastq.gz string) and replace it with a pipe character ('|'), which should never appear in a filename, before finding this pipe character and deleting everything after it. This produces the following output:
 
322
1c8_P6_act
5c4_P8_res

This feels a bit hacky to me, as really I feel like I should be able to do this in one substitution, but the first part of the command actually selects the latter half (so if anyone knows how to tidy this up I'd love to hear it!).

It's also worth pointing out that the output of different machines or demultiplexing settings will differ in the number of underscores, and so the command will need to change slightly. For instance, the above example was run on NextSeq data demultiplexed using bcl2fastq --no-lane-splitting. For an example of a file containing lane information ('L001' etc), here's the equivalent on some MiSeq filenames I pulled up.
# This 
324bAB_S8_L001_R1_001.fastq.gz 
076-PBMCs-alpha_S5_L001_R1_001.fastq.gz 

# After this
sed 's/\(.*\)_\(.*_\)\(.*\)_\(.*\)_/\1|\2/;s/|.*//' FilenameList.txt   

# Becomes this 
324bAB
076-PBMCs-alpha
The reason I was actually doing this was because I had a number of different NextSeq runs, some of which contained samples sequenced from the same original libraries (to increase the depth), so I needed to get the names of all samples sequenced in each run. I had each run in separate directories, and then ran this in the folder above:
for i in */
do echo $i
ls $i | grep R1 | grep fastq.gz | sed 's/\(.*\)_\(.*_\)\(.*\)_/\1|\
2/;s/|.*//' > ${i%?}.fl
done
This goes through all the directories, finds the R1 FASTQ files (as there are other files in there, and this gives me only one entry per sample) and strips their sample names out as above, and writes these to a textfile with the suffix '.fl'.

Thursday, 4 August 2016

Blog fail, but life successes

While I doubt there are many regular readers of this blog (not least because there isn't a regular output of posts!) I thought I'd make an update here, to explain the sparsity of content and continue the general narrative.

Essentially, I've not written nearly as often or as much here as I might wish. There are a variety of reasons for this, but it basically comes down to the twin demons of being too busy and falling out of the habit.

It's hard for me to feel too bad about it, because it has indeed been a pretty eventful year or two for me. I finished my PhD and went to a couple of very exciting international conferences. I also got out my first crop of PhD papers*, which were slightly longer in the making than I might have wished, and have been working on a number of other papers since with various labmates.

I've also still been doing the odd bit of writing for BioNews every now and then, and responding to lab and scientific questions, problems and discussions on Reddit (which I think makes for a great discussion platform for scientists, given its large user base and easy interface). This often scratches the itch that blogging does but in a more schedule-friendly (and less inspiration-necessary) manner, so I can see why it might be syphoning off some what's left of my writing enthusiasm after working on whatever the current paper is.

But life is more than work, and I have a number of life events this year that have kept the rest of my free time pretty well booked up. In addition to some of the bigger, more time-consuming life events that exist (including the biggest!) I'm also very happy to report that I've accepted an invitation to go Boston for a post-doc, where I'll be exploring TCR sequences in the context of cancer rather then infection. While I am hugely excited for all of these developments, they take time and effort to happen, and so other pursuits (e.g. blogging) can suffer.

Hopefully, once I've got the next big paper finished and have successfully made it to the other side of the pond, I can start getting the ball rolling here again. Little and often is the plan; I've got a few particular posts in mind, but I think things like a TCRseq publication alert roundup might be a nice place to start. So if you do take something from these posts (and I'm very surprised but happy to find that there are people that claim to!) take heart, as more is definitely on the cards.


*An application of the TCRseq tech we'd worked on during my thesis characterising HIV+ patient repertoires and a review of the history DNA sequencing methods.