Tag Archives: Mobile Metagenomics

Mobile Metagenomics & Concurrency

Ladies and Gentlemen, we have concurrency! By that, I mean that my test application for MM with Käppler’s interface seems to be working 100% as expected. All that I need to do now is patch the concepts from my proof-of-concept into real MM. I’m going to do my best to get that done between today and tomorrow, and hopefully have a video made by mid-next week.

Things are going to be a little crazy once the semester starts, I’d imagine, but I’m going to try to keep up with MM. I’d like to be able to keep improving on it through the semester, potentially adding things like the Notifications that Daniel found for me. Rob and I have also talked about working up some cool ideas for the hierarchy views, which is particularly exciting!

Stay tuned for a new MM video which should be dropping by the end of next week!

The First Rule of Programming

If I were clever, I’d say that it is “you don’t talk about programming”. Since I’m not clever, I submit that the first rule of programming is “check to see if somebody else already figured it out”. The answer is yes at least 85% of the time, and usually that person did a better job than you would if you’re rushing towards a bigger and better goal. On that note, I found this cool thing today.

I’ve been thinking over approaches for dealing with the issue of MM getting onPause()’d, and have tried my hand at a few snippets of code so far. I still rather like my approach of the downloads happening in a service while the background thread deals with sorting results. I believe that Käppler‘s approach will save me a lot of time on coding my onResume()/onPause() and generally laying out the structure. I haven’t studied his code intesively enough yet, but it already looks much more promising than what I frantically hacked up last week on the subject.

So, next time you’re about to scratch-code something difficult, talk to Uncle Google and see if some helpful person already solved the problem for you! 🙂 …and that is all from me for the week, as I’m going on vacation. Enjoy the silence!


Multitasking MM Update

So far I’ve learned some interesting things about services in Android. I also discovered that the issues with my build path (re: file manager troubles) are, well, known issues. Apparently the Android/Eclipse environment used to handle imports just fine, but nowadays it messes things up a bit when it builds .apk packages for phone deployment. A search on the Android Developers google group for ‘verify error’ turned up a detailed, though difficult for me to understand, explanation of exactly why Eclipse doesn’t build in method dependencies into apks. Either way, I’ve resolved myself to not importing methods – I’ll just cut and paste!

The AIDL tool for creating service interfaces is pretty cool, though a bit confusing to learn. From my current (limited) understanding, you can write Services which use Java primitives (and String… is that a primitive now?!), as well as any classes you write (provided you implement Parcelable!). As far as I’ve been able to discern, already-built classes like Hashtable are not in that list of usable classes. (Unless I change the class to implement parcelable, which I don’t have any real interest in doing…) Look for more on this tool when I have a better grasp of it – perhaps a future N&B article!

In my case, this unfortunately reduces me to the awkward approach of background threading for doing my JSON -> Hashtable conversion, list creation, and list sorting. Meanwhile, all http/cgi queries/uploads/downloads will be done in a background service. This approach isn’t terrible, however, as the difficult part to resume and recover would have been the download. If the background thread is interrupted, I can easily save the data and restart it when the app hits onResume(); Generally the time window on interrupting the sorting/list creation is a few seconds at most, so this will rarely come up.

The other issue I’ve been struggling with today is that for some reason my download buffer is coming up as expecting 0 bytes to download when I run it from the service. Ugh, and that took me 1+ hours to track down even with the awesome Eclipse debugger. I had sort of hacked it into the service when I finally got my initial test running, so I went back and reconstructed everything from the pure MM classes (which still work). I now have a sort of pseudo-MM set up inside of my service test app, which I’ll get to test first thing tomorrow!

Edit, 8/18/09, Morning: It helps when you give your program good values to run tests on… (peek behind the read more)

Continue reading

Multitasking Mobile Metagenomics

Triple M?! You betcha! Up until about five minutes ago, I was under the impression that when somebody navigated away from Mobile Metagenomics, I had to drop everything. I envisioned stopping my download thread, saving current results, saving iteration values, saving a mode variable, and whatever else was necessary to later restart whatever MM was doing. I even wrote pseudocode for it yesterday, and spent the first half of today implementing it.

I’m glad I decided to take a short break and read about Android stuff, because as it turns out I was flat out wrong about onStop(). Apparently, I can actually let my worker thread busily download new chunks of data into MM while a user is checking their email, making phone calls, IMing their friends about how cool Edwardslab is… And if the phone needs additional memory and has to kill the MM process, I believe I can actually store & create aforementioned variables at that point. Which is cool not only because we get to save our progress, but also because I don’t have to crumple up two pages of pseudocode Laughing

I was starting to feel like MM might be getting close to finished (unless Rob and I do some kind of cool file browser-esque navigation of results, in which case I’ll probably have to spend a week just learning the Biology), but now I have a new thing for my brain to chew on for a bit. I feel like doing the annotation downloads as a background process adds quite a bit of value to MM as an application. The user may choose to view the results as they happen (which is the original intent of Real-Time Metagenomics to begin with), but they will no longer be locked into MM. Even as a developer I hate the notion of “okay I started MM, now lets have it sit there for 3 minutes”, so I can only imagine how much users would’ve disliked that.

As far as progress since my last post about what I’m actually working on, I’ve got a fair amount of error detection/recovery implemented in both Genome Search and Mobile Metagenomics. I’m not going to say that I can detect and recover from everything (because I’m sure we’ll find some obscure way to break the app), but it is looking pretty solid from my tests. Through normal use, it shouldn’t do anything weird anymore. Note that ‘normal use’ still confines us to being locked inside of MM unless we want to lose all progress. That is, until I get this next part figured out!

Adding Error Recovery to GS / MM

One of the tasks that I’ve been meaning to work on for some time is doing some actual error recovery for MM. I realized however, that not only is this a pretty big problem to get a hold of, I also never did it for GenomeSearch. Since we want to put both on the market someday anyhow, I figured I may as well start with the more simple app and get some practice.

I took Daniel’s network status checking snippet, stripped out the textview stuff specific to his test app, and turned it into a small boolean method for GS to query. Now, when the app launches, it checks for network availability before it tries to fill up the list of Genomes. If it should fail, I have an alert dialog method which either recurses on itself until the network is available, or closes the program. The user is able to click ‘Retry’ or ‘Quit’ to achieve either option. In the future I may want to add an arbitrary delay between re-tries, or we may choose to just leave it with no delay.

I also put into place a little bit of code to let the user know if something goes wrong anywhere along the GenomeSearch process. This part isn’t quite done yet; I had most of the code in place last week, but due to some complexities I didn’t anticipate I had to not use any of the cool Toast error pop-ups. (Specifically, the methods I put the Toasts into are called from both the UI thread and a worker thread. The worker thread isn’t allowed to perform the toast pop-ups, and I had forgotten that we were using a worker thread in GS, so I have to work around this a bit.)

I have the solution to the Toast issue about 75% in-place, but I need to do a couple more things and then test it before I call it good to go and move on to MM. I had honestly been dreading the error recovery stuff, but once I traced through GS, it was actually very easy. Not only that, but I made some passing improvements to the code as I went along! MM is a bit more work to trace, but I already did a preliminary run-through, so I should be able to tackle this in the coming week 🙂


MM Gets Major Upgrade Thanks to OpenIntents!

Before I show you cool things, you’re probably wondering “what the heck is OpenIntents, Josh?” Well, OpenIntents is a pile of awesome pieces of code that work independently as useful software, but are also a great resource to tap for other projects. In my case, Mobile Metagenomics has been sitting around with a broken “Browse” button since the first day I made the layout. I knew that there were a handful of open source file browsers out there that I could use, but none of them seemed to work for me.

Today I tried pulling down the OpenIntents source directly from their svn repository, and it fixed all of my issues! The final result? When you click browse, this happens:


Thanks, OpenIntents!

MM Update – Share Button Options

I recently tested the code for the share options on my Ion and I’m proud to say they work perfectly! Well, with the exception of the browse button not working yet… (that is next on my list!). Now, users are able to press the share button, and choose an output format: .mmr for sending results to other phones, or .txt for sending results to computers. The text version has been tested in Windows, Linux, and Mac environments and is viewable in all three. One application that has problems with the output is Notepad in Windows; the WordPad application works fine, and is an acceptable alternative.

Another thing I’m happy to have done is the registration for the Android Market. In the future I’ll be able to upload our lab applications to the market where they will be available as free downloads to anyone with an Android phone. It was a pretty simple process to go through, and would’ve been really quick, but I decided it was probably a good idea to actually read the license agreement… Either way, I am now set up to upload our apps! Big thanks to Rob for paying my Market fees! (I’ll be sure to remember you when I make my imaginary millions on MtgHelper…)

I’ll have to talk it over with Rob, but I think there are only a few adjustments I’d like to make before releasing initial versions of GenomeSearch and Mobile Metagenomics. Both applications currently have no provision for warning the user of poor/no internet connection – this results in application failure and is unnacceptable for Market-deployed apps. The other issue is that MM needs to have the browse button coded, which requires me to either code a file browser by hand or somehow incorporate one which has been written by others. Once I complete these features, we can consider deploying the apps on the Market.

MM Preview Release

I’ve created a preview release of MM in case Rob or anyone else needs/wants to show off the app to anyone. You can download it via directly typing in the download link, by doing an “adb install mobilemetagenomics.apk” if you have the sdk set up on your PC, or you can just use the Barcode Scanner app to scan and download directly from the QR-code behind the read-more cut. As I stated, this is a preview version of the code so many things are incomplete. I’ll try to update the .apk when I make signifcant changes, so check back for the latest version!

NOTE: Daniel just pointed out to me that you need to have a fasta file in the root directory of your SD Card for MM to actually do anything. You can transfer the file most easily by connecting your phone to a computer via USB, mounting the phone as a removable storage device, and then clicking and dragging the file from your PC to your phone. I’m unsure of where files are placed when a phone directly downloads a file, so the safest bet is to use the USB method.

Update (7/24/09): As far as I’m able to test (bioseed went down just before I could try it on a real phone), I have the dialog and the .txt and .mmr outputs both working! I’m pretty excited to finally have this section of the app coded; I actually agonized over the newlines for quite a while before realizing it was just Notepad displaying my results wrong… The .txt outputs display just fine in Wordpad and should also work for Mac and Linux (though linux may have those pesky ^M characters after each line). Unfortunately the java environment variables don’t help us in Android to determine what type of newlines the user will want when they email their file. I had to write the code with /r/n both in, because the file could be emailed to any operating system.

Continue reading

More cool MM

Today I completed my trio of menu buttons for MM! That’s right folks, we have a Share Button!

If you can’t tell, I’m pretty excited about that. Not only because it took half a workday to do, but also because (in my opinion) it is a really cool feature. One of the things that most impressed me about my Ion when I first got it was that when browsing my pictures, there was a button with a pop up that asked what I wanted to do with it. In terms of MM, about the only reasonable thing I can think of to do with a .MMR output is to email it. So for now, that is what our share button does.

Another issue is that, as of right now, a .MMR is just a Serializable Array recorded to a file. It isn’t exactly very reader-friendly. This works fine if all we want to do is shoot a file across email to another android phone for viewing in their MM app, but we may want to look into more options in the future. The notion of sending an MMR across bluetooth to another phone is also interesting, but that would require a fair bit of digging to accomplish (and may not even be allowed, I’m not sure). Either way, I’m very happy to have accomplished the rough outline of what we want our menu buttons to do. At this point, adding more functionality will be pretty easy to do. Now if I could just add those nifty icons to my buttons…


Unfortunately I didn’t make it into the lab today to pick up my progress bar code, so that will have to wait until Monday, but I did make a lot of progress on MM! I coded a third Activity – this one is a pop-up dialog to ask the user what file they want to load. It gets displayed when they choose “load file” from the options menu. To go along with this, I coded full functionality for saving and loading files! I actually coded it twice, the first time it saved it to the phone’s storage, which I didn’t like. The new and final version saves files to the SDCard. I may add functionality to the save feature to name files whatever the user wants, but for now everything is saved as “filename.fa.mmr” MMR stands for Mobile Metagenomics Results filetype (which is actually just a serializable array dumped to a file).

And now my challenge to the lab! MM needs a cool icon for display on the Android phone. Right now it has the generic application window with a gear in front of it, and that is not only boring, but unprofessional. I’m absolute rubbish at art (digital or otherwise), so if somebody in the lab has a knack for it, feel free to make up a 48×48 PNG file for us! You can go with Rob’s tricorder theme, or any other idea you may have that applies. Translucent backgrounds work great as the phone will show the background theme through such a background (yes, I made some very crude artwork to test how this process works). If nobody in the lab feels up to the challenge, I’ll have to create a flat, pixelated masterpiece myself… (you’ve been warned!)