Wednesday, November 2, 2022

CITYSPORTS E06 Error - fix

I have one of these treadmills. A few times it has stopped with the belt unable to move but with the display still working. The last time it displayed an error message: "E06" which means that the motor is overloaded. The first time this happened I thought I was going to have to replace the treadmill. I took it apart for an inspection and noted that the motor has an access port for the brushes. I cleaned the brush and put it back and the treadmill worked again for about 1 month before the same error was thrown. I ordered some replacement brushes and replaced the worn down one - now everything is working just fine.
In this last picture you can see how worn down the old brush was!

Thursday, March 7, 2019

R: use purrr::map_dfc to update all cells in a data.frame

I've just loaded a large data.frame generated from a set of SDFs from a collaborator. The 'empty' cell value is set as a period ('.') which isn't great for general analysis.

The quick way of converting these to NA is by using the map_dfc function from the purrr package.


# replace all insances of '.' in all columns without changing anything else.
dt <- data.frame(
a=sample(LETTERS, 10),
b=sample(c('.', 1, 2, 3), 10, replace=T),
c=sample(c('.', 'rick', 'morty', 'summer'), 10, replace=T))
# print the data.frame
dt
# use purrr::map_dfc to loop through the columns of the data.frame
dt %>%
purrr::map_dfc(
function(x) str_replace(x, '^\\.$', replacement=NA_character_))
This should output the following (note that all occurrences of '.' have been replaced with NA):
   a b      c
1  T 2  morty
2  D 1 summer
3  P 1   rick
4  O . summer
5  V 3 summer
6  M 3 summer
7  Z .   rick
8  F 2      .
9  J 2   rick
10 E 3   rick

  a     b     c
 1 T     2     morty
 2 D     1     summer
 3 P     1     rick
 4 O     NA    summer
 5 V     3     summer
 6 M     3     summer
 7 Z     NA    rick
 8 F     2     NA
 9 J     2     rick
10 E     3     rick

Tuesday, January 30, 2018

Count SDF entries in a file

This is something I find myself doing a lot, so thought I'd share. There's a quick and easy way to count the number of entries in an SDF when you're on the command line:
grep -c $'$$$$' <filename>
view raw grep_sdf.sh hosted with ❤ by GitHub

Tuesday, September 5, 2017

capture logging info from xargs comand

Here's an example of how to capture STDOUT and STERR from a set of commands parallelized using 'xargs':


# create babel fastsearch indexes and capture the output
find . -name "*20M.smi" -print0 | \
xargs -P 3 -L 1 -0 -I{} sh -c 'babel "$1" -ofs &> "$1.log"' -- {})
Note that I'm using 'find' rather than the output of 'ls' as the input (since 'find' will not return anything if no files are found).  You can define multiple shell arguments in this way and refer to them in the normal manner ("$1", "$2", "$3", etc.).

Tuesday, February 14, 2017

R: find the color name you want

Simple tip for finding the color name you want from the base set.

grep("orange", color())
view raw color_grep.R hosted with ❤ by GitHub


This gives the following output:

[1] "darkorange" "darkorange1" "darkorange2" "darkorange3" "darkorange4" "orange" "orange1"
[8] "orange2" "orange3" "orange4" "orangered" "orangered1" "orangered2" "orangered3"
[15] "orangered4"

Monday, January 23, 2017

Terminate a frozen SSH session

I work remotely via a VPN and am often plagued by frozen SSH sessions (especially if I step away from my desk for any length of time).  I always used to close the shell/terminal - which is a bit annoying.  Then I came across the solution below, just type enter (in the frozen shell) then tilde and period/full-stop and you drop out of the ssh session.

[Enter]
~.

Monday, January 9, 2017

Generating random numbers in bash

I wanted to assign each member of a training set to a cross-validation fold.  I wanted to do this in a bash script and so ended up using something like the following:
#!/bin/bash -eu
n=100
m=5
for i in $(seq 1 $n); do
echo $(( (RANDOM % $m) + 1));
done
view raw gistfile1.txt hosted with ❤ by GitHub

This script generates n numbers selected randomly in the series of integers from 1 to m.  In this case m represents the number of cross validation folds.


You could generate a random CV fold assignment like so:
#!/bin/bash -eu
CV_FOLDS=5
while read mol_name label; do
FOLD=$(( (RANDOM % $CV_FOLDS) + 1));
echo -e "mol_name\tlabel\t$FOLD";
done

Depending on your input file format of course.