-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIPSamplesheetSample2.py
More file actions
992 lines (729 loc) · 26.4 KB
/
VIPSamplesheetSample2.py
File metadata and controls
992 lines (729 loc) · 26.4 KB
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
import re
class VIPSamplesheetSample2:
def __init__(self):
self.number_of_columns = 0
self.sampledata = {}
self.sample_affected = False
self.is_proband = False
self.pcr_is_performed = False
self.hpo_ids = {}
self.sample_errors = {}
self.sample_info = {}
def get_data(self):
"""Returns all saved sample data.
Returns
-------
self.sampledata : dict of str
Saved sample data per column name
"""
return self.sampledata
def has_datafield(self, headerfield):
"""Returns whether a certain datafield is present.
Parameters
----------
headerfield : str
Column name to check
"""
return headerfield in self.sampledata
def get_datafield(self, headerfield):
"""Returns the data for the specified column. Will return None if not available.
Parameters
----------
headerfield : str
Column name indicating which data to get
"""
if headerfield in self.sampledata:
return re.sub(r"[\x00-\x1f]", "", self.sampledata[headerfield])
return None
def get_datafield_raw(self, headerfield):
"""Returns the data for the specified column. Will return None if not available.
Parameters
----------
headerfield : str
Column name indicating which data to get
"""
if headerfield in self.sampledata:
return self.sampledata[headerfield]
return None
def get_number_of_columns(self):
"""Returns the number of columns the sample has.
Returns
-------
self.number_of_columns : int
The number of columns the sample has
"""
return self.number_of_columns
def set_number_of_columns(self, numofcols):
"""Sets the number of samplesheet columns the sample has.
Parameters
----------
numofcols : int
The number of columns
"""
self.number_of_columns = numofcols
def get_project_id(self):
"""Returns the saved project_id stripped of non printable characters.
Returns
-------
str
self.project_id stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["project_id"].strip())
def get_project_id_raw(self):
"""Returns the saved project_id as is (potentially with non printable characters).
Returns
-------
self.project_id : str
Project ID as is.
"""
return self.sampledata["project_id"]
def set_project_id(self, projectid):
"""Saves the supplied sample project id.
Parameters
----------
projectid : str
Project ID to save
"""
self.sampledata["project_id"] = projectid
def get_family_id(self):
"""Returns the saved family id stripped of non printable characters.
Returns
-------
str
self.family_id stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["family_id"].strip())
def get_family_id_raw(self):
"""Returns the saved family_id as is (potentially with non printable characters).
Returns
-------
self.family_id : str
Family ID as is.
"""
return self.sampledata["family_id"]
def set_family_id(self, famid):
"""Saves the supplied family_id.
Parameters
----------
famid : str
Family ID to save
"""
self.sampledata["family_id"] = famid
def get_individual_id(self):
"""Returns the saved individual_id stripped of non printable characters.
Returns
-------
str
Saved individual_id stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["individual_id"].strip())
def get_individual_id_raw(self):
"""Returns the saved individual_id as is (potentially with non printable characters).
Returns
-------
self.individual_id : str
Saved individual_id as is
"""
return self.sampledata["individual_id"]
def set_individual_id(self, individualid):
"""Saves the supplied individual id.
Parameters
----------
individualid : str
Individual ID to save
"""
self.sampledata["individual_id"] = individualid
def get_paternal_id(self):
"""Returns the saved paternal id stripped of non printable characters.
Returns
-------
str
Saved paternal_id stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["paternal_id"].strip())
def get_paternal_id_raw(self):
"""Returns the saved paternal_id as is (potentially with non printable characters).
Returns
-------
self.paternal_id : str
Saved paternal_id as is
"""
return self.sampledata["paternal_id"]
def set_paternal_id(self, patid):
"""Saves the supplied paternal id.
Parameters
----------
patid : str
Paternal ID to save
"""
self.sampledata["paternal_id"] = patid
def get_maternal_id(self):
"""Returns the saved maternal id stripped of non printable characters.
Returns
-------
str
Saved maternal_id stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["maternal_id"].strip())
def get_maternal_id_raw(self):
"""Returns the saved maternal_id as is (potentially with non printable characters).
Returns
-------
self.maternal_id : str
Saved maternal_id as is
"""
return self.sampledata["maternal_id"]
def set_maternal_id(self, matid):
"""Saves the supplied maternal_id
Parameters
----------
matid : str
Maternal ID to save
"""
self.sampledata["maternal_id"] = matid
def get_sample_sex(self):
"""Returns the saved sample sex stripped of non printable characters.
Returns
-------
str
Saved sample sex stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["sex"].strip())
def get_sample_sex_raw(self):
"""Returns the saved sample sex as is
Returns
-------
self.sample_sex : str
Saved sample sex as is
"""
return self.sampledata["sex"]
def set_sample_sex(self, samplesex):
"""Saves the supplied sample sex.
Parameters
----------
sex : str
Sample sex to save
"""
self.sampledata["sex"] = samplesex
def get_affected(self):
"""Returns the saved affected status stripped of non printable characters.
Returns
-------
str
Saved affected status stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["affected"].strip())
def get_affected_raw(self):
"""Returns the affected status as is (potentially with non printable characters)
Returns
-------
self.affected : str
Saved affected status
"""
return self.sampledata["affected"]
def is_affected(self):
"""Returns boolean representation whether the sample has an affected status.
Returns
-------
self.sample_affected : bool
Whether the sample has affected status or not
"""
return self.sample_affected
def set_affected(self, aff):
"""Saves the supplied affected status.
Parameters
----------
aff : str
Affected status to save
"""
self.sampledata["affected"] = aff
def set_is_affected(self):
"""Sets the boolean for affected status to true."""
self.sample_affected = True
def get_proband(self):
"""Returns the saved proband status stripped of non printable characters.
Returns
-------
str
Saved proband status stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["proband"].strip())
def get_proband_raw(self):
"""Returns the saved proband status as is (potentially with non printable characters)
Returns
-------
self.proband : str
"""
return self.sampledata["proband"]
def is_proband(self):
"""Returns whether the sample is a proband.
Returns
-------
self.is_proband : bool
Whether the sample is a proband
"""
return self.is_proband
def set_proband(self, proba):
"""Saves the supplied proband value.
Parameters
----------
proba : str
Proband status to save
"""
self.sampledata["proband"] = proba
def set_is_proband(self):
"""Sets the boolean for proband to true"""
self.is_proband = True
def get_hpo(self):
"""Returns the HPO terms stripped of non printable characters.
Returns
-------
str
HPO terms stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["hpo_ids"].strip())
def get_hpo_raw(self):
"""Returns the save HPPO terms as is (potentially with non pintable characters)
Returns
-------
str
HPO terms as is
"""
return self.sampledata["hpo_ids"]
def set_hpo(self, hpostr):
"""Saves the supplied HPO terms.
Parameters
----------
hpostr : str
HPO terms to save
"""
self.sampledata["hpo_ids"] = hpostr
def get_hpo_ids(self):
"""Returns the set of split HPO terms.
Returns
-------
self.hpo_ids
"""
return self.hpo_ids
def set_hpo_ids(self, hpoids):
"""Saves the supplied hpo ids.
Parameters
----------
hpoids : dict of str
Split HPO terms
"""
self.hpo_ids = hpoids
def get_sequencing_method(self):
"""Returns the saved sequencing method stripped of non printable characters.
Returns
-------
str
Sequencing method stripped of potential non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["sequencing_method"].strip())
def get_sequencing_method_raw(self):
"""Returns the saved sequencing method as is.
Returns
-------
str
Saved sequencing method as is (potentially with non printable characters)
"""
return self.sampledata["sequencing_method"]
def set_sequencing_method(self, seqmethod):
"""Saves the supplied sequencing method.
Parameters
----------
seqmethod : str
Sequencing method to save
"""
self.sampledata["sequencing_method"] = seqmethod
def get_pcr_performed(self):
"""Returns the saved pcr_performed value stripped of non printable characters.
Returns
-------
str
Saved pcr performed value stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["pcr_performed"])
def get_pcr_performed_raw(self):
"""Returns the saved pcr_performed value as is (potentially with non printable characters).
Returns
-------
str
Saved pcr_performed value as is
"""
return self.sampledata["pcr_performed"]
def get_pcr_is_performed(self):
"""Returns whether the pcr_performed value is set to true.
Returns
-------
self.pcr_is_performed : bool
Whether the pcf_performed is set to true
"""
return self.pcr_is_performed
def set_pcr_performed(self, pcrperformed):
"""Saves the supplied prc performed value.
Parameters
----------
pcrperformed : str
pcr_performed status to save
"""
self.sampledata["pcr_performed"] = pcrperformed
def set_pcr_is_performed(self):
"""Sets the pcr_performed status to true."""
self.pcr_is_performed = True
def get_bed_file(self):
"""Returns the saved BED file stripped of non printable characters.
Returns
-------
str
Path to BED file stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["regions"].strip())
def get_bed_file_raw(self):
"""Returns the saved path to the BED file as is (potentially with non printable characters)\
Returns
-------
str
Path to the saved BED file
"""
return self.sampledata["regions"]
def set_bed_file(self, bedfile):
"""Saves the supplied path to the BED file.
Parameters
----------
bedfile : str
Path to the BED file to save
"""
self.sampledata["regions"] = bedfile
def get_adaptive_sampling(self):
"""Returns the saved adaptive_sampling value stripped of non printable characters.
Returns
-------
str
Adaptive sampling value stripped of non printable characters
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["adaptive_sampling"].strip())
def get_adaptive_sampling_raw(self):
"""Returns the saved adaptive_sampling value as is.
Returns
-------
str
Saved adaptive_sampling value as is
"""
return self.sampledata["adaptive_sampling"]
def set_adaptive_sampling(self, adsampling):
"""Saves the supplied adaptive_sampling value.
Parameters
----------
adsampling : str
The adaptive_sampling value to save
"""
self.sampledata["adaptive_sampling"] = adsampling
def get_fastq_files(self):
"""Returns the saved paths to fastq files as string stripped of non printable characters.
Returns
-------
str
Paths to fastq files as string
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["fastq"])
# return [re.sub(r"[\x00-\x1f]", "", x.strip()) for x in self.sampledata["fastq"]]
def get_fastq_files_raw(self):
"""Returns the paths to the fastq files as string as is (potentially with non printable characters).
Returns
-------
str
Paths to fastq files as string
"""
return self.sampledata["fastq"]
def set_fastq_files(self, fastqfiles):
"""Saves the supplied paths to fastq files.
Parameters
----------
fastqfiles : str
Paths to fastq files as string
"""
self.sampledata["fastq"] = fastqfiles
def get_fastq_r1_files(self):
"""Returns the saved paths to fastq r1 files stripped of non printable characters.
Returns
-------
str
Paths to fastq r1 files as string
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["fastq_r1"])
# return [re.sub(r"[\x00-\x1f]", "", x.strip()) for x in self.sampledata["fastq_r1"]]
def get_fastq_r1_files_raw(self):
"""Returns the paths to the saved fastq r1 files as is (potentially with non printable characters).
Returns
-------
str
Paths to fastq r1 files as string
"""
return self.sampledata["fastq_r1"]
def set_fastq_r1_files(self, r1files):
"""Saves the paths to the supplied fastq r1 files.
Parameters
----------
str
Paths to the fastq r1 files as string
"""
self.sampledata["fastq_r1"] = r1files
def get_fastq_r2_files(self):
"""Returns the saved paths to the fastq r2 files as string stripped of non printable characters.
Returns
-------
str
Paths to the fastq r2 files as string
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["fastq_r2"])
# return [re.sub(r"[\x00-\x1f]", "", x.strip()) for x in self.sampledata["fastq_r2"]]
def get_fastq_r2_files_raw(self):
"""Returns the saved paths to the fastq r2 files as string as is (potentially with non printable characters).
Returns
-------
str
Paths to the fastq r2 files as string as is
"""
return self.sampledata["fastq_r2"]
def set_fastq_r2_files(self, r2files):
"""Saves the supplied paths to the fastq r2 files as string.
Parameters
----------
r2files : str
Paths to the fastq r2 files as string
"""
self.sampledata["fastq_r2"] = r2files
def get_sequencing_platform(self):
"""Returns the saved value for sequencing_platform stripped of non printable characters.
Returns
-------
str
The value for sequencing_platform
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["sequencing_platform"].strip())
def get_sequencing_platform_raw(self):
"""Returns the saved value for sequencing_platform as is (potentially with non printable characters).
Parameters
----------
str
Saved value for sequencing_platform as is
"""
return self.sampledata["sequencing_platform"]
def set_sequencing_platform(self, seqplatform):
"""Saves the supplied value for sequencing_platform.
Parameters
----------
seqplatform : str
Value for sequencing_platform to save
"""
self.sampledata["sequencing_platform"] = seqplatform
def get_cram_file(self):
"""Returns the saved path to the CRAM file stripped of non printable characters.
Returns
-------
str
Saved path to the CRAM file
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["cram"].strip())
def get_cram_file_raw(self):
"""Returns the saved path to the CRAM file as is (potentially with non printable characters).
Returns
-------
str
Saved path to the CRAM file
"""
return self.sampledata["cram"]
def set_cram_file(self, cramfile):
"""Saves the supplied path to the CRAM file.
Parameters
----------
cramfile : str
Path to the CRAM file to save
"""
self.sampledata["cram"] = cramfile
def get_assembly(self):
"""Returns the saved assembly value stripped of non printable characters.
Returns
-------
str
Saved assembly value
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["assembly"].strip())
def get_assembly_raw(self):
"""Returns the saved assembly value as is (potentially with non printable characters).
Returns
-------
str
Saves assembly value
"""
return self.sampledata["assembly"]
def set_assembly(self, assem):
"""Saves the supplied assembly value.
Parameters
----------
assem : str
Value for assembly to save
"""
self.sampledata["assembly"] = assem
def get_gvcf_file(self):
"""Returns the saved path to the GVCF file stripped of non printable characters.
Returns
-------
str
Saves path to the GVCF file
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["gvcf"].strip())
def get_gvcf_file_raw(self):
"""Returns the saved path to the GVCF file as is (potentially with non printable characters).
Returns
-------
str
Saved path to the GVCF file
"""
return self.sampledata["gvcf"]
def set_gvcf_file(self, gvcffile):
"""Saves the supplied path to the GVCF file.
Parameters
----------
gvcffile : str
Path to the GVCF file
"""
self.sampledata["gvcf"] = gvcffile
def get_vcf_file(self):
"""Returns the saved path to the VCF file stripped of non printable characters.
Returns
-------
str
Saved path to the VCF file
"""
return re.sub(r"[\x00-\x1f]", "", self.sampledata["vcf"].strip())
def get_vcf_file_raw(self):
"""Returns the saved path to the VCF file as is (potentially with non printable characters).
Returns
-------
str
Saved path to the VCF file
"""
return self.sampledata["vcf"]
def set_vcf_file(self, vcffile):
"""Sets the pat
Parameters
----------
vcffile : str
"""
self.sampledata["vcf"] = vcffile
def add_sample_error(self, columnname, errormessage):
"""Add an error message for a column.
Parameters
----------
columnname : str
Name of the column where the error occured
errormessage : str
The error message to save
"""
if columnname not in self.sample_errors:
self.sample_errors[columnname] = []
self.sample_errors[columnname].append(errormessage)
def get_sample_errors(self):
"""Returns the dictionary with all sample errors.
Returns
-------
self.sample_errors : dict of str
Dictionary containing the sample errors per column name
"""
return self.sample_errors
def get_sample_column_errors(self, columnname):
"""Returns the error messages of the sample for a specified column.
If the columnname had no error for the sample (and can therefore not be found)
an empty list will be returned.
Parameters
----------
columnname : str
Name of the samplesheet column to get the error messages for.
Returns
-------
list of str
List of error messages for the column
"""
if columnname in self.sample_errors:
return self.sample_errors[columnname]
return []
def add_sample_info(self, columnname, infomessage):
"""Adds the supplied information message.
Parameters
----------
columnname : str
Name of the column where the info message occured
infomessage : str
THe infomessage to save
"""
if columnname not in self.sample_info:
self.sample_info[columnname] = []
self.sample_info[columnname].append(infomessage)
def get_sample_infos(self):
"""Returns all sample info messages.
Returns
-------
self.sample_info : dict of str
Info messages of the sample
"""
return self.sample_info
def get_sample_column_infos(self, columnname):
"""Get all info messages of this sample for a specified column.
Parameters
----------
columnname : str
Name of the column
Returns
-------
list of str
Info messages for a specified column
"""
if columnname in self.sample_info:
return self.sample_info[columnname]
return []
def field_has_errors(self, columnname):
"""Checks whether a supplied column has an error for this sample.
Parameters
----------
columnname : str
Name of the column to check
Returns
-------
bool
True if sample has one or more errors in the supplied column, False if not
"""
return columnname in self.sample_errors
def field_has_info(self, columnname):
"""Returns whether this sample has one or more info messages for a specified samplesheet column.
Parameters
----------
columnname : str
Name of the column to check for info messages
"""
return columnname in self.sample_info
def get_sampledata_as_filelinestr(self, headerfields):
"""Returns the requested sample data as a file line.
The requested data is specified by the list of header fields.
Parameters
----------
headerfields : list of str
List of samplesheet column headers specifying which data to get
Returns
-------
sampledatastr : str
Sample data as a file line
"""
sampledatastr = ""
x = 0
for hf in headerfields:
if hf in self.sampledata:
sampledatastr += f"{self.get_datafield(hf)}"
else:
sampledatastr += ""
if x < len(headerfields) -1:
sampledatastr += "\t"
x += 1
return sampledatastr