Expected input, just some junk by hand and a gnuplot script to see it
Ruby script to make normally-distributed data
Cleanup of norm-distrib.rb, generated dat file
Generated two dat files.  TBD: find the function that maps one to the other
New debias.rb to find the function that maps the experimental dat
into the expected dat (TBD: shifts to find mean, multiplies to correct
amplitude, and multiplies to spread data for better fit; the idea
is to minimize the area difference between the two datasets -- no
model (i.e. normal, binomial, etc) required)

Currently, debias just finds the mean in each input file.
This was verified to work correctly.
Finding sqrt of the squared differences sum.  This should be minimized.
Calcs mean of expected dat, shifts expected dat by the mean to the center.
Calcs mean of experimental dat, shifts experimental dat by the mean to the center.
Calculates the difference between these centered dats.  This is less than uncentered difference.
This helps figure out the bias function, where experimental[i] = bias(expected[i], expected_mean, experimental_mean)
Eventually, this bias function will correct for amplitude and spread, I think.
Eventually the bias function will be found iteratively, finding progressively better means, amplitudes, and spreads to minimize error.

expected mean:     50.0
experimental mean: 40.0
expected:experimental diff, unadjusted: 1.61299698890372
expected:experimental diff, centered:   1.42111290910789e-263
Printing function to get from experimental to expected GC content values.
This is a description of the bias function.

expected mean:     50.0
experimental mean: 40.0
expected:experimental diff, unadjusted: 1.61299698890372
expected:experimental diff, centered:   1.42111290910789e-263
expected_gc_content[i] =~ experimental_gc_content[i - (10.0)]
Now finding best first offset guess for expected[i]=experimental[i + offset]
Validated this first guess by comparing it to the difference in means of
expected to experimental.

expected mean:     50.0
experimental mean: 40.0
expected:experimental diff, unadjusted: 1.32265753090105
expected:experimental diff, centered:   0.0322599397780744
expected_gc_content[i] =~ experimental_gc_content[i + (10.0)]
expected:experimental diff, found:      0.0322599397780744
expected_gc_content[i] =~ experimental_gc_content[i + (10)] <-- see the XXX in the code for this
New norm-distrib params for new dat file.
Next todo is to adjust for amplitude by a particular factor.
Amplifying experimental (multiplying by a factor) such that the maximum
values of experimental and expected are identical.
Better and TBD is to try various possible amplification factors, and use
the one that minimizes the areal difference of the two curves.

expected mean:     50.0
experimental mean: 40.0
expected:experimental diff, unadjusted: 1.32265753090105
expected:experimental diff, centered:   0.0322599397780744
expected_gc_content[i] =~ experimental_gc_content[i + (10.0)]
expected:experimental diff, found:      0.0322599397780744
expected_gc_content[i] =~ experimental_gc_content[i + (10)]
expected     max: 0.892062058076386
experimental max: 0.713649646461109
expected:experimental amplification: 1.25
expected:experimental diff, amplified:  3.46667399173252e-33
expected_gc_content[i] =~ experimental_gc_content[i + (10)] * (1.25)
Added working gnuplot scripts for the sample norm distrivutions.
Linear interpolation between each datapoint, so that fit between
expected and experimental may be shifted by a fraction of a bin.
This fractional shifting along the X axis (gc_content bin) should
allow for greater error minimization, as fractional shifts can
shift the experimental curve "tighter" to the expected curve,
so a greater amount of areal overlap is possible.

Also printing out resulting datapoints so it's easy to plug into
Excel, or make another gnuplot.

Output:
expected mean:     50.0
experimental mean: 40.0
expected:experimental diff, unadjusted: 1.32265753090105
expected:experimental diff, centered:   0.0322599397780744
expected_gc_content[i] =~ experimental_gc_content[i + (10.0)]
expected:experimental diff, found:      0.233387167361045
expected_gc_content[i] =~ experimental_gc_content[i + (10.0)]
expected     max: 0.892062058076386
experimental max: 0.713649646461109
expected:experimental amplification: 1.25
expected:experimental diff, amplified:  6.641177678478
expected_gc_content[i] =~ experimental_gc_content[i + (10.0)] * (1.25)
debiased data follows according to above linear transformation:
39	0.0
40	2.38108331707304e-109
41	1.01335702507848e-88
42	2.90588192420119e-70
43	5.61462861653231e-54
44	7.30956776526076e-40
45	6.41194737115056e-28
46	3.78979564041296e-18
47	1.50927794290321e-10
48	4.04995547804455e-05
49	0.0732249128096324
50	0.892062058076386
51	0.0732249128096324
52	4.04995547804455e-05
53	1.50927794290321e-10
54	3.78979564041296e-18
55	6.41194737115056e-28
56	7.30956776526076e-40
57	5.61462861653231e-54
58	2.90588192420119e-70
59	1.01335702507848e-88
60	2.38108331707304e-109
61	3.76976512412629e-132
62	4.02143990200897e-157
63	2.89052322923912e-184
64	1.39990619491475e-213
65	4.56824089617716e-245
66	1.00444613019402e-278
67	1.48809923297984e-314
68	0.0
69	0.0
70	0.0
71	0.0
72	0.0
73	0.0
74	0.0
75	0.0
76	0.0
77	0.0
78	0.0
79	0.0
Added noise_level to norm-distrib.rb to add some fake bias, that would
otherwise come from an actual instrument.
Noise applied increases as signal increases.
This noise should move the curve a bit offcenter, which is more interesting
for testing debias.rb's ability to fit experiemental to expected with
fractional shifting etc.
Proof of fractional shift for better fit.  TBD: fit amplification factor
rather than just let amp be the ration of expected max to experimental
max.
The fit00 plot shows the expected, experimental, and experimental fit to
expected via linear transformation.

expected mean:     50.0
experimental mean: 39.7823888453991
expected:experimental diff, unadjusted: 0.69691512222759
expected:experimental diff, centered:   0.0272863771097296
expected_gc_content[i] =~ experimental_gc_content[i + (10.2176111546009)]
expected:experimental diff, found:      0.129282885691297
expected_gc_content[i] =~ experimental_gc_content[i + (10.2)]
expected     max: 0.564189583547756
experimental max: 0.475646913335881
expected:experimental amplification: 1.1861520967116
expected:experimental diff, amplified:  3.88129079271168
expected_gc_content[i] =~ experimental_gc_content[i + (10.2)] * (1.1861520967116)
debiased data follows according to above linear transformation:
40      7.08697495637484e-45
41      1.47186236701651e-36
42      9.9419253447544e-29
43      3.29203088805845e-22
44      4.13458801180453e-17
45      3.72865721783323e-12
46      2.12205688392411e-08
47      8.32138323779515e-05
48      0.0115233886247827
49      0.236019517730553
50      0.509637634615036
51      0.182521438249667
52      0.0264087126581387
53      0.00229186905045479
54      1.12825333477001e-05
55      1.37002057704199e-08
56      8.13808140667696e-13
57      1.87843631433472e-17
58      5.2801208790514e-23
59      1.3096275076529e-29
60      1.0447034155218e-36
61      1.73695854096606e-45
62      1.42556488462864e-54
63      2.45567088512595e-64
64      2.98250882626689e-75
65      8.71590981370941e-87
66      1.82941001143328e-99
67      1.02312318727572e-112
68      3.68452469270351e-127
69      1.76344350175774e-142
70      9.9918677026822e-159
71      1.83091715889819e-175
72      1.75278163578618e-193
73      2.78165088080124e-212
74      1.865452912118e-231
75      7.04205102517929e-252
76      1.51706648598018e-273
77      2.22774698680773e-295
78      3.84657772963578e-318
79      0.0
80      0.0
Iteratively finding amplification factor, which does a slightly better job
than guessing the amplification by the ratio of expected max gc content amount
to experimental max gc content amount, as evidenced by a lower diff score
(compare the lines
expected:experimental diff, amplified:  0.047730358128424
 and
expected:experimental diff, iteratively amplified:  0.047688293548018
)
It would be even better to do one iteration of guessing amplification,
finding the lowest diff, then recursing to another guessing round, but with
lo and hi boundaries set to the fineamp steps immediately prior and after
this best guess amplifcation.  This way the space of guessed amlification
factors may be recursively subdivided for increasing accuracy.  It's
not as clever as a binary search, but more exhaustive.

expected mean:     50.0
experimental mean: 39.7823888453991
expected:experimental diff, unadjusted: 0.69691512222759
expected:experimental diff, centered:   0.0272863771097296
expected_gc_content[i] =~ experimental_gc_content[i + (10.2176111546009)]
expected:experimental diff, found:      0.129282885691297
expected_gc_content[i] =~ experimental_gc_content[i + (10.2)]
expected     max: 0.564189583547756
experimental max: 0.475646913335881
expected:experimental amplification: 1.1861520967116
expected:experimental diff, amplified:  0.047730358128424
expected_gc_content[i] =~ experimental_gc_content[i + (10.2)] * (1.1861520967116)
expected:experimental diff, iteratively amplified:  0.047688293548018
expected_gc_content[i] =~ experimental_gc_content[i + (10.2)] * (1.18333333333333)
debiased data follows according to above linear transformation:
40	7.07013351966103e-45
41	1.46836464379072e-36
42	9.91829942431052e-29
43	3.28420772934793e-22
44	4.12476260635762e-17
45	3.7197964634284e-12
46	2.11701404308811e-08
47	8.30160836205008e-05
48	0.0114960045262855
49	0.235458642632849
50	0.508426535376901
51	0.18208769560628
52	0.02634595518183
53	0.00228642266919802
54	1.12557216159646e-05
55	1.36676486991915e-08
56	8.11874212809533e-13
57	1.87397241168182e-17
58	5.26757323747326e-23
59	1.30651531818919e-29
60	1.04222078978014e-36
61	1.73283084508422e-45
62	1.42217718240961e-54
63	2.44983524635815e-64
64	2.97542121357528e-75
65	8.69519738782468e-87
66	1.82506261453674e-99
67	1.02069184463447e-112
68	3.67576881451647e-127
69	1.75925286720407e-142
70	9.96812309957533e-159
71	1.82656618042717e-175
72	1.74861633801472e-193
73	2.77504058549791e-212
74	1.86101986312948e-231
75	7.025316345375e-252
76	1.51346134000866e-273
77	2.22245298476544e-295
78	3.83743751518771e-318
79	0.0
80	0.0
Generating more distributions for demo, particularly
norm-distrib_mean53_variance5.0_amp3.5_range20-80_noise1.5_fit00.dat

Its wider variance allows more opportunity for random noising,
which gives a better demo of how actual data may be fit to the expected.
Restructuring code so functions aren't interspersed with calls.
This is in anticipation of looping, converging on a best shift
and multiplier to fit experimental to expected.
Merge https://github.com/aday00/minimize-area-difference