Craic Computing Tech Tips

A collection of computer systems and programming tips that you may find useful.
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Thursday, April 25, 2019

Ruby serializable_hash removes ruby/object from YAML output

I use YAML as a convenient way to serialize data in a number of projects, most of which are written in Ruby and Rails

You generate the YAML representation with the .to_yaml method - really simple.

p = Paper.find(359)
puts p.to_yaml

But if the input is a ruby or rails object the output is prefixed with !ruby/object and that causes problems when you try and load that document in another script that does not know about this object

For example - here is an example of a Paper object from a Rails application.

--- !ruby/object:Paper
  id: 359
  pmid: 7945531
  title: 'Pharmacokinetics of a new human monoclonal antibody against cytomegalovirus.
    Third communication: correspondence of the idiotype activity and virus neutralization
    activity of the new monoclonal antibody, regavirumab in rat serum and its pharmacokinetics'

If I try and read this file in a separate script I get this error because that script has no concept of a Paper object.

y = YAML.load_file('test.yml')
ArgumentError: undefined class/module Paper
from /Users/jones/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/psych-2.0.5/lib/psych/class_loader.rb:53:in `path2class'
from /Users/jones/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/psych-2.0.5/lib/psych/class_loader.rb:53:in `resolve'
from /Users/jones/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/psych-2.0.5/lib/psych/class_loader.rb:45:in `find'

The way to strip off the ruby/object 'header' is to use serializable_hash before to_yaml.

abstract: TI-23 consists of lyophilized regavirumab (monoclonal antibody C23, MCA
id: 359
pmid: 7945531
publication_date: 1994-07-01
title: 'Pharmacokinetics of a new human monoclonal antibody against cytomegalovirus.
  Third communication: correspondence of the idiotype activity and virus neutralization
  activity of the new monoclonal antibody, regavirumab in rat serum and its pharmacokinetics'

It looks like the keys in the yaml block are output in alphabetical order.

It's a simple fix but I had to hunt around to find it.

Thursday, March 14, 2019

Using Google BERT to Classify Biomedical Papers

I have been using Google's BERT language representation model to help classify a certain type of biomedical paper based on abstracts in the PubMed database.

The scripts that I use for data preparation and a detailed walk through of the process are written up in a new GitHub repository that I have created.

My work was based on a blog post by Javed Qadrud-Din that I found extremely helpful.

With my dataset I am getting around 91% accuracy - which is much better than my earlier experiments with LSTM, CNN, etc approaches.

Tuesday, November 13, 2018

Sharing a folder on a Synology NAS with MacOS and Ubuntu linux using CIFS / SMB

I have a Synology DS418 Network Attached Storage (NAS) system.

I wanted to create a Shared Folder on the NAS that I could access from Mac OS (Mojave 10.14) and a Linux box running Ubuntu 16.04.

MacOS uses SMB to share folders and so I decided to use that on the Linux box.

There are 3 parts to this process:

#1 Set up the folder on the NAS.

In Synology File Station, create the folder (SMBtest is the name used here). Under the Permissions Tab I gave my user (jones) full control by selecting 'Administration' and 'Change Permissions' and 'Take Ownership'

I think that is all that is needed on the NAS.

#2 on the Mac

Under the Finder -> 'Go' -> 'Connect to Server'
In my case the address to use was 'smb://craic-nas-1'
Connect as Registered User on the NAS and then select the volume 'SMBtest'

I then had access to that volume in the Finder or at /Volumes/SMBtest on the command line

#3 on the Linux box

Ubuntu Linux uses the CIFS "common internet file system" protocol to communicate with SMB servers.

I had to install the CIFS software

sudo apt-get install cifs-utils

and I created a credentials file with my NAS username and password.

emacs ~/.smbcredentials


chmod 600 ~/.smbcredentials

I created a mount point on the Linux box and made myself the owner

mkdir /mnt/
mkdir /mnt/jones
sudo chown jones.jones /mnt/jones

To mount that shared folder

sudo mount -t cifs -o credentials=~/.smbcredentials,uid=1000,gid=1000,iocharset=utf8 //craic-nas-1/SMBtest /mnt/jones/SMBtest

My UID on the linux box is 1000 - the uid and gid options means that the mounted directory is owned by me on the linux box - otherwise there are all sorts of permission issues.

The iocharset=utf8 is important. Without it, if I edited a file on Linux then there would be strange characters when I looked at it on the Mac side.

With that mount command I can create, edit and run scripts on either MacOS or Linux

To unmount the share

sudo umount /mnt/jones/SMBtest

To mount the share automatically I added this to /etc/fstab

//craic-nas-1/SMBtest /mnt/jones/SMBtest cifs credentials=/home/jones/.smbcredentials,uid=1000,iocharset=utf8 0 0

To test that works

sudo mount -a

Wednesday, January 3, 2018

Audio Cover on Gigabyte Aorus Z370 Gaming 7 Motherboard Blocks PCIEX16 Slot

I've just finished building a machine learning Linux machine based on the Gigabyte Aorus Z370 Gaming 7 Motherboard and a Gigabyte Aorus Geforce GTX 1080 Ti graphics card.

Most high end motherboards these days are aimed at gamers and so they include all sorts of RGB Led lights and assorted bling so that the users can install them in cases with a clear side. I don't care about all that.

The problem with this motherboard and card combination is that, as part of the bling, they have covered part of the board with a piece of plastic, marked as 'AMP-UP AUDIO', which has no actual function... and one end of that lies in front of the PCIEX16 slot where the graphics card needs to sit (see the arrow).

Here is the tab on the graphics card that is blocked. I don't know if other cards have this tab.

So with the plastic in place, you can't seat the card... and both components are from the same manufacturer... sigh

Fortunately, because the cover has no function whatsoever, you can just remove it and solve the problem. Flip over the motherboard and remove these two small screws. Throw the nasty piece of plastic in the recycling. Job done...

Thursday, September 29, 2016

pi_power - power management for portable Raspberry Pi projects

I have been working on a portable Raspberry Pi project for a while - still not there yet but I've completed one important piece.

It's portable so it obviously has a battery. The Pi takes quite a bit of power so it needed to be rechargeable and include a charger. Adafruit make a great device called the PowerBoost 1000C which takes care of the core charging and power supply functions. But I really wanted my project to work like my phone does:

  • To power it up from a cold state, press a button for a few seconds
  • To power it off, press the same button for a few seconds
  • Indicate how much power remains in the battery
  • Provide an alert when that is running really low
  • Shut down safely without any data corruption if the battery does run out
  • To recharge the battery, just plug in a cable from a USB charger

  • I couldn't find anything that provided all the functionality I wanted - so I built my own

    pi_power consists of fairly straightforward circuitry that links the PowerBoost to the Pi in conjunction with two python scripts that run in the background and monitor the battery voltage.

    If you are building a portable RasPi project then you might want to take a look

    Wednesday, June 8, 2016

    Image capture software for cheap USB microscopes

    Look on Amazon and you will find a variety of cheap USB microscopes. These are basically a USB video camera with a macro lens. They are good for inspecting fine details of things like electronic components, plants, insects, stamps, etc. but they are not powerful enough for looking at, say, cells in biological samples.

    I just bought one to help me capture images of various plant pathologies.

    They are marketed as having a range of magnification from, for example, 20 to 300X and the cameras have resolutions anywhere from 0.3 to 5 M pixels. Be aware that the specified magnification range may include the magnification inherent in displaying the image on a large monitor !

    Dino-Lite make a range of professional USB microscopes of various sorts but these can cost hundreds of dollars. For basic experimentation there are a load of other vendors and products with prices in the $50 - $100 range.

    If you look on Amazon it will be obvious that the same basic models are being sold be several different vendors.

    Here is the one that I bought for $60 which is branded  DBPOWER

    The same microscope with the same stand is also branded as :

    Celestron 5 MP Handheld Digital Microscope Pro  $83

    And with a different stand, or without a stand, by a wide variety of other vendors

    I went with the $60 DBPOWER variant with a 5 MP camera. It comes with the stand in two pieces and a CD containing software called MicroCapturePro for PC and Mac.

    You need software to interact with it - it does not just show up as a camera in the MacOS ImageCapture or Preview tools.

    I don't have a CD drive on the machine I want to use this with and transferring the software from one that does is a bit of a pain. So I looked online for the software.

    You can get MicroCapturePro from Celestron but after digging around a bit I would recommend a different solution.

    Plugable have a similar microscope and they provide a piece of software called Digital Viewer - get that and install it on your Mac (they have a Windows version too). When I started it up it displayed the view from my webcam but click the Settings icon in the top left and select the microscope.

    The focussing mechanism on these microscopes is a bit rough but you'll get used to it. I can see that I may want to build myself a better stand and illumination rig.

    Under Settings you can select the image resolution and do a bit of image adjustment. You can take individual images, videos or a set of timed images.

    It looks like it will do exactly what I need it to do - for $60 that's not bad.

    Here is an example image:

    Thursday, January 28, 2016

    Raspberry Pi - strange icon in top right of screen

    I have been working with a mobile Raspberry Pi project powered by a LiPo battery and a Powerboost 1000c charger from Adafruit to handle battery charging.

    Several times I have seen a small square icon in the top right of the attached small HDMI screen that has a rainbow of colors. I had absolutely no idea where this came from or what it represented.

    But now I do...

    The B+ (and presumably later models) has an under-voltage trigger that shows itself as this 'rainbow' square in the top right of the display when the supply voltage drops below 4.65V.

    In addition, an over-temperature trigger displays a solid red square in the same location if the temperature goes above 85deg C.

    You can disable the warnings in config.txt - see the link for details

    I'm glad that the system has these triggers but I don't think the display of a red/rainbow square is a good way to inform the user.

    Archive of Tips