A single line of code almost undid our publication
We are currently preparing a manuscript for publication. It's me, a postdoc, and the PI on the project. I generated the last batch of data around a week ago and passed it on for processing and visualization to the postdoc, who had the scripts from the previous projects. The results that came out of that were puzzling.
Let's say we have Figures 1 and 2, the types of which are standard in our field. We know from our previous publications that Figure 2 looking a certain way implies Figure 1 looking a certain way. Instead, we got good results in Figure 2, but Figure 1 looked opposite of what you would expect.
My PI was horrified when he first saw it, on the fence about going ahead with the publication and suggesting I go back to the drawing board. We also tried to come up with alternative explanations, but all of them were unsatisfactory. By that point, I spent more than a month on an otherwise promising approach and, frankly, had no better ideas. Today (yes, we're working Sundays), out of desperation, I decided to dig into the data processing scripts. The key part of the script looked like this:
foo = 0.0
for i in range(0,N):
foo += bar[i]
foo = pesky_function(foo)
pesky_function() is the only modification from the previous projects for the purposes of data processing. And then I realized...pesky_function() should be outside the for loop:
foo = 0.0
for i in range(0,N):
foo += bar[i]
foo = pesky_function(foo)
I immediately grabbed my laptop and ran to the postdoc's office. Told him that I think I found the source of our nightmares. We replotted Figure 1 with the fixed code, and...it looks exactly as you would expect from the previous publications! He shook my hand, emailed to the PI that I found a bug, and tomorrow we'll be rewriting the relevant part of the manuscript. My approach vindicated, publication saved, and overall a huge weight off my shoulders. Phew!