App to convert raw data to 23andMe format

        App to convert raw data to 23andMe format

On the internet I found other apps that claim to convert Ancestry raw data to
23andMe format, but the ones I found have flaws.  Among others, none of them
handled the PAR1 and PAR2 regions of the X and Y chromosomes correctly. 
Depending on what SNPs one counts as being in PAR1 and PAR2, most of them
are heterozygotic or homozygotic.   In the app I wrote, I used the limits that

23andMe uses to define the heterozygotic or homozygotic ranges.

Here's how to use the app I wrote:

1. Download the "Ancestry to 23andMe.exe.jpg" file.
    Here's a link to it:

2. Remove the extension, ".jpg", so that just Ancestry to 23andMe.exe is left,
    and put the Ancestry to 23andMe.exe file into a folder.  (Keep&Share doesn't
    like files that end in ".exe".)

 3. Copy your AncestryDNA.txt file into the same folder.  Make sure it is called

4. Double click on the Ancestry to 23andMe.exe file to run the program.
    The program creates a file named "23andMe format file.txt" in the
    same folder.

 5. Done!

Landline phone conversation recorder for Windows 10

Phone Recorder is an application for Windows 10
that allows you to join and record an ongoing telephone
conversation.  It runs under either 64-bit or 32-bit Windows.  
Phone Recorder doesn't have much of a user interface — just
two buttons: "Start recording/Stop recording" and "Exit".  
When you click on "Start recording", Phone Recorder will join
an ongoing phone conversation on the same line as that of the
modem, and the button label will change to "Stop recording".  
The conversation is stored as a .wav file in the same folder
as the Phone Recorder executable (.exe) file.  To run Phone
Recorder, you need to have a dial-up modem that has voice
capability installed on your computer.  Phone Recorder uses
only the voice feature of the modem — there's no need to
"dial-up" anywhere.  Be sure to tell the other party or
parties on the line that you are recording the conversation
if it is legally required to do so.

Here's a link to the Phone Recorder app kit:

Easy to Build 40 Hz Gamma Wave Flashing LED Lamp

According to an article in the December 8, 2016 issue of the journal Nature, an
LED light that flashes at 40 Hz, which is the frequency of Gamma wave in the
brain, may alleviate the symptoms of Alzheimer's disease. Also, a 40 Hz
flashing LED light is said to be an aid to meditation.

In the link below, I describe an easy way to build a 40 Hz flashing LED floor
lamp. About all you need to know is a little bit about electricity that you probably
learned as a kid, and a little bit about household wiring, such as how to replace
an electrical outlet in the wall of your home.  Here's tke link:

Linear Regression: Least Squares Fit of a Straight Line to a Set of Points. Includes a Proof that the Total Variance can be Divided into Component Parts, and also Includes a Derivation of the Correlation Coefficient, Explaining its Meaning

We want to fit a straight line of the form:

(Eq. 1) or, alternatively,

(Eq. 2) to a set of data points.

Using the least squares method, we want to minimize the function:

(Eq. 3).

Taking partial derivatives and setting them to zero, we get:

(Eq. 4).

(Eq. 5).

Solving these equations, we get:

(Eq. 6), and

(Eq. 7),

or, (Eq. 8). 

In the following, we will assume that the number of points, n, in our data set is
quite large, say, >= 100. 
So to calculate variances we will simply divide sums
by n (rather than n-1 or n-2 to take into account degrees of freedom). 
Consequently, the variances we will calculate are only close approximations.

Using the values of a and b that we calculated above to minimize the F function,
we have:

(Eq. 9),

where is the part of the total variance, that is left unexplained by the regression. 

The other part of the total variance is variance explained by the regression,
The explained and unexplained variances should add up to the total variance, i.e., that

(Eq. 10), and we will now prove that. 

Equation 10 can also be written as:


We start the proof with:


Squaring both sides and summing, we get:


So the theorem is true if: 

Or equivalently if:

(Eq. 11).

            (A)                       (B)

From Equation 4, since we are using the optimum values for a and b, we know that:

, and, substituting for , that means that

is zero. So (B) above is true. 
From equation 5, we know that . Substituting , we get:

Simplifying, we get: ,



. Since (B) , above, is zero, that means that (D) is zero,

           (C)                            (D)


which in turn means that (C) is zero. And (C) is the same as (A), so (A) is zero. 
Then, because (A) and (B) are both zero, equation 11 is zero. This proves
equation 10, that:

, i.e., that the total variance can be separated into two
non-overlapping components, the variance explained and the variance
unexplained by the regression, that added together are equal to the total variance.

Now we will look at the relationship between the total variance and the unexplained variance and define a correlation coefficient, r.

Squaring equation 1, , we get: .

Summing over n yields: , which means that


Substituting for in Equation 10, we have

, or

A standard equation for the variance of a sample is:

And since, from equation 6,
, then


, or

The rightmost term on the right hand side of this equation is the square of the correlation coefficient, r.

So, (Eq. 12). 

From equation 10, we know that , or .

Substituting into equation 12, . 


In words, is the ratio of the variance explained by the regression of Y on X to the total variance. This, in my opinion provides a better definition of the correlation coefficient than its usual definition as .



Cow Grazing in a Circular Pasture Problem: Solution by Calculus

"A cow is attached by a rope to a point on the perimeter 
of a circular field. How long should the rope be in terms 
of the radius of the field so that the cow can graze in 
exactly half of the field?"

This problem has been around in one form or another 
for a long time.  You can find many solutions to it 
on on the internet.  But all of the solutions I've seen 
are geometric solutions, using plane geometry.  They 
all chop up the pasture into various shapes and add up 
the area of each one.

I have found a solution using calculus that I think is 
a lot simpler and more elegant.  This solution defines 
a differential of area that is centered around the point 
on the perimeter of the pasture where one end of the 
rope is tied.  Then it integrates from the origin (zero) 
until the rope is long enough to allow the cow to graze 
on half the area of the circular pasture.  
Here's the derivation:

Let R be the radius of the cow pasture.
Let r be the length of the rope.
Let Θ be the angle between a line from the point where 
the rope is tied on the perimeter of the pasture to the 
center of the pasture, and a line of length r from where
the rope is tied on the perimeter to the edge of the 
pasture.  See diagram: 


1. BC is a circular arc of radius r centered at point A.  
   The length L of BC is 2Θr.
2. Cos(Θ) = AB/AD = r/(2R), so Θ = cos-1(r/(2R)).
   (Note: Angle ABD is a right angle because it intercepts
   a 180 degree arc.)
3. So L = 2Θr = 2r * cos-1(r/(2R)).
4. Consequently, one form of a differential of area of
   the pasture is dArea = 2r * cos-1(r/(2R))dr.

We want to integrate this differential along AC starting 
at point A until r is long enough so that half the area
of the pasture is enclosed, so we need to solve for x:

Wolfram’s online integrator,, easily solves 
the integral portion of this equation if you substitute K for R 
in the integral.  Then you can let R = 1 and use WolframAlpha to 
solve for the ratio of r to R that will result in half of the 
area of the pasture.  The answer, to 4 decimal places is 
r = R * 1.1587

About Butterscotch and How to Make Butterscotch Flavor Powder

About Butterscotch
      My sources for this are many Google searches about butterscotch on the internet. 
First, there is no such thing as "true butterscotch".  The many recipes I found have various
ratios of sugar to butter, and there is a variation in the ingredients.  So there is only
"version A" of butterscotch, "version B", "version C" and so on.  The commonality
among most of them is that they contain sugar, butter, salt, and molasses.  The sugar
can be light brown sugar, dark brown sugar, or just plain sugar.  If it's just plain sugar,
molasses is added to the recipe; otherwise, molasses is optional.  If molasses is added
it can be plain molasses or, occasionally, blackstrap molasses.  The sugar to butter
ratio varies greatly — anywhere from 4:3 to 16:1 by weight, I've read.

The sugar, butter, salt, and molasses are mixed together and cooked until the temperature
is raised to anywhere between 245 degrees F to 310 degrees F. 

One question I asked myself is why, if molasses is just mostly caramelized sugar (as many
sources on the internet say), why, if it's added separately, is it always cooked along with the
other ingredients and not added later?  After further research on the internet, I found the
answer: Molasses is NOT caramelized sugar!  Why?  To refine sugar, sugar cane is boiled in
a vacuum at 160 degrees F.  160 degrees F is well below the caramelization temperature of
sugar, which begins at about 320 degrees F.  Also at 160 degrees F the Maillard reaction
(which I'll get to shortly) is very slow, so molasses has undergone very little Maillard reaction.

Caramelization is not important for butterscotch because butterscotch is not caramelized, but
the Maillard reaction is very important since it is what develops the butterscotch flavor.  The
Maillard reaction takes place at an optimal rate between 270 and 310 degrees F.  To avoid

caramelization from occurring, among all but one of the recipes  I've seen for butterscotch,
the maximum cooking temperature is 300 degees F.

How to Make Butterscotch Flavor Powder
      I like the flavor of butterscotch a lot, and after some experimenting I figured out how to
make a butterscotch flavor powder that I could add to other things, such as yogurt.  The
following recipe is based on recipes for butterscotch I've found on the internet, plus a
couple of my own ideas, which seem to be original.

60 grams      dark brown sugar

30 grams      unsalted butter
1/8 tsp          salt (not sea salt)

1 1/2 Tbsp    blackstrap molasses (optional, to make the flavor "extra butterscotchy")
2 tsp             water (approximarely)

      Mix the ingredients together in a pan, adding just enough water to wet down the
other ingredients, set a stovetop burner in the medium heat range, and, stirring 
constantly, cook slowly until the temperature of the mixture is a carefully measured
310 to 315 degrees F.  Cooking slowly is important for giving the Maillard reaction time
to take place. (The Maillard reaction is what develops the butterscotch flavor.)  For
measuring the temperature, I use an infrared surface temperature thermometer. 
There are many brands of these infrared thermometers on Amazon.

When the mixture is cooked, pour it immediately (not letting it harden) onto a flat
surface that has been covered with a sheet of parchment paper, and let the mixture
cool for, say, 20 minutes, until it is rock solid.  Then crack it up with your food-gloved
hands, transfer it to a blade type coffee grinder, and grind it into a fine powder.  This
may require several "transfer-grind" operations.  Store the powder in a refrigerator,
and use it as desired.  When using the powder, also add some vanilla flavor or extract.

Serving size 1 Tbsp.  Makes about 7 servings.

“Knock Knock Unlock” Puzzle Box

This is my version of a "knock knock unlock" puzzle box.  A knock knock unlock puzzle box is a locked box that is opened by knocking on it with a particular sequence of knocks, for example "knock-pause-knock-knock-pause-knock-knock-knock" There are several versions of these boxes on the internet.  For my version, I wanted to make a box that has nothing mounted on the outside — no lights, no switches, no wires going through the box, and no outside latch.  Just a blank box on the outside.  Here are photos of and links to photos the inside and the outside of the box:



    1. Mini Pushbutton Power Switch, LV (Pololu #2808) – 3.95
    2. Mercury Tilt Switch, 1A @ 250V (Amazon) – $2.37
    3. Pololu 5V Step-Up/Step-Down voltage regulator (Pololu #2123) – $5.95
    4. Pololu A-Star 32U4 Micro microcontroller (Pololu #3101) – $12.75
    5. Anycubic Microphone Sound Detection Sensor Module (Amazon) – 6.99
    6. Hitec 35485S HS-5485HB Digital Servo (Amazon) – 24.84
    7. Micro Vibration Motor With Cable, 1.5V to 6V (Amazon) – $8.69
    8. 470 uF, 35VDC Capacitor (RadioShack #272-1030) – $1.49
    9. 1000 uF, 35VDC Capacitor (RadioShack #272-1032) – $1.99
    10. Safety 1st Spring-Loaded Cabinet & Drawer Latch (Walmart) – $3.59
    11. Pololu 3-AA Battery Holder (Pololu #142) – $0.99
    12. Breadboard (Sparkfun #PRT-12625) – $5.95
    13. Three Alkaline or Lithium size AA Batteries
    14. ArtMinds Wooden Box, 8 1/2" L, 5 5/16" W, 3 9/16" H (Michaels crafts) – $5.49

    Mini Pushbutton Power Switch
        VIN to 4.5V battery pack
        VOUT to voltage regulator, VIN
        A to mercury switch
        B to mercury switch
        OFF to 32U4, pin 12
        GND to common ground

    Mercury switch
        To A and B on the pushbutton power switch
        (Note: The mercury switch is mounted vertically, with the
         tip down and the connection wires above.)

    Voltage regulator
        VIN to power switch, VOUT
        VOUT to 5V common positive
        GND to common ground

    32U4 Micro microcontroller
        5V to 5V common positive
        GND to common ground
        Pin 3 to microphone DO pin
        Pin 5 to servo signal wire
        Pin 9 to vibration motor red (+) wire
        Pin 12 power switch OFF

        + to 5V common positive
        G to common ground
        DO to 32U4 pin 3

        Black to common ground
        Red to 5V common positive
        Signal wire to 32U4 pin 5

    Vibration Motor
        Red to 32U4 pin 9
        Black to common ground

    470 uF Capacitor
        Positive to 5V common positive
        Negative to common ground

    1000 uF Capacitor
        Positive to voltage regulator VIN
        Negative to common ground

    Cabinet & Drawer Latch
        1. Trim the top of the latch off so it will fit in the box.
        2. Drill a couple of 1/16" holes into the arm of the latch.
        3. Loop heavy sewing thread through the 1/16" holes and
            the servo arm and tie the servo to the latch.

    The following is just a very basic program to receive knocks and open and close
the box.  You start the program by turning the box upside down, closing the mercury
switch, and then turning the box upright.  The sequence of knocks required to open
the box is just four knocks within 30 seconds.  Add your own code to make the
required sequence of knocks more complex.

This software was written by Bob Day.
It was written in May, 2016.

This software is licensed under the terms of the Creative
Commons "Attribution Non-Commercial Share Alike" license, version
3.0, which grants the limited right to use or modify it NON-
COMMERCIALLY, so long as appropriate credit is given and
derivative works are licensed under the IDENTICAL TERMS.  For
license details see
This source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of

#include <avr/sleep.h>
#include <avr/power.h>
#include <Servo.h>
// #include <SoftwareSerial.h>
// #include <serial.h>

        // Pin assignments
static const int servo_control = 5;
static const int knock_interrupt_pin = 3;
static const int off_pin = 12;
static const int buzz_pin = 9;

        // These values should be adjusted according to your needs
static const int OPEN_ANGLE = 120;  // degrees
static const int CLOSED_ANGLE = 60; // degrees
int knocksToOpen = 4;

        // The basic objects needed
Servo servo;
volatile long knock_heard = 0;
volatile long knockOkFlag = 0;
int knock_count = 0;
int delay_count = 0;
int idx; // Index variable.
int len;
int blinkLed = 13;

// The Arduino setup() function
void setup()
pinMode(servo_control, OUTPUT);
pinMode(3, INPUT);
pinMode(off_pin, OUTPUT);
pinMode(buzz_pin, OUTPUT);

attachInterrupt(0, knock_detected, RISING);


knock_count = 0;
knock_heard = 0;
knockOkFlag = 0;
delay_count = 0;
} // End of setup().

void loop()
if (knock_count >= knocksToOpen)
  knock_count = 0;
  knock_heard = 0;
  knockOkFlag = 0;
  digitalWrite(off_pin, HIGH);     // Turn off the power.
  if (knock_count < knocksToOpen)

  knockOkFlag = 1;                 // Allow reception of knocks.
  if (delay_count >= 120)          // If 30 seconds have passed since starting,
    digitalWrite(buzz_pin, HIGH);  // send a long buzz and
    digitalWrite(buzz_pin, LOW);
    digitalWrite(off_pin, HIGH);   // turn off the power.

  knockOkFlag = 0;                 // Knocks not allowed.
  digitalWrite(blinkLed, LOW);     // Turn off the blink LED.
  if (knock_heard == 1)
    digitalWrite(buzz_pin, HIGH);  // Acknowledge the knock.
    delay(250);                    //         "
    digitalWrite(buzz_pin, LOW);   //         "
    knock_heard = 0;

  if (knock_count >= knocksToOpen)
  } // End of while(1).
} // End of loop().

// Functions

// Knock detected interrupt
void knock_detected()
  if (knockOkFlag == 1)           // If knocks are OK,
    knock_heard = 1;              // A knock was heard.
    digitalWrite(blinkLed, HIGH); // Turn on the blink LED.

  knockOkFlag = 0;                // Knocks are not OK for a while.

Runs Up and Down Test for Randomness — Source Code

I recently searched long and hard on the internet for source code in C language to do a runs up and down test on a sequence of numbers to test whether it was a sequence of random numbers.  I found very little.  The couple of programs had, to me, very opaque and incomprehensible code.  So I wrote my own code.  Here is a link to my C language source code:

I hope it is comprehensible to others — I've included quite a few comments in  the code to try to make it so.  The download consists of a C++ program (actually it's just C) for doing the test and an error function.  Both are intended for Windows Visual Studio, but the test program should be very easily adaptable to other platforms.  The error function might take more doing and it might be best to replace it with your own.

Geiger Counter

I'm quiet happy with the Geiger counter I recently built.  I found many of the ideas for the electronic circuit I used on the internet, and I added some of my own ideas that significantly improved what I found on the internet.  Here is a link to the circuit:

I connect the output of the circuit to an interrupt input of an Arduino Micro microcontroller.  What I like about the circuit is that for every alpha, beta or gamma particle the Geiger tube detects, the circuit sends a single, very clean, pulse about four microseconds wide to the microcontroller, so that each particle detection is counted once and only once.  That is in contrast with many other circuits I tried that often count a particle detection multiple times.

Currently I'm using an LND 7313 Geiger tube (which, except for the style of its connectors, is the same as the more common 7317) instead of the LND 712 that I used originally.  The 7313 is a lot more sensitive to radiation than the 712.  It also runs at 550 volts, but R7 should be 4.7 megohms instead of 10 megohms.  The circuit should also run higher voltage tubes — it can easily be adjusted to provide more that 1000 volts.

For the MCU (microcontroller), I'm using a Pololu A-Star 32U4 Micro (item #3101), which is Arduino compatible.

For a display, I use a serial 20×4 LCD display, a sparkfun #LCD-09568.

The power supply consists of three 1.5v batteries in series connected to an adjustable step-up/step-down voltage regulator (pololu item #2118) adjusted to have a 5 volt output.

These four components, the Geiger counter circuit, the MCU, the LCD display, and the 5 volt power supply share a common ground, which I'll refer to as "GND".  The positive output of the power supply I'll call "POS".  POS is also common among the components.

The connections among the components are as follows:

From the Geiger counter circuit: Vcc 5V and Vcc go to POS, "to MCU interrupt" goes to pin 3 on the MCU, and ground goes to GND.

From the LCD display: RX goes to pin 2 on the MCU, VDD goes to POS, and GND goes to GND.

From the MCU (for the connections not previously listed): the 5V pin goes to POS, and the GND pin goes to GND.

Here is a link to the program I use in the Arduino Micro: