-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIodineAssay_DataExtractor.py
executable file
·1404 lines (1329 loc) · 65.5 KB
/
IodineAssay_DataExtractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# The script has been written in Python 3.5
# IODINE ASSAY DATA EXTRACTOR for plates and spectrum text (.txt) files
# 2017 by A.L.O. Gaenssle ([email protected]),
# University of Groningen, the Netherlands
import os
# ---------------------------------------------------------------------------
# DEFAULT VALUES ------------------------------------------------------------
# ---------------------------------------------------------------------------
# Information: Backup the file if you change variables
# Information: The default values below are based on columns of input files
# Information: All columns are separted by a space
# (check the number by copying the input file into a table e.g. Excel)
# Number of the column containing the wavelength in nm
# (only required for spectra)
Default_WavelengthColumnIndex = 1 # Default = 1
# Number of the column containing the first column of results
# (wells A-H1 for plate format, well A1 for column format)
Default_FirstDataColumnIndex = 3 # Default = 3
# The given text appearing at the beginning of the line directly
# above the data (only required for spectra)
Default_BeforeDataText = "Wavelength" # Default = "Wavelength"
# The given text appearing at the beginning of the line below the data
# (adjust Default_EmptyLinesBetweenDataAndAfterText for empty lines
# between data and label)
Default_AfterDataText = "~End" # Default = "~End"
# Empty Lines between the last line containing data
# (Wells H1-12 for plate format, last Wavelength for column format)
# and Default_AfterDataText
Default_EmptyLinesBetweenDataAndAfterText = 1 # Default = 1
# Default settings (Default types of sample settings)
# Warning: Do not change anything expect the values of the variables!
def GetDefaultSettings(DefaultType, SampleDirection):
if SampleDirection == "v": # Do not change!
if DefaultType == "short": # Do not change!
# Number of time points (no extra wells) (whole number from 1-8)
NTimePoints = 6 # Default = 6
# Number of time points and extra wells (whole number from 1-8)
SlopeCount = 8 # Default = 8
# Number of identical samples per sample (whole number from 1-12)
Muliplicates = 3 # Default = 3
# Total number of samples on plate (samples * repetitions)
# (whole number from 1-12)
TotNSamples = 12 # Default = 12
# List of time points in min at which aliquotes were taken
# Default = [1, 2, 3, 5, 7, 10] (any list of numbers)
TypeTimePoints = [1, 2, 3, 5, 7, 10]
else:
NTimePoints = 14 # Default = 14 (whole number from 1-16)
SlopeCount = 16 # Default = 16 (whole number from 1-16)
Muliplicates = 2 # Default = 2 (whole number from 1-6)
TotNSamples = 6 # Default = 6 (whole number from 1-6)
# List of time points in min at which aliquotes were taken
# Default = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30]
# (any list of numbers)
TypeTimePoints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30]
else:
NTimePoints = 10 # Default = 10 (whole number from 1-12)
SlopeCount = 12 # Default = 12 (whole number from 1-12)
Muliplicates = 2 # Default = 2 (whole number from 1-8)
TotNSamples = 8 # Default = 8 (whole number from 1-8)
# List of time points in min at which aliquotes were taken
# Default = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (any list of numbers)
TypeTimePoints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Position of wells containing the ASSAY solution)
# (may be f, l, a or e)
# (f=first, l=last, a=absent, e=end of first column/row)
Lassay = "f" # Default = "f"
# Position of wells contianing the WASH solution)
# (may be f, l, a or e)
# (f=first, l=last, a=absent, e=end of first column/row)
Lwash = "l" # Default = "l"
AssayArea = "A1-H12"
return (AssayArea, Lassay, Lwash, Muliplicates, NTimePoints, SlopeCount,
TotNSamples, TypeTimePoints)
# Default start value of input data for shift values
# (wavelength and absorbance at lambda(max))
def getABandWLMax():
# Minimum wavelength to have the maximum abosrbance
# (set value to e.g. 450 if measuring spectra from 280 nm)
# (any whole number)
WLMax = 0 # Default = 0
ABMax = 0 # Do not change!
return (ABMax, WLMax)
# -----------------------------------------------------------------------------
# FUNCTIONS -------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Print header
def PrintHeader():
print("\n","-"*75,"\n","-"*75,"\n")
print("THE IODINE ASSAY DATA EXTRACTOR\tby A.L.O. Gaenssle, 2017")
print("\n","-"*75,"\n","-"*75,"\n")
print("This program re-organizes text files from the spectrophotometer "
"for analysis")
print("\nThe program has been written to:"
"\n- Import files from spectrophotometer "
"(default Molecular Devices but variable)"
"\n- Export files suitable for programs such as Stata or Origin"
"\n- Extract and re-organize data depending on user input"
"\n- Save data in columns of:\n\t- Sample index"
"\n\t- Time(min)\n\t- (Wavelength (nm))"
"\n\t- Results for each multiplicate"
"\n\t- (Wavelength and absorbance at lambda(max))")
print("\nContact A. Lucie Gaenssle for help and adaptions "
"([email protected])")
print("\n","-"*75)
print("\nInformation:\n- Complete input by clicking enter"
"\n- Navigate within and between the inputs using the arrow keys"
"\n- Terminate the program any time by:"
"\n\t- Closing the terminal (window)"
"\n\t- Ctrl + C")
print("\n","-"*75,"\n QUESTIONAIRE\n","-"*75)
# Complete questionaire
def CompleteQuestionaire():
# Determine if input is in plate or column format
# (Subfunction to CompleteQuestionaire)
def GetInputFormat():
InputFormat = input("\nIs your data stored in plate format "
"(single wavelength) or columns (spectra)?"
"\n(p=plate, c=columns)\n")
while InputFormat not in ("p", "c"):
InputFormat = input("\nPlease enter 'p' or 'c'!"
"\n(only the letter)\n")
if InputFormat == "p":
InputFormatFull = "plate"
else:
InputFormatFull = "columns"
return (InputFormat, InputFormatFull)
# Get slope direction
# (Subfunction to GetSlopeCount)
def GetDirection():
SampleDirection = input("\nWhat is the direction of your time points "
"(slope)? \n(h=horizontal, v=vertical)\n")
while SampleDirection not in ("v", "h"):
SampleDirection = input("\nPlease enter 'h' or 'v'!"
"\n(only the letter)\n")
if SampleDirection == "v":
DirectionFull = "columns"
else:
DirectionFull = "rows"
return (DirectionFull, SampleDirection)
# Check if detault setting have been used
# (Subfunction to CompleteQuestionaire)
def CheckIfDefaultSettings(SampleDirection):
if SampleDirection == "v":
DefaultType = "short"
(AssayArea, Lassay, Lwash, Muliplicates, NTimePoints, SlopeCount,
TotNSamples, TypeTimePoints) = GetDefaultSettings(
DefaultType, SampleDirection)
Correct = input("The default settings (%s assay) are:"
"\n\n- %d samples, each %d time(s)"
"\n- Assay wells in %s. row, wash wells in %s. row "
"(f=first, l=last, a=absent)"
"\n- %d time points taken at min %s"
"\n- Your total assay area is %s"
"\n\nDoes your experiment have these settings?"
"\n(y=yes, n=no)\n"
% (DefaultType, TotNSamples/Muliplicates,
Muliplicates, Lassay, Lwash, NTimePoints,
TypeTimePoints, AssayArea))
while Correct not in ("y", "n"):
Correct = input("\nPlease enter 'y' or 'n'!\n")
if Correct == "n":
DefaultType = "long"
(AssayArea, Lassay, Lwash, Muliplicates, NTimePoints,
SlopeCount, TotNSamples, TypeTimePoints) = \
GetDefaultSettings(DefaultType, SampleDirection)
Correct = input("The default settings (%s assay) are:"
"\n\n- %d samples, each %d time(s)"
"\n- Assay wells in %s. row, wash wells in %s."
"row\n (f=first, l=last, a=absent, "
"e=end of first columns)"
"\n- %d time points taken at min %s"
"\n- Your total assay area is %s"
"\n\nDoes your experiment have these settings?"
"\n(y=yes, n=no)\n"
% (DefaultType, TotNSamples/Muliplicates,
Muliplicates, Lassay, Lwash, NTimePoints,
TypeTimePoints, AssayArea))
else:
DefaultType = "normal"
(AssayArea, Lassay, Lwash, Muliplicates, NTimePoints,
SlopeCount, TotNSamples, TypeTimePoints) = \
GetDefaultSettings(DefaultType, SampleDirection)
Correct = input("The default settings are:"
"\n\n- %d samples, each %d time(s)"
"\n- Assay wells in %s. column, "
"wash wells in %s.column "
"(f=first, l=last, a=absent)"
"\n- %d time points taken at min %s"
"\n- Your total assay area is %s"
"\n\nDoes your experiment have these settings?"
"\n(y=yes, n=no)\n"
% (TotNSamples/Muliplicates, Muliplicates,
Lassay, Lwash, NTimePoints, TypeTimePoints,
AssayArea))
while Correct not in ("y", "n"):
Correct = input("\nPlease enter 'y' or 'n'!\n")
if Correct == "y":
Default = True
else:
print("\nSee manual, if you want to modiy the default settings"
"\n\nThe questionaire will be conducted")
Default = False
return (Default, DefaultType)
# Determine location of assay and wash wells
# (Subfunction to GetSlopeCount)
def GetLocationOfExtraWells():
Lassay = 0
Lwash = 0
while Lassay == Lwash:
Lassay = input("\nWhere are your ASSAY solutions located?"
"\n(f=first row/column, l=last row/column, "
"e=end of first row/column, a=absent\n")
while Lassay not in ("f", "l", "e", "a"):
Lassay = input("\nPlease enter 'f', 'l', 'e', or 'a'\n")
Lwash = input("\nWhere are your WASH solutions located?"
"\n(f=first row/column, l=last row/column, "
"e=end of first row/column, a=absent\n")
while Lwash not in ("f", "l", "e", "a"):
Lwash = input("\nPlease enter 'f', 'l', 'e', or 'a'\n")
if Lassay == Lwash:
print("\nAssays and wash solutions cannot be "
"located in the same wells!")
SlopeCount = 0
if Lassay in ("f", "l", "e"):
SlopeCount += 1
if Lwash in ("f", "l", "e"):
SlopeCount += 1
return (Lassay, Lwash, SlopeCount)
# Get number of time points
# (Subfunction to GetSlopeCount)
def GetSlope(SampleDirection, SlopeCount):
Correct = False
while Correct == False:
try:
if SampleDirection == "v":
NTimePoints = int(input(
"\nEnter your number of time points"
"\n(between 1 and 16, usually 6 or 14)\n"))
else:
NTimePoints = int(input(
"\nEnter your number of time points"
"\n(between 1 and 12, usually 10)\n"))
except ValueError:
print("\nPlease enter a number!")
else:
SlopeCount = SlopeCount + NTimePoints
Correct = True
return (NTimePoints, SlopeCount)
# Get total number of wells/sample and check if within allowed range
# (Subfunction to Questionaire)
def GetSlopeCount():
Correct = False
while Correct == False:
DirectionFull, SampleDirection = GetDirection()
Lassay, Lwash, SlopeCount = GetLocationOfExtraWells()
NTimePoints, SlopeCount = GetSlope(SampleDirection, SlopeCount)
if SampleDirection == "v" and SlopeCount > 16:
print("\nYour wells/sample (%d) exceed the "
"allowed number of 16!\n(%d time points +%d extra wells)"
% (SlopeCount, NTimePoints, (SlopeCount - NTimePoints)))
elif SampleDirection == "h" and SlopeCount > 12:
print("\nYour wells/sample (%d) exceed the "
"allowed number of 12!\n(%d time points +%d extra wells)"
% (SlopeCount, NTimePoints, (SlopeCount - NTimePoints)))
else:
Correct = True
break
return (DirectionFull, Lassay, Lwash, NTimePoints, SampleDirection,
SlopeCount)
# Get number of multiplicates
# (Subfunction to GetSampleNumber)
def GetMultiplicates():
Muliplicates = 0
while Muliplicates == 0:
try:
Muliplicates = int(input("\nEnter the number of identical "
"samples (multiplicates)\nIdentical samples are assumed "
"to be next to on another\n(e.g. 2=duplicates)\n"))
except ValueError:
print("\nThis is not a number!")
continue
else:
break
return (Muliplicates)
# Set the number of samples
# (Subfunction to Questionaire)
def GetSampleNumber(SampleDirection):
Muliplicates = GetMultiplicates()
NSamples= 0
while NSamples == 0:
try:
NSamples = int(input("\nEnter the number of individual "
"samples\n(e.g 4)\n"))
except ValueError:
print("\nThis is not a number!")
continue
else:
TotNSamples = NSamples*Muliplicates
if SampleDirection == "v" and not 1 <= TotNSamples <= 12:
print("\nYour total number of samples (%d), "
"samples*multiplicates (%d*%d),"
"\n exeeds the maximal column number of 12!"
% (TotNSamples, NSamples, Muliplicates))
Muliplicates = GetMultiplicates()
NSamples = 0
elif SampleDirection == "h" and not 1 <= TotNSamples <= 8:
print("\nYour total number of samples (%d), "
"samples*multiplicates (%d*%d),"
"\n exeeds the maximal row number of 8!"
% (TotNSamples, NSamples, Muliplicates))
Muliplicates = GetMultiplicates()
NSamples = 0
else:
break
return (Muliplicates, NSamples, TotNSamples)
# Get sample area on plate
#(Subfunction to Questionaire)
def GetAssayArea(SampleDirection, SlopeCount, TotNSamples):
AssayArea = "A1-H12"
Correct = False
AreaSize = 96
while Correct == False:
try:
StartWell, EndWell = AssayArea.split('-')
StartRow = ord(StartWell[0])
StartColumn = int(StartWell[1:])
EndRow = ord(EndWell[0])
EndColumn = int(EndWell[1:])
NRows = EndRow-StartRow+1
NColumns = EndColumn-StartColumn+1
except ValueError:
AssayArea = input("\nThis is not a valid format!"
"\nWhat is the plate range of your experiment?"
"\n(96 well plates, e.g. A1-H6)\n")
if (" ") in AssayArea:
AssayArea = input("\nWrong format! "
"Please do not include spaces!"
"\nWhat is the plate range of your experiment?"
"\n(e.g. A1-H6)\n")
else:
AreaSize = NRows*NColumns
if not 65 <= StartRow <= 72 or not 65 <= EndRow <= 72:
AssayArea = input("\nYour start row (%s) and/or end row "
"(%s) is not within the allowed range!"
"\nPlease enter another assay area\n(between A1-H12)\n"
% (chr(StartRow), chr(EndRow)))
elif not 1 <= AreaSize <= 96:
AssayArea = input("\nYour assay area (%d) is not within "
"the allowed range of 96!\nPlease enter another one\n"
% AreaSize)
elif NColumns > 12:
AssayArea = input("\nYour number of columns (%d) is not "
"within the allowed range of 12!"
"\nPlease enter another assay area\n(between A1-H12)\n"
% NColumns)
elif NRows > 8:
AssayArea = input("\nYour number of rows (%d) is not "
"within the allowed range of 8!"
"\nPlease enter another assay area\n(between A1-H12)\n"
% NRows)
elif TotNSamples*SlopeCount < AreaSize:
AssayArea = input("\nPlease enter your assay area "
"(inculding analysis, assay and wash wells)"
"\nYour samples (%d) and wells/sample (%d) do not "
"cover a whole plate\n(between A1-H12)\n"
% (TotNSamples, SlopeCount))
else:
Correct = True
break
if SampleDirection == "v" and SlopeCount > 8:
NColumns = NColumns/2
NRows = NRows*2
return (AssayArea, AreaSize, EndWell, NColumns, NRows, StartWell)
# Go through questionaire
# (Subfunction to CompleteQuestionaire)
def Questionaire(InputFormat, InputFormatFull):
Confirmation = False
Correct = "n"
while Correct == "n":
while Confirmation == False:
repetition = 0
(DirectionFull, Lassay, Lwash, NTimePoints, SampleDirection,
SlopeCount) = GetSlopeCount()
Muliplicates, NSamples, TotNSamples = \
GetSampleNumber(SampleDirection)
AssayArea, AreaSize, EndWell, NColumns, NRows, StartWell = \
GetAssayArea(SampleDirection, SlopeCount, TotNSamples)
while TotNSamples not in (NRows, NColumns) and repetition <= 1:
if SampleDirection == "v":
print("\nYour number of samples (%d) is not equal "
"to your number of columns (%d)!"
% (TotNSamples, NColumns))
else:
print("\nYour number of samples (%d) is not equal "
"to your number of rows (%d)!"
% (TotNSamples, NRows))
Muliplicates, NSamples, TotNSamples = \
GetSampleNumber(SampleDirection)
if TotNSamples in (NRows, NColumns):
break
(AssayArea, AreaSize, EndWell, NColumns, NRows,
StartWell) = GetAssayArea(SampleDirection,
SlopeCount, TotNSamples)
repetition += 1
while SlopeCount not in (NRows, NColumns) and repetition <= 1:
if SampleDirection == "v":
print("\nYour number of wells/sample (%d) is not "
"equal to your number of rows (%d)!"
% (SlopeCount, NRows))
else:
print("\nYour number of wells/sample (%d) is not "
"equal to your number of columns (%d)!"
% (SlopeCount, NColumns))
(DirectionFull, Lassay, Lwash, NTimePoints,
SampleDirection, SlopeCount) = GetSlopeCount()
if SlopeCount in (NRows, NColumns):
break
(AssayArea, AreaSize, EndWell, NColumns, NRows,
StartWell) = GetAssayArea(SampleDirection,
SlopeCount, TotNSamples)
repetition += 1
if (SampleDirection == "v" and TotNSamples == NColumns
and SlopeCount == NRows):
Confirmation = True
break
elif (SampleDirection == "h" and TotNSamples == NRows
and SlopeCount == NColumns):
Confirmation = True
break
else:
print("\nThere is something not correct with your input"
"\n(the questionaire will thus be repeated)\n")
print("\n","-"*20)
print("\n","-"*20)
Correct = input("Summary:"
"\n\nYour input file is stored in %s format"
"\nYour sample number is %d*%d"
"\nYou have %d time points +%d extra wells/sample in %s"
"\nYour total assay area is %s"
"\n\nIs this correct?\n(y=yes, n=no)\n"
% (InputFormatFull, NSamples, Muliplicates,
NTimePoints, (SlopeCount-NTimePoints),
DirectionFull, AssayArea))
while Correct not in ("y", "n"):
Correct = input("\nPlease enter 'y' or 'n'!"
"\n(only the letter)\n")
if Correct == "n":
Confirmation = False
InputFormat, InputFormatFull = GetInputFormat()
return (AssayArea, InputFormat, Lassay, Lwash, Muliplicates,
NTimePoints, SampleDirection, SlopeCount, TotNSamples)
# Get type (min) of time points
# (Subfunction to CompleteQuestionaire)
def GetTypeTimePoints(NTimePoints):
Correct = "n"
Default = True
Repetition = 0
Restart = "n"
while Correct != "y":
if Default == True and NTimePoints in (6, 10, 14):
if NTimePoints == 6:
TypeTimePoints = [1, 2, 3, 5, 7, 10]
elif NTimePoints == 10:
TypeTimePoints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
else:
TypeTimePoints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
15, 20, 25, 30]
else:
try:
InputString = input("\nEnter your time points in min, "
"separated by a space\n(e.g. 1 2 3.5 4 5.5 15)\n")
TypeTimePoints = InputString.split(" ")
for i in TypeTimePoints:
TypeTimePoints = [float(x) for x in TypeTimePoints]
except ValueError:
print("\nPlease enter a series of numbers separated "
"by a single space each!")
if NTimePoints != len(TypeTimePoints):
print("\nYour number of time points are not equal to number"
"entered earlier!")
else:
Correct = input("\nSamples were taken at the follwing minutes:"
"\n%s\nIs this correct?\n(y=yes, n=no)\n" % TypeTimePoints)
while Correct not in ("y", "n"):
Correct = input("\nPlease enter 'y' or 'n'!\n")
if Correct == "n":
Default = False
if Repetition >= 1:
Restart = input("\nDo you want to restart the "
"questionaire?\n(y=yes, n=no)\n")
while Restart not in ("y", "n"):
Restart = input("\nPlease enter 'y' or 'n'!\n")
if Restart == "y":
Correct = "y"
Repetition += 1
return(Restart, TypeTimePoints)
# Start of CompleteQuestionaire script
InputFormat, InputFormatFull = GetInputFormat()
DirectionFull, SampleDirection = GetDirection()
Default, DefaultType = CheckIfDefaultSettings(SampleDirection)
if Default == True:
(AssayArea, Lassay, Lwash, Muliplicates, NTimePoints, SlopeCount,
TotNSamples, TypeTimePoints) = GetDefaultSettings(DefaultType,
SampleDirection)
else:
(AssayArea, InputFormat, Lassay, Lwash, Muliplicates,
NTimePoints, SampleDirection, SlopeCount, TotNSamples) = \
Questionaire(InputFormat, InputFormatFull)
Restart, TypeTimePoints = GetTypeTimePoints(NTimePoints)
while Restart == "y":
(AssayArea, InputFormat, Lassay, Lwash, Muliplicates,
NTimePoints, SampleDirection, SlopeCount, TotNSamples) = \
Questionaire(InputFormat, InputFormatFull)
Restart, TypeTimePoints = GetTypeTimePoints(NTimePoints)
return (AssayArea, Default, DirectionFull, InputFormat, Lassay, Lwash,
Muliplicates, NTimePoints, SampleDirection, SlopeCount, TotNSamples,
TypeTimePoints)
# Get file name and import it
def GetInputFile(InputFormat):
# Get file name
# (Subfunction to GetInputFile)
def GetFileName(DirectoryName):
InputPath = input("\nEnter your file name:"
"\n- If file and python script in the same folder: e.g. Test.txt"
"\n- If file in subfolder of folder with python script: e.g. "
"IodineAssay\Test.txt\n- Otherwise enter full path: e.g. "
"X:\Experiments\IodineAssay\Test.txt"
"\n\nHint: Your current directory is:\n%s\n"
% DirectoryName)
FileFormat = False
while FileFormat == False:
while os.path.isfile(InputPath) == False:
InputPath = input("\nThis file does not exist!"
"\nPlease enter a correct name"
"\n(Check the file path by right clicking on "
"the file and selecting 'Properties')"
"\n(To not rewrite whole path, use arrows on keyboard)\n")
if InputPath.endswith(".txt") or InputPath.endswith(".csv"):
FileFormat = True
else:
InputPath = input("\nYour file does not have the correct "
"format!\nPlease enter a name ending with .txt or .csv\n")
return (InputPath)
# Import table, store data in list(lines) of lists(columns)
# (Subfunction to GetInputFile)
def GetFile(InputPath):
InputData = []
try:
for DecodedLineOfFile in open(InputPath, 'r', encoding='UTF-16'):
DecodedLineOfFile = DecodedLineOfFile.rstrip()
LineOfFile = DecodedLineOfFile.split('\t')
InputData.append(LineOfFile)
except UnicodeError:
try:
for DecodedLineOfFile in open(InputPath, 'r'):
DecodedLineOfFile = DecodedLineOfFile.rstrip()
LineOfFile = DecodedLineOfFile.split('\t')
InputData.append(LineOfFile)
except UnicodeError:
print("\nThe program is for a file encoded with UTF-8 or "
"UTF-16\nIf you have another file format, "
"contact Lucie Gaenssle\n([email protected])"
"\n\nThe program will now be terminated")
quit()
return (InputData)
# Check which files should be created
def GetWantedFiles(InputFormat):
if InputFormat == "c":
WantedFiles = 0
print("\nWhich files do you want to create?"
"\nChoose one of these options (enter the number):"
"\n1 - only spectra"
"\n2 - only shift (wavelength and absorbance at lambda(max))"
"\n3 - both spectra and shift (separate files)"
"\n4 - nothing (quit program)")
while WantedFiles not in (1, 2, 3, 4):
try:
WantedFiles = int(input())
if WantedFiles not in (1, 2, 3, 4):
print("\nPlease enter a number between 1 and 4!")
except ValueError:
print("\nThis is not a number!"
"\nPlease enter a number between 1 and 4!")
if WantedFiles == 4:
print("\nThe program will now be terminated")
quit()
else:
WantedFiles = 1
return(WantedFiles)
# Start of GetInputFile script
DirectoryName, ScriptName = os.path.split(os.path.abspath(__file__))
os.chdir(DirectoryName)
InputPath = GetFileName(DirectoryName)
InputData = GetFile(InputPath)
WantedFiles = GetWantedFiles(InputFormat)
return(DirectoryName, InputData, InputPath, WantedFiles)
# Get the number of experiments and the index of the last line of data
def GetNExperimentsAndLastLineIndex(Default_AfterDataText,
Default_EmptyLinesBetweenDataAndAfterText, InputData, InputFormat):
Correct = False
Count = 0
NPlates = 0
PlateIndex = 0
if any(Default_AfterDataText == Lines[0] for Lines in InputData) == False:
PresenceEnd = False
while Correct == False:
try:
if InputFormat == "p":
LastLineIndex = (int(input("\nThe endline '%s' is missing "
"in your file!\nEnter the line (row) index of the "
"wells H1-12 of your input plate"
"\n(if you have no data in row H, enter "
"the line index where the data would be)"
"\n(find index: open input file with "
"Notpad, Tab 'View'>'Status Bar'>'Ln')"
"\n(else see manual to modify the default end line)"
"\n(most likely 11 for the first plate)\n"
% Default_AfterDataText)) - 1)
else:
LastLineIndex = (int(input("\nThe endline '%s' is missing "
"in your file!\nEnter the line (row) index containing "
"the last data of your input plate"
"\n(find index: open input file with "
"Notpad, Tab 'View'>'Status Bar'>'Ln')"
"\n(else see manual to modify the default end line)"
"\n(most likely 154 for the first plate)\n"
% Default_AfterDataText)) - 1)
except ValueError:
print("\nPlease enter a number!")
else:
NPlates = 1
PlateIndex = 1
break
else:
PresenceEnd = True
for Lines in InputData:
if Lines[0] == Default_AfterDataText:
NPlates += 1
if NPlates > 1:
while PlateIndex == 0:
try:
PlateIndex = int(input("\nYou have %s plates in your "
"file! Which one should be converted?"
"\n(insert a number (e.g. 2), only one at a time can "
"be converted)\n" % NPlates))
except ValueError:
print("\nThis is not a number!")
continue
else:
if PlateIndex > NPlates:
print("\nYour input number (%s) is not within your "
"number of plates (%s)!")
else:
break
else:
PlateIndex = 1
for LastLineIndex in range(len(InputData)):
if InputData[LastLineIndex][0] == Default_AfterDataText:
Count += 1
if Count == PlateIndex:
LastLineIndex -= \
Default_EmptyLinesBetweenDataAndAfterText + 1
break
return (LastLineIndex, NPlates, PlateIndex, PresenceEnd)
# Check and get column and row indices of wavelength and first data point
def GetLocationIndices(AssayArea, Default_BeforeDataText,
Default_FirstDataColumnIndex, Default_WavelengthColumnIndex, InputData,
InputFormat, LastLineIndex, PlateIndex, PresenceEnd, SampleDirection):
# Check for presence and requirement of label 'Wavelength'
# (Subfunction to GetLocationIndices)
def CheckPresenceWavelength(Default_BeforeDataText, InputData, InputFormat,
PresenceEnd):
Option = 0
AskForFirstLineIndex = False
if (any(Default_BeforeDataText == Lines[0] for Lines in InputData) ==
False):
PresenceWavelength = False
if InputFormat == "c":
print("\nYour file does not contain a '%s' label!"
"\nChoose one of these options (enter the number):"
"\n1 - Change format from column to plate "
"(single wavelength)\n2 - Enter the index of the "
"first line (row) containing the data"
"\n3 - quit program (see manaul to modify default "
"first line)" % Default_BeforeDataText)
while Option not in (1, 2, 3):
try:
Option = int(input())
if Option not in (1, 2, 3):
print("\nPlease enter a number between 1 and 3!")
except ValueError:
print("\nThis is not a number!\nPlease enter a number "
"between 1 and 3!")
if Option == 1:
InputFormat = "p"
elif Option == 2:
AskForFirstLineIndex = True
else:
print("\nThe program will now be terminated")
quit()
else:
PresenceWavelength = True
if InputFormat == "p":
Confirmation = input("\nYour input file seems to be in a "
"column format (spectrum)!"
"\nDo you want to change the format from "
"'plate' to 'columns'?\n(y=yes, n=no)\n")
while Confirmation not in ("y", "n"):
Confirmation = input("\nPlease enter 'y' or 'n'!\n")
if Confirmation == "y":
InputFormat = "c"
else:
print("\nThe file will be imported in a plate format "
"(there might be some problems)"
"\nCheck your output file afterwards")
return(AskForFirstLineIndex, PresenceWavelength)
# Get index of first line (Subfunction to GetLocationIndices)
def GetFirstLineIndex(AskForFirstLineIndex, Default_BeforeDataText,
InputData, InputFormat, LastLineIndex, PlateIndex, PresenceEnd,
PresenceWavelength):
Correct = False
PlateCount = 0
if InputFormat == "p":
FirstLineIndex = LastLineIndex - 7
else:
if PresenceWavelength == True:
for Line in range(len(InputData)):
if InputData[Line][0] == Default_BeforeDataText:
PlateCount += 1
if PlateCount == PlateIndex:
FirstLineIndex = Line + 1
break
elif AskForFirstLineIndex == True:
while Correct == False:
try:
FirstLineIndex = (int(input("\nEnter the line (row) "
"index containing the first data of your single "
"input plate"
"\n(See manaul to change default column)"
"\n(most likely 3 or 4 for plate 1)\n")) -1)
except ValueError:
print("\nPlease enter a number!")
else:
break
else:
FirstLineIndex = 3
return(FirstLineIndex)
# Check if wavelengths are located in the first column
# (Subfunction to GetLocationIndices)
def GetWavelengthColumnIndex(Default_WavelengthColumnIndex, FirstLineIndex,
InputData, InputFormat, LastLineIndex):
Correct = False
Count = 0
WavelengthColumnIndex = Default_WavelengthColumnIndex - 1
if InputFormat == "c":
while Correct == False:
try:
if (all(float(Lines[WavelengthColumnIndex])
in range(200,800) for Lines in
InputData[FirstLineIndex:(LastLineIndex+1)]) == True):
break
else:
WavelengthColumnIndex = (int(input(
"\nYour wavelengths don't seem to be in "
"the first column!"
"\n(range contains data not in range 200-800)"
"\n\nEnter the column index containing the "
"wavelength"
"\n(See manaul to change default column)"
"\n(columns are separated by spaces)\n")) - 1)
if (WavelengthColumnIndex not in
range(len(InputData[FirstLineIndex]))):
WavelengthColumnIndex = (int(input(
"\nThis is not a valid column number!"
"\n(columns are separated by spaces)\n")) -1)
except ValueError:
WavelengthColumnIndex = (int(input(
"\nYour wavelengths don't seem to be in the "
"first column!"
"\n(range contains not only numbers)"
"\n\nEnter the column index containing the wavelength"
"\n(See manaul to change default column)"
"\n(columns are separated by spaces)\n")) -1)
Count += 1
if Count > 1:
QuitProgram = input("\nPlease check your input file!"
"\nDo you want to quit the program?\n(y=yes, n=no)\n")
while QuitProgram not in ("y", "n"):
QuitProgram = input("\nPlease enter 'y' or 'n'!\n")
if QuitProgram == "y":
quit()
return(WavelengthColumnIndex)
# Check if location of first data point is correct
# (Subfunction to GetLocationIndices)
def GetFirstDataColumnIndex(AssayArea, Default_FirstDataColumnIndex,
FirstLineIndex, InputData, InputFormat,
LastLineIndex, SampleDirection):
Correct = False
Count = 0
FirstDataColumnIndex = Default_FirstDataColumnIndex - 1
StartWell, EndWell = AssayArea.split('-')
StartRow = ord(StartWell[0]) - 65
StartColumn = int(StartWell[1:]) -1
FirstTestLineIndex = FirstLineIndex
LastTestLineIndex = LastLineIndex
while Correct == False:
if InputFormat == "p":
FirstResultsColumnIndex = FirstDataColumnIndex + StartColumn
if SampleDirection == "h":
FirstResultsColumnIndex += 1
else:
FirstTestLineIndex += 1
LastTestLineIndex -+ 1
else:
FirstResultsColumnIndex = (FirstDataColumnIndex + StartColumn +
StartRow*12 + 1)
if SampleDirection == "v":
FirstResultsColumnIndex += 12
try:
if (all(0 <= float(Lines[FirstResultsColumnIndex]) <= 5
for Lines in
InputData[FirstTestLineIndex:(LastTestLineIndex)])
== True):
break
else:
FirstDataColumnIndex = (int(input(
"\nYour first data column does not seem "
"to be in the default column (=3)!"
"\n(range contains data not in range 0-5)"
"\n\nEnter the column index containing "
"the spectrum of well A1"
"\n(if you have no data in A1, enter the "
"column where this data would be)"
"\n(See manual to change default column)"
"\n(columns are separated by spaces)"
"\n(most likely 3)\n")) - 1)
if (FirstResultsColumnIndex not in
range(len(InputData[FirstLineIndex]))):
FirstDataColumnIndex = (int(input(
"\nThis is not a valid column number!"
"\n(columns are separated by spaces)\n")) - 1)
except ValueError:
FirstDataColumnIndex = (int(input(
"\nYour first data column does not seem "
"to be in the default column (=3)!"
"\n(range contains not only numbers)"
"\n\nEnter the column index containing "
"the spectrum of well A1"
"\n(if you have no data in A1, enter the "
"column where this data would be)"
"\n(See manual to change default column)"
"\n(columns are separated by spaces)"
"\n(most likely 3)\n")) - 1)
Count += 1
if Count > 1:
QuitProgram = input("\nPlease check your input file!"
"\nDo you want to quit the program?\n(y=yes, n=no)\n")
while QuitProgram not in ("y", "n"):
QuitProgram = input("\nPlease enter 'y' or 'n'!\n")
if QuitProgram == "y":
quit()
return(FirstDataColumnIndex)
# Start of GetLocationIndices script
AskForFirstLineIndex, PresenceWavelength = CheckPresenceWavelength(
Default_BeforeDataText, InputData, InputFormat, PresenceEnd)
FirstLineIndex = GetFirstLineIndex(AskForFirstLineIndex,
Default_BeforeDataText, InputData, InputFormat, LastLineIndex,
PlateIndex, PresenceEnd, PresenceWavelength)
WavelengthColumnIndex = GetWavelengthColumnIndex(
Default_WavelengthColumnIndex, FirstLineIndex, InputData, InputFormat,
LastLineIndex)
FirstDataColumnIndex = GetFirstDataColumnIndex(AssayArea,
Default_FirstDataColumnIndex, FirstLineIndex, InputData, InputFormat,
LastLineIndex, SampleDirection)
return(FirstDataColumnIndex, FirstLineIndex, WavelengthColumnIndex)
# Extract data from input file
def GetData(AssayArea, FirstDataColumnIndex, FirstLineIndex, InputData,
InputFormat, LastLineIndex, PlateIndex, WavelengthColumnIndex):
# Extract wavelengths of input data
def GetWavelengthList(InputData, InputFormat, FirstLineIndex,
LastLineIndex, WavelengthColumnIndex):
WavelengthList = []
if InputFormat == "c":
for Line in range(FirstLineIndex, LastLineIndex+1):
try:
float(InputData[Line][WavelengthColumnIndex])
WavelengthList.append(float(InputData[Line]
[WavelengthColumnIndex]))
except ValueError:
print("There are not only numbers in the first column!"
"\nPlease check your text file")
break
if len(WavelengthList) == 0:
print("There is not label above the list of wavelength!"
"\nSee manual to change the default label"
"\nElse contact Lucie Gaenssle ([email protected])"
"\n\nThe program will now be terminated")
quit()
return (WavelengthList)
# Read data into lists and store in plate format
def ReadDataToPlateFormat(InputData, InputFormat, FirstDataColumnIndex,
FirstLineIndex, LastLineIndex):
DataPoints = []
CombinedData = []
if InputFormat == "c":
for Column in range(FirstDataColumnIndex,
(FirstDataColumnIndex+96)):
for Line in range(FirstLineIndex, LastLineIndex+1):
try:
DataPoints.append(InputData[Line][Column])
except IndexError:
DataPoints.append("0")
DataListofLists = ([DataPoints[index:(index+LastLineIndex-
FirstLineIndex+1)] for index in
range(0, len(DataPoints), LastLineIndex-FirstLineIndex+1)])
DataPlateFormat = ([DataListofLists[index:index+12] for index in
range(0, len(DataListofLists), 12)])
else:
for Line in range(FirstLineIndex, LastLineIndex+1):
for Column in range(FirstDataColumnIndex,
(FirstDataColumnIndex+12)):
try:
DataPoints.append(InputData[Line][Column])
except IndexError:
DataPoints.append("0")
DataPlateFormat = ([DataPoints[index:index+12] for index in
range(0, len(DataPoints), 12)])
return (DataPlateFormat)
# Extract total assay area
# (Subfunction to ConvertData)
def ExtractAssayArea(AssayArea, DataPlateFormat, InputFormat):
Plate = []
StartWell, EndWell = AssayArea.split('-')
StartRow = ord(StartWell[0]) - 65
StartColumn = int(StartWell[1:]) - 1
EndRow = ord(EndWell[0]) - 64
EndColumn = int(EndWell[1:])
for Line in DataPlateFormat[(StartRow):(EndRow)]:
Rows = Line[(StartColumn):(EndColumn+1)]
Plate.append(Rows)
return (Plate)
# Start of GetData script
WavelengthList = GetWavelengthList(InputData, InputFormat, FirstLineIndex,
LastLineIndex, WavelengthColumnIndex)
DataPlateFormat = ReadDataToPlateFormat(InputData, InputFormat,
FirstDataColumnIndex, FirstLineIndex, LastLineIndex)
Plate = ExtractAssayArea(AssayArea, DataPlateFormat, InputFormat)
return(Plate, WavelengthList)