-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTranscript.py
More file actions
1866 lines (1699 loc) · 80 KB
/
Transcript.py
File metadata and controls
1866 lines (1699 loc) · 80 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
993
994
995
996
997
998
999
1000
__author__ = "Jan-Simon Baasner"
__email__ = "janbaas@cebitec.uni-bielefeld.de"
from enum import Enum, unique
from VCF_Variant import Variant,VariantEnum
from LogOrganizer import LogEnums, LogOrganizer
from GenomeHandler import GenomeHandler,SequenceHandlingError,Fasta_Enum
@unique
class TranscriptEnum (Enum):
"""
This class supports enums for transcripts and the classification of variants inside these transcripts.
"""
START_NOT_IN_CDS = "Error - Startposition is not in the CDS"
END_NOT_IN_CDS = "Error - Endposition is not in the CDS"
POSITION_NOT_IN_CDS = -1
FORWARD = True
REVERSE = False
UNKNOWN_STRAND_DIRECTION = "No Direction for this transcript available" #will hopefully never happen
# Stuff for variants inside the transcript
INSERTION = "INS"
DELETION = "DEL"
SUBSTITUTION = "SUB"
FRAMESHIFT = "Frameshift"
FRAMESHIFT_1 = "Frameshift+1"
FRAMESHIFT_2 = "Frameshift+2"
FRAMESHIFT_1_DEL = "Frameshift-1"
FRAMESHIFT_2_DEL = "Frameshift-2"
STOP_GAINED = "Stop gained"
STOP_LOST = "Stop lost"
STOP_CHANGED = "Stop changed"
STOP_CAUSED_IN = "STOP_CAUSED_IN:".lower()
AA_CHANGE = "Amino acid change"
START_LOST = "Start lost"
MISSENSE_VARIANT = "MISSENSE_VARIANT".lower() # http://sequenceontology.org/browser/current_svn/term/SO:0001583
#errors/warnings
UNKNOWN_NUKLEOTIDE = "UNKNOWN_NUKLEOTIDE".lower()
UNKNOWN_AMINOACID = "UNKNOWN_AMINOACID".lower()
# when the transcript structure is damaged
CDS_START_INVOLVED = "Hits before Start into CDS"
CDS_STOP_INVOLVED = "Hits CDS Stop and after"
CDS_INTRON_TO_EXON = "Hits from intron to exon"
CDS_EXON_TO_INTRON = "Hits from exon to intron"
CDS_INTRON_DELETION = "CDS_INTRON_DELETION".lower()
CDS_EXON_DELETION = "CDS_EXON_DELETION".lower()
class Variant_Information_Storage:
"""
A storage class for in-transcript use only. It contains all necessary variant information.
"""
def __init__(self, ChrPosition: int, Ref: str, Alt: str, Unchanged_CDS_Position: int, ID: str, qual:str, filter:str, info:str):
"""
Initialization of all necessary information.
:param ChrPosition: Position of the variant.
:param Ref: VCF REF entry.
:param Alt: VCF ALT entry.
:param Unchanged_CDS_Position: Position inside the original CDS.
:param ID: VCF ID entry.
:param qual: VCF QUAL entry.
:param filter: VCF FILTER entry.
:param info: VCF INFO entry.
"""
self.ChrPosition = ChrPosition
self.Unchanged_CDS_Position = Unchanged_CDS_Position #without variant effects
self.Changed_CDS_Position = 0 #with variant effects
self.Ref = Ref
self.Alt = Alt
self.ID = ID
self.Qual = qual
self.Filter = filter
self.OLD_Info = info
self.ReverseRef = For_Type_Safety_and_statics.BioReverseSeq(Ref)
self.ReverseAlt = For_Type_Safety_and_statics.BioReverseSeq(Alt)
if self.Unchanged_CDS_Position != TranscriptEnum.POSITION_NOT_IN_CDS:
self.OrigRaster = For_Type_Safety_and_statics.calculateRaster(self.Unchanged_CDS_Position)
else:
self.OrigRaster = self.Unchanged_CDS_Position
self.Classification = []
self.StartOfOwnEffect = 0
self.EndOfOwnEffect = 0
self.OrigTriplets = ""
self.OrigRevTriplets = ""
self.OrigAmino = ""
# after variant effects
self.Changed_Raster = 0
self.ChangedTriplets = ""
self.ChangedRevTriplets = ""
self.NewAmino = ""
self.STOP_CAUSED_IN = -1
self.SharedEffectsWith = []
def SetUnchanged_CDS_Position(self, Unchanged_CDS_Position:int):
self.Unchanged_CDS_Position = Unchanged_CDS_Position
if self.Unchanged_CDS_Position != TranscriptEnum.POSITION_NOT_IN_CDS:
self.OrigRaster = For_Type_Safety_and_statics.calculateRaster(self.Unchanged_CDS_Position)
else:
self.OrigRaster = self.Unchanged_CDS_Position
def SetChanged_CDS_Position(self, Changed_CDS_Position: int):
"""
Sets the value for the changed cds position and calculates the changed raster, too.
But only, if possible, this position is maybe outside the cds and will note it.
:param Changed_CDS_Position: New CDS position after all variant effects.
:return: Nothing.
"""
self.Changed_CDS_Position = Changed_CDS_Position
if type(Changed_CDS_Position) == int:
self.Changed_Raster = For_Type_Safety_and_statics.calculateRaster(Changed_CDS_Position)
else:
self.Changed_Raster = Changed_CDS_Position
class Transcript:
"""
Contains all information about a single transcript, including all variants in it's range.
Contains all necessary functions to calculate classification of the variants inside a transcript.
"""
def __init__ (self, IndexKey: int, TID: str, StartOfRNA: int, EndOfRNA: int, ForwardDirection: TranscriptEnum.REVERSE, Chr:str):
"""
Initialization of the transcript-class.
:param IndexKey: Unique number, for identifying this transcript: 0...n.
:param TID: Not unique(tri-allele)! Transcripts identification string from the GFF3-File: For example: "AT5G40340.1"
:param StartOfRNA: Start position inside the genome/dna-data. Not String-Position.
:param EndOfRNA: End position inside genome/dna-data. Not String-Position.
:param ForwardDirection: TranscriptEnum.FORWARD or TranscriptEnum.REVERSE for transcript/strand orientation.
"""
self.IndexKey = IndexKey
self.Chr = Chr
self.TID = TID
self.StartOfRNA = int(StartOfRNA)
self.EndOfRNA = int(EndOfRNA)
self.ListofCDS = [] # [(StartPos, EndPos, Raster)]
self.ForwardDirection = ForwardDirection
self.Complete_CDS = ""
self.Rev_CDS = ""
self.ListofVariants = [] # [VariantIDs]
self.LastCDSPosition = 0
self.Gene_Info_String = ""
self.UTR_Description = []
self.EXON_Descriptin = []
self.Gene_Start_Position = 0
self.Gene_End_Position = 0
#original not changed data an sequence of the transcript
self.uChDNAsequence = ""
self.uChAAsequence = ""
self.uChDNA_length = 0
self.uChAA_length = 0
# for integrated variants action:
self.IntegratedVariantObjects_CDS_Hits = []
self.IntegratedVariantObjects_NotCDS = []
self.IV_Changed_DNA_CDS_Seq = ""
self.IV_Ready = False
self.IV_NewPositionList = [0]
self.IV_OriginalTranslation = ""
self.IV_ChangedTranslation = ""
self.IV_Count_Stops_in_New_AA = -1
self.IV_ListOfEffects = []
self.IV_DNA_length = 0
self.IV_AA_length = 0
# state's of transcript
self.TID_locked = False # for changing TID because of more than one multi_allel_variants
self.Transcript_CDS_damaged = False # exon or intron damaged
self.CDS_Exist = False
self.Rev_CDS_Exist = False
self.MultiAllelVariants = False
self.Lost_Stop = False
self.Found_New_Stop = False
self.CDS_Changed = False
self.origDNAtoshort = False
def SetGene_Start_Position(self,Gene_Start_Position:int):
"""
Set the start position of the gene.
:param Gene_Start_Position: Position in the chromosome.
:return: Nothing.
"""
self.Gene_Start_Position = Gene_Start_Position
def SetGene_End_Position(self,Gene_End_Position:int):
"""
Set the end position of the gene.
:param Gene_End_Position: Position in the chromosome.
:return: Nothing.
"""
self.Gene_End_Position = Gene_End_Position
def SetGene_Info_String(self,Gene_Info_String:str):
"""
Normaly there exist an information string about the classification of the certain gene in the gff3 file.
Especially hypothetical genes can make some problems, so the information can be stored for explanation,
if something went wrong.
:param Gene_Info_String: String description of the gene, if the gff3 file holds this information.
:return: Nothing.
"""
self.Gene_Info_String = Gene_Info_String
def AddUTR_Description(self,UTR_Description:list ):
"""
Sometimes the gff3 file contains information about the UTR in some genes.
It can be usefull, if the transcript is somehow damaged from variants.
:param UTR_Description: String from the gff3 file with the UTR description.
:return: Nothing.
"""
self.UTR_Description.append(UTR_Description)
def AddEXON_Descriptin(self,EXON_Descriptin:list):
"""
Sometimes the gff3 file contains information about the exon in some genes.
It can be usefull, if the transcript is somehow damaged from variants.
:param EXON_Descriptin: String from the gff3 file with the exon description.
:return: Nothing
"""
self.EXON_Descriptin.append(EXON_Descriptin)
def change_Last_CDS_Position(self, length: int):
"""
Updates the CDS Position inside the ListofCDS list.
Positive values: Longer CDS
Negative values: smaller CDS
:return: Nothing.
"""
self.CDS_Changed = True
if self.ForwardDirection == TranscriptEnum.FORWARD:
if length < 0:
currentLastCDSLength = abs(self.ListofCDS[len(self.ListofCDS)-1][0] - self.ListofCDS[len(self.ListofCDS)-1][1])
while currentLastCDSLength < abs(length):
del(self.ListofCDS[len(self.ListofCDS)-1])
length = -abs(currentLastCDSLength + length)
currentLastCDSLength = abs(self.ListofCDS[len(self.ListofCDS) - 1][0] - self.ListofCDS[len(self.ListofCDS) - 1][1])
self.ListofCDS[len(self.ListofCDS)-1][1] = self.LastCDSPosition + length
self.LastCDSPosition += length
elif self.ForwardDirection == TranscriptEnum.REVERSE:
if length < 0:
currentLastCDSLength = (abs(self.ListofCDS[0][0] - self.ListofCDS[0][1]))
while currentLastCDSLength < abs(length):
del(self.ListofCDS[0])
length = -abs(currentLastCDSLength + length)
currentLastCDSLength = (abs(self.ListofCDS[0][0] - self.ListofCDS[0][1]))
self.ListofCDS[0][0] = self.LastCDSPosition - length
self.LastCDSPosition -= length
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No Direction: " + str(self.TID) + "\n")
def Create_IV_OriginalTranslation(self, genetic_code:dict) -> bool:
"""
Create the AminoAcid sequence from the original dna source without any variant effects.
:param genetic_code: A dictionary which translates lowercase triplet RNA to AA. Example: genetic_code = {'agg':'r'}
:return: Bool value if the transcription and translation of the DNA was successful.
"""
if self.ForwardDirection == TranscriptEnum.FORWARD and self.Complete_CDS != "":
self.IV_OriginalTranslation = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(self.Complete_CDS), genetic_code)
return True
elif self.ForwardDirection == TranscriptEnum.REVERSE and self.Rev_CDS != "":
self.IV_OriginalTranslation = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(self.Rev_CDS), genetic_code)
return True
else:
if self.Complete_CDS != "":
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_CDS_CREATION_LOG, "No CDS: " + str(self.TID) + "\n")
#print("No CDS: " + str(self.TID))
return False
elif self.Rev_CDS != "":
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_CDS_CREATION_LOG, "No Rev CDS: " + str(self.TID) + "\n")
#print("No Rev CDS: " + str(self.TID))
return False
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_CDS_CREATION_LOG, "No direction?: " + str(self.TID) + "\n")
#print ("No direction?: " + str(self.TID))
return False
def Create_IV_ChangedTranslation (self, genetic_code: dict) -> bool:
"""
Create the AminoAcid sequence with the original dna source AND with variant effects inside the CDS.
:param genetic_code: A dictionary which translates lowercase triplet RNA to AA. Example: genetic_code = {'agg':'r'}
:return :Bool value if the transcription and translation of the DNA was successful.
"""
if self.ForwardDirection == TranscriptEnum.FORWARD:
self.IV_ChangedTranslation = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(self.IV_Changed_DNA_CDS_Seq), genetic_code)
self.IV_AA_length = len(self.IV_ChangedTranslation)
return True
elif self.ForwardDirection == TranscriptEnum.REVERSE:
self.IV_ChangedTranslation = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(self.IV_Changed_DNA_CDS_Seq), genetic_code)
self.IV_AA_length = len(self.IV_ChangedTranslation)
return True
else:
if self.IV_Changed_DNA_CDS_Seq == "" and self.Complete_CDS == "":
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No CDS: " + str(self.TID) + "\n" )
#print("No CDS: " + str(self.TID))
return False
elif self.IV_Changed_DNA_CDS_Seq == "":
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No Changed_DNA_CDS_Seq, but CDS without changes exist: " + str(self.TID) + "\n")
#For_Type_Safety_and_statics.log.append("No Changed_DNA_CDS_Seq, but CDS without changes exist: " + str(self.TID) + "\n")
return False
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No direction?: " + str(self.TID)+ "\n")
#print("No direction?: " + str(self.TID))
return False
def Create_IV_Changed_DNA_CDS_Seq (self, genetic_code: dict, IntegratedVariantObjects: list, stopcodon: str):
"""
First Step:
Simple classification for every Variant_Information_Storage object in SUB, DEl and INS.
While doing this classification, the new CDS position for every variant will be calculated.
In this step the new DNA sequence of the transcript will be created
Second Step:
For every variant the IV_Local_Classification will be used to create the exact changes inside the CDS.
For every variant the IV_Local_Effect_Length will be used to calculate the length of the effects.
Third Step.
For all variants SetKeysToCombinedEffects will be used to add the information about side effects.
-> After this step every variant contains the information with which other variant it shares an effect.
:param genetic_code: The genetic code as a dictionary.
:param IntegratedVariantObjects: A list from all variants in Variant_Information_Storage format, which all hits the CDS.
:param stopcodon: Which letter stands for the stop codon.
:return: Nothing.
"""
if self.ForwardDirection == TranscriptEnum.FORWARD:
self.IV_Changed_DNA_CDS_Seq = self.Complete_CDS
elif self.ForwardDirection == TranscriptEnum.REVERSE:
#self.Rev_CDS = For_Type_Safety_and_statics.BioReverseSeq(self.Complete_CDS)
self.IV_Changed_DNA_CDS_Seq = self.Rev_CDS
IntegratedVariantObjects = sorted(IntegratedVariantObjects, key = lambda variant_information: variant_information.Unchanged_CDS_Position)
# list needs to be ordered after position, so the new cds position can be calculated.
# because every variants cds position can be changed with previous indels.
for vinfo in IntegratedVariantObjects:
if vinfo.ChrPosition == 5921700 and self.TID == "Ma09_t08910.1":
print('bugsearch')
if self.ForwardDirection == TranscriptEnum.FORWARD:
alt = vinfo.Alt
ref = vinfo.Ref
elif self.ForwardDirection == TranscriptEnum.REVERSE:
alt = vinfo.ReverseAlt
ref = vinfo.ReverseRef
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Transcript without Direction: " + str(self.TID) + "\n")
#print("Transcript without Direction: " + str(self.TID))
continue
cds_position = vinfo.Unchanged_CDS_Position
current_additional_position = self.IV_NewPositionList[len(self.IV_NewPositionList)-1]
vinfo.SetChanged_CDS_Position(cds_position + current_additional_position)
if len(ref) == 1 and len(alt) == 1:
firstkoord = cds_position + current_additional_position -1
###
# important, because seq[0:0] does not work.
# but there can be the case, that the first position will be substituted
###
if firstkoord != 0:
first = self.IV_Changed_DNA_CDS_Seq[0:firstkoord]
else:
first = ""
test = self.IV_Changed_DNA_CDS_Seq[cds_position + current_additional_position - 1]
if test != ref:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"Error 1: SUB not identical with Ref: " + str(
self.TID) + " " + str(vinfo.ChrPosition) + " " + str(self.ForwardDirection) + "\n")
#asdasdasdasd = self.IV_Changed_DNA_CDS_Seq[1128]
#asdasdasdasd2 = self.IV_Changed_DNA_CDS_Seq[1125:1135]
#print("Error 1: SUB not identical with Ref: " + str(self.TID) + " " + str(vinfo.ChrPosition))
substitution = alt
second = self.IV_Changed_DNA_CDS_Seq[cds_position + current_additional_position:]
self.IV_Changed_DNA_CDS_Seq = first + substitution + second
vinfo.Classification.append(TranscriptEnum.SUBSTITUTION)
self.IV_NewPositionList.append(current_additional_position)
self.IV_ListOfEffects.append((vinfo.ChrPosition, vinfo.Unchanged_CDS_Position,current_additional_position))
elif len(ref) > 1 and len(alt) == 1: # del
dellength = (len(ref)-1)
if self.ForwardDirection == TranscriptEnum.REVERSE:
if cds_position + current_additional_position + dellength <= 3 \
and cds_position + current_additional_position + dellength > 0:
first = self.IV_Changed_DNA_CDS_Seq[0:cds_position + current_additional_position -1 ]
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_ADDITIONAL_INFO_LOG, "Note 1: DEL removed start: " + str(self.TID) + "\t" + str(vinfo.ChrPosition) + "\n")
#print("Note 1: DEL removed start: " + str(self.TID) + "\t" + str(vinfo.ChrPosition))
vinfo.Classification.append(TranscriptEnum.START_LOST)
elif cds_position + current_additional_position + dellength <= 0:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_ADDITIONAL_INFO_LOG,"Note 1.1: DEL destroyed start exon: " + str(self.TID) + "\t" + str(vinfo.ChrPosition) + "\n")
#print("Note 1.1: DEL destroyed start exon: " + str(self.TID) + "\t" + str(vinfo.ChrPosition))
vinfo.Classification.append(TranscriptEnum.CDS_START_INVOLVED)
first = ""
else:
first = self.IV_Changed_DNA_CDS_Seq[0:cds_position + current_additional_position -1 ]
second = self.IV_Changed_DNA_CDS_Seq[cds_position + dellength + current_additional_position -1:]
if second[0] != ref[len(ref) - 1]:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,"Error 2: DEL not identical with Ref: " + str(self.TID) +"\t"+ str(vinfo.ChrPosition) + "\n" )
#print("Error 2: DEL not identical with Ref: " + str(self.TID) + str(vinfo.ChrPosition))
else:
first = self.IV_Changed_DNA_CDS_Seq[0:cds_position + current_additional_position]
second = self.IV_Changed_DNA_CDS_Seq[cds_position + current_additional_position + dellength:]
if first != "":
if first[len(first) - 1] != ref[0]:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error 3: DEL not identical with Ref: " + str(self.TID) +"\t"+ str(vinfo.ChrPosition) + "\n")
#print("Error 3: DEL not identical with Ref: " + str(self.TID) + str(vinfo.ChrPosition))
self.IV_Changed_DNA_CDS_Seq = first + second
self.IV_NewPositionList.append(current_additional_position - (-1 + len(ref)))
self.IV_ListOfEffects.append((vinfo.ChrPosition, vinfo.Unchanged_CDS_Position,current_additional_position - (-1 + len(ref))))
vinfo.Classification.append(TranscriptEnum.DELETION)
elif len(ref) == 1 and len(alt) > 1: #insert
test = self.IV_Changed_DNA_CDS_Seq[cds_position + current_additional_position - 1]
first = self.IV_Changed_DNA_CDS_Seq[0:cds_position + current_additional_position - 1]
insert = alt
second = self.IV_Changed_DNA_CDS_Seq[cds_position + current_additional_position:]
self.IV_Changed_DNA_CDS_Seq = first + insert + second
vinfo.Classification.append(TranscriptEnum.INSERTION)
self.IV_NewPositionList.append(current_additional_position + (-1 + len(alt)))
self.IV_ListOfEffects.append((vinfo.ChrPosition, vinfo.Unchanged_CDS_Position,current_additional_position + (-1 + len(alt))))
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Create_IV_IV_Changed_DNA_CDS_Seq - error?"+ str(self.TID) + str(vinfo.ChrPosition) + "\n")
#print("Create_IV_IV_Changed_DNA_CDS_Seq - error?"+ str(self.TID) + str(vinfo.ChrPosition) + "\n")
self.IV_NewPositionList.append(current_additional_position)
self.IV_ListOfEffects.append((vinfo.ChrPosition, vinfo.Unchanged_CDS_Position,current_additional_position))
continue
###
# after every mutation is inside the new cds:
# start with classification, its important, that every entry is inside, because of sideeffects
#
###
for vinfo in IntegratedVariantObjects:
self.origDNAtoshort = False
self.IV_Local_Classification(vinfo, genetic_code, stopcodon)
self.IV_Local_Effect_Length(vinfo)
self.IV_DNA_length = len(self.IV_Changed_DNA_CDS_Seq)
#IntegratedVariantObjects = self.updateIntegratedVariantObjectsList(IntegratedVariantObjects)
self.SetKeysToCombinedEffects(IntegratedVariantObjects)
def SetKeysToCombinedEffects(self, IntegratedVariantObjects: list):
"""
Every variant, which has an effect to another variant will be calculated inside this function.
Example: A variant which will cause a frameshift get the keys from every variant after this frameshift.
Every variant inside this frameshift will get the key from the one it caused it.
:param IntegratedVariantObjects: List of all classified variants. They all needs to have the effect length already.
:return: Nothing.
"""
if len(IntegratedVariantObjects) > 0:
vinfo = For_Type_Safety_and_statics.Variant_Information_Storage_Type_Safety(IntegratedVariantObjects[0])
listWithVariants = [vinfo]
#intForFrameshifts = 0
Marked = False
in_the_end = False
for i in range(1, len(IntegratedVariantObjects)):
current_vinfo = For_Type_Safety_and_statics.Variant_Information_Storage_Type_Safety(IntegratedVariantObjects[i])
listed_for_deletion = []
for old_vinfo in listWithVariants:
if old_vinfo.StartOfOwnEffect == current_vinfo.StartOfOwnEffect:
Marked = True
elif old_vinfo.EndOfOwnEffect == VariantEnum.NO_EndOfOwnEffect:
if TranscriptEnum.STOP_GAINED in old_vinfo.Classification:
#if TranscriptEnum.STOP_GAINED in current_vinfo.Classification:
if TranscriptEnum.DELETION in old_vinfo.Classification:
endeffect_without_stop = old_vinfo.Changed_CDS_Position + (2 - old_vinfo.Changed_Raster)
elif TranscriptEnum.INSERTION in old_vinfo.Classification:
endeffect_without_stop = old_vinfo.Changed_CDS_Position + (len(old_vinfo.Alt) - 1) + (
2 - old_vinfo.Changed_Raster)
elif TranscriptEnum.SUBSTITUTION in old_vinfo.Classification \
or TranscriptEnum.AA_CHANGE in old_vinfo.Classification:
endeffect_without_stop = old_vinfo.Changed_CDS_Position + (2 - old_vinfo.Changed_Raster)
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error: SetKeysToCombinedEffects:" + str(self.TID)+
"\t" + str(old_vinfo.ChrPosition) +
"\t" + str(current_vinfo.ChrPosition) + "\n")
#print("Error: SetKeysToCombinedEffects:" + str(self.TID)+
# "\t" + str(old_vinfo.ChrPosition) +
# "\t" + str(current_vinfo.ChrPosition) + "\n")
break
#if endeffect_without_stop >= current_vinfo.StartOfOwnEffect:
Marked = True
#else:
# Marked = False
# in_the_end = True # after stop nothing matters
# break
else:
Marked = True
elif old_vinfo.EndOfOwnEffect >= current_vinfo.StartOfOwnEffect:
Marked = True
else:
listed_for_deletion.append(old_vinfo)
#listWithVariants.remove(old_vinfo)
if Marked:
old_vinfo.SharedEffectsWith.append(current_vinfo)
current_vinfo.SharedEffectsWith.append(old_vinfo)
Marked = False
if len(listed_for_deletion) > 0:
for deleteit in listed_for_deletion:
if deleteit == []:
pass
listWithVariants.remove(deleteit)
if in_the_end: # stop == nothing else matters
# Look 14 lines above, to reactivate this
if len(current_vinfo.SharedEffectsWith) > 0: # if there are more effects before the stop, they have to be removed
for vinfo_in_shared_effects in current_vinfo.SharedEffectsWith:
vinfo_in_shared_effects.SharedEffectsWith.remove(current_vinfo)
current_vinfo.SharedEffectsWith.remove(vinfo_in_shared_effects)
break
listWithVariants.append(current_vinfo)
def RasterZero (self, dna:str, vinfo):
return dna[vinfo.Unchanged_CDS_Position-1:vinfo.Unchanged_CDS_Position+2]
def RasterOne (self, dna:str, vinfo):
return dna[vinfo.Unchanged_CDS_Position-2:vinfo.Unchanged_CDS_Position+1]
def RasterTwo (self, dna:str, vinfo):
return dna[vinfo.Unchanged_CDS_Position-3:vinfo.Unchanged_CDS_Position]
def RasterZeroChanged (self, dna:str, vinfo):
return dna[vinfo.Changed_CDS_Position-1:vinfo.Changed_CDS_Position+2]
def RasterOneChanged (self, dna:str, vinfo):
return dna[vinfo.Changed_CDS_Position-2:vinfo.Changed_CDS_Position+1]
def RasterTwoChanged (self, dna:str, vinfo):
return dna[vinfo.Changed_CDS_Position-3:vinfo.Changed_CDS_Position]
def prematureStopCodon(self, stopcodon):
stopStartPositionInChangedCDS = 1 + (self.IV_ChangedTranslation.find(stopcodon)) * 3
stopEndPositionInChangedCDS = 1 + (1+self.IV_ChangedTranslation.find(stopcodon)) * 3
lastPossibleChrPosition = 0
for tripple in self.IV_ListOfEffects:
chrPos = tripple[0]
cdsPos = tripple[1]
change = tripple[2]
if cdsPos + change <= stopStartPositionInChangedCDS:
lastPossibleChrPosition = chrPos
continue
elif cdsPos + change <= stopEndPositionInChangedCDS:
lastPossibleChrPosition = chrPos
continue
else:
break
self.removeOutsiderVariants(lastPossibleChrPosition)
def removeOutsiderVariants(self, ChrPosition:int):
markedForDeletion = []
if self.ForwardDirection == TranscriptEnum.FORWARD:
for vinfo in self.IntegratedVariantObjects_CDS_Hits:
if vinfo.ChrPosition > ChrPosition:
markedForDeletion.append(vinfo)
else:
for vinfo in self.IntegratedVariantObjects_CDS_Hits:
if vinfo.ChrPosition < ChrPosition:
markedForDeletion.append(vinfo)
for vinfo in markedForDeletion:
self.IntegratedVariantObjects_CDS_Hits.remove(vinfo)
self.IntegratedVariantObjects_NotCDS.append(vinfo)
def IV_Local_Classification(self,vinfo: Variant_Information_Storage, genetic_code: dict, stopcodon: str):
"""
Adds (and calculates) following information to the Variant_Information_Storage object:
OrigTriplets -> original codons for the position of the variant.
ChangedTriplets -> codons for the NEW position in the NEW transcript.
Classifications -> FRAMESHIFT_1; FRAMESHIFT_2; FRAMESHIFT_1_DEL; FRAMESHIFT_2_DEL;
-> STOP_LOST; STOP_GAINED; AA_CHANGE
:param vinfo: A single Variant_Information_Storage object.
:param genetic_code: Dictionary of the genetic code.
:param stopcodon: Character of the stopcodon.
:return: Nothing.
"""
chrPos = vinfo.ChrPosition
new_Raster = vinfo.Changed_Raster
OrigRaster = vinfo.OrigRaster
cdsPosition = vinfo.Unchanged_CDS_Position
cdsPositionChanged = vinfo.Changed_CDS_Position
if self.ForwardDirection == TranscriptEnum.FORWARD:
Forward = True
current_CDS = self.Complete_CDS
elif self.ForwardDirection == TranscriptEnum.REVERSE:
Forward = False
current_CDS = self.Rev_CDS
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error: Direction: " + str(self.TID) +" " + str(chrPos) + "\n")
#print ("Error: Direction: " + str(self.TID) +" " + str(chrPos) + "\n")
return False
if TranscriptEnum.SUBSTITUTION in vinfo.Classification:
if OrigRaster == 0:
OrigTriplets = self.RasterZero(current_CDS, vinfo)
elif OrigRaster == 1:
OrigTriplets = self.RasterOne(current_CDS, vinfo)
elif OrigRaster == 2:
OrigTriplets = self.RasterTwo(current_CDS, vinfo)
else:
#print("(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(OrigRaster) + "\n")
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(OrigRaster) + "\n")
return False
if new_Raster == 0:
ChangedTriplets = self.RasterZeroChanged(self.IV_Changed_DNA_CDS_Seq, vinfo)
elif new_Raster == 1:
ChangedTriplets = self.RasterOneChanged(self.IV_Changed_DNA_CDS_Seq, vinfo)
elif new_Raster == 2:
ChangedTriplets = self.RasterTwoChanged(self.IV_Changed_DNA_CDS_Seq, vinfo)
else:
#print("Error: " + str(self.TID) + " " + str(chrPos))
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
new_Raster) + "\n")
return False
if Forward:
vinfo.OrigTriplets = OrigTriplets
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(OrigTriplets), genetic_code)
else:
vinfo.OrigTriplets = For_Type_Safety_and_statics.BioReverseSeq(OrigTriplets)
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(OrigTriplets), genetic_code)
vinfo.OrigAmino = vinfo.OrigAmino[::-1]
if Forward:
vinfo.ChangedTriplets = ChangedTriplets
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(ChangedTriplets), genetic_code)
else:
vinfo.ChangedTriplets = For_Type_Safety_and_statics.BioReverseSeq(ChangedTriplets)
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(ChangedTriplets), genetic_code)
vinfo.NewAmino = vinfo.NewAmino[::-1]
elif TranscriptEnum.INSERTION in vinfo.Classification:
###
#
# Rasterchange = (len(Alt) -1) % 3
# Raster Rasterchange (Normal without change) Before Next
# 0 0 2 0 2
# 0 1 2 0 1
# 0 2 2 0 0
#
# 1 0 1 1 1
# 1 1 1 1 0
# 1 2 1 1 2
#
# 2 0 0 2 0
# 2 1 0 2 2
# 2 2 0 2 1
###
RasterChange = (len(vinfo.Alt) -1) % 3
if RasterChange == 1:
vinfo.Classification.append(TranscriptEnum.FRAMESHIFT_1)
elif RasterChange == 2:
vinfo.Classification.append(TranscriptEnum.FRAMESHIFT_2)
if OrigRaster == 0 :
#before = ""
before = current_CDS[cdsPosition-1:cdsPosition+2]
next = ""
elif OrigRaster == 1:
#before = current_CDS[cdsPosition-2:cdsPosition-1]
before = current_CDS[cdsPosition-2:cdsPosition + 1]
next = ""
elif OrigRaster == 2:
#before = current_CDS[cdsPosition-3:cdsPosition-1]
before = current_CDS[cdsPosition-3:cdsPosition]
next = ""
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
OrigRaster) + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if new_Raster == 0:
before2 = ""
elif new_Raster == 1:
before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-2:cdsPositionChanged-1]
elif new_Raster == 2:
before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-3:cdsPositionChanged-1]
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
new_Raster) + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if new_Raster == 0 and RasterChange == 0:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 2 + len(vinfo.Alt) - 1]
elif new_Raster == 0 and RasterChange == 1:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 1 + len(vinfo.Alt) - 1]
elif new_Raster == 0 and RasterChange == 2:
next2 = ""
elif new_Raster == 1 and RasterChange == 0:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 1 + len(vinfo.Alt) - 1]
elif new_Raster == 1 and RasterChange == 1:
next2 = ""
elif new_Raster == 1 and RasterChange == 2:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 2 + len(vinfo.Alt) - 1]
elif new_Raster == 2 and RasterChange == 0:
next2 = ""
elif new_Raster == 2 and RasterChange == 1:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 2 + len(vinfo.Alt) - 1]
elif new_Raster == 2 and RasterChange == 2:
next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Alt) - 1: cdsPositionChanged + 1 + len(vinfo.Alt) - 1]
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
new_Raster) + " " + str(RasterChange) + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if Forward:
vinfo.OrigTriplets = before + next
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(vinfo.OrigTriplets), genetic_code)
else:
vinfo.OrigTriplets = For_Type_Safety_and_statics.BioReverseSeq(before + next)
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(before + next), genetic_code)
vinfo.OrigAmino = vinfo.OrigAmino[::-1]
if Forward:
vinfo.ChangedTriplets = before2 + vinfo.Alt + next2
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(vinfo.ChangedTriplets), genetic_code)
else:
vinfo.ChangedTriplets = For_Type_Safety_and_statics.BioReverseSeq(before2 + For_Type_Safety_and_statics.BioReverseSeq(vinfo.Alt) + next2)
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(before2 + For_Type_Safety_and_statics.BioReverseSeq(vinfo.Alt) + next2), genetic_code)
vinfo.NewAmino = vinfo.NewAmino[::-1]
elif TranscriptEnum.DELETION in vinfo.Classification:
RasterChange = (len(vinfo.Ref) - 1) % 3
if RasterChange == 1:
vinfo.Classification.append(TranscriptEnum.FRAMESHIFT_1_DEL)
elif RasterChange == 2:
vinfo.Classification.append(TranscriptEnum.FRAMESHIFT_2_DEL)
if OrigRaster == 0:
#before = current_CDS[cdsPosition - 1:cdsPosition] # del position
#next = current_CDS[cdsPosition + len(vinfo.Ref) -1 :cdsPosition + len(vinfo.Ref) -1 +2]
before = ""
next = ""
elif OrigRaster == 1:
#before = current_CDS[cdsPosition - 2:cdsPosition] #del position, too
#next = current_CDS[cdsPosition +len(vinfo.Ref) -1 :cdsPosition +len (vinfo.Ref)-1 +1]
before = current_CDS[cdsPosition - 2:cdsPosition-1]
next = ""
elif OrigRaster == 2:
before = current_CDS[cdsPosition - 3:cdsPosition-1]
next = ""
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
OrigRaster) + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if OrigRaster == 0 and RasterChange == 0:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 2]
elif OrigRaster == 0 and RasterChange == 1:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 1]
elif OrigRaster == 0 and RasterChange == 2:
next = ""
elif OrigRaster == 1 and RasterChange == 0:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 1]
elif OrigRaster == 1 and RasterChange == 1:
next = ""
elif OrigRaster == 1 and RasterChange == 2:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 2]
elif OrigRaster == 2 and RasterChange == 0:
next = ""
elif OrigRaster == 2 and RasterChange == 1:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 2]
elif OrigRaster == 2 and RasterChange == 2:
next = current_CDS[cdsPosition + len(vinfo.Ref) - 1: cdsPosition + len(vinfo.Ref) - 1 + 1]
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
OrigRaster) + " " + RasterChange + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if new_Raster == 0:
#before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged - 1: cdsPositionChanged + 2]
# next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Ref) -1: cdsPositionChanged +len(vinfo.Ref) -1 +2]
before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged - 1: cdsPositionChanged + 2]
next2 = ""
elif new_Raster == 1:
#before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-2 : cdsPositionChanged + 1]
#next2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged + len(vinfo.Ref) -1 : cdsPositionChanged + len(vinfo.Ref)-1 +1]
before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-2 : cdsPositionChanged + 1]
next2 = ""
elif new_Raster == 2:
#before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-3: cdsPositionChanged]
before2 = self.IV_Changed_DNA_CDS_Seq[cdsPositionChanged-3: cdsPositionChanged]
next2 = ""
else :
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"(Impossible) Raster Error: " + str(self.TID) + " " + str(chrPos) + " " + str(
new_Raster) + "\n")
#print("Error: " + str(self.TID) + " " + str(chrPos))
return False
if Forward:
vinfo.OrigTriplets = before + vinfo.Ref +next
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(vinfo.OrigTriplets), genetic_code)
else:
vinfo.OrigTriplets = For_Type_Safety_and_statics.BioReverseSeq(before + For_Type_Safety_and_statics.BioReverseSeq(vinfo.Ref) + next)
vinfo.OrigAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(before + For_Type_Safety_and_statics.BioReverseSeq(vinfo.Ref) + next), genetic_code)
vinfo.OrigAmino = vinfo.OrigAmino[::-1]
if Forward:
vinfo.ChangedTriplets = before2 + next2
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(vinfo.ChangedTriplets), genetic_code)
else:
vinfo.ChangedTriplets = For_Type_Safety_and_statics.BioReverseSeq(before2 + next2)
vinfo.NewAmino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(before2 + next2), genetic_code)
vinfo.NewAmino = vinfo.NewAmino[::-1]
origAmino = vinfo.OrigAmino
newAmino = vinfo.NewAmino
vinfo.OrigRevTriplets = For_Type_Safety_and_statics.BioReverseSeq(vinfo.OrigTriplets)
if stopcodon in origAmino and not stopcodon in newAmino:
vinfo.Classification.append(TranscriptEnum.STOP_LOST)
self.Lost_Stop = True
self.Calculate_Last_CDS_Position()
elif stopcodon in newAmino and not stopcodon in origAmino:
vinfo.Classification.append(TranscriptEnum.STOP_GAINED)
elif stopcodon in newAmino and stopcodon in origAmino:
if len(newAmino) == len(origAmino):
vinfo.Classification.append(TranscriptEnum.STOP_CHANGED)
elif TranscriptEnum.SUBSTITUTION in vinfo.Classification:
vinfo.Classification.append(TranscriptEnum.STOP_CHANGED)
elif TranscriptEnum.DELETION in vinfo.Classification:
vinfo.Classification.append(TranscriptEnum.STOP_CHANGED)
elif TranscriptEnum.INSERTION in vinfo.Classification:
if vinfo.NewAmino[0] == stopcodon:
vinfo.Classification.append(TranscriptEnum.STOP_CHANGED)
else:
vinfo.Classification.append(TranscriptEnum.STOP_LOST)
vinfo.Classification.append(TranscriptEnum.STOP_GAINED)
elif origAmino != newAmino:
vinfo.Classification.append(TranscriptEnum.AA_CHANGE)
if stopcodon in self.IV_ChangedTranslation:
self.Lost_Stop = False
if len(vinfo.ChangedTriplets) % 3 != 0 or len(vinfo.OrigTriplets) % 3 != 0 or len(vinfo.OrigRevTriplets) % 3 != 0 or len(vinfo.ChangedRevTriplets) % 3 != 0:
self.origDNAtoshort = True # not really orgiDNA, others too, but hey, it works
if 'n' in vinfo.ChangedTriplets.lower():
vinfo.Classification.append(TranscriptEnum.UNKNOWN_NUKLEOTIDE)
if 'x' in vinfo.NewAmino.lower():
vinfo.Classification.append(TranscriptEnum.UNKNOWN_AMINOACID)
def IV_Local_Effect_Length(self, vinfo: Variant_Information_Storage):
"""
Calculates the effect length and add it to a single Variant_Information_Storage (object).
The starteffect is always a position, because every variant in here is inside the transcript.
The endeffect can be a position and the NO_EndOfOwnEffect enum value.
Frameshifts or other high impact effects (Stop) will effect every following variant.
:param vinfo: A single Variant_Information_Storage object, already containing its classifications.
:return: False, if anything went wrong.
"""
starteffect = vinfo.Changed_CDS_Position - vinfo.Changed_Raster
classification = vinfo.Classification
if TranscriptEnum.STOP_GAINED in classification \
or TranscriptEnum.STOP_LOST in classification \
or TranscriptEnum.FRAMESHIFT in classification \
or TranscriptEnum.FRAMESHIFT_1 in classification \
or TranscriptEnum.FRAMESHIFT_2 in classification \
or TranscriptEnum.FRAMESHIFT_1_DEL in classification \
or TranscriptEnum.FRAMESHIFT_2_DEL in classification:
if TranscriptEnum.FRAMESHIFT in classification:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Still FRAMESHIFT in use." + "\n" )
endeffect = VariantEnum.NO_EndOfOwnEffect
elif TranscriptEnum.DELETION in classification:
endeffect = vinfo.Changed_CDS_Position + (2-vinfo.Changed_Raster)
elif TranscriptEnum.INSERTION in classification:
endeffect = vinfo.Changed_CDS_Position + (len(vinfo.Alt)-1) + (2-vinfo.Changed_Raster)
elif TranscriptEnum.SUBSTITUTION in classification or TranscriptEnum.AA_CHANGE in classification:
endeffect = vinfo.Changed_CDS_Position + (2-vinfo.Changed_Raster)
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error in IV_Local_Effect_Length: " + str(self.TID) + " " + str(vinfo.ChrPosition) + "\n")
#print("Error in IV_Local_Effect_Length: " + str(self.TID) + " " + str(vinfo.ChrPosition))
return False
vinfo.StartOfOwnEffect = starteffect
vinfo.EndOfOwnEffect = endeffect
def Calculate_Last_CDS_Position(self):
"""
The last position of the CDS in the chromosome may be needed to extend the cds.
:return: The last position of the CDS in the chromosome. In reverse direction it
is of course the position on the left side.
"""
if self.LastCDSPosition != 0 or len(self.ListofCDS) == 0:
return False
if self.ForwardDirection == TranscriptEnum.FORWARD:
self.LastCDSPosition = self.ListofCDS[len(self.ListofCDS)-1][1]
elif self.ForwardDirection == TranscriptEnum.REVERSE:
self.LastCDSPosition = self.ListofCDS[0][0]
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No Direction: " + str(self.TID) + "\n")
#print ("No Direction: " + str(self.TID))
def update_Last_CDS_Position(self):
"""
Updates the CDS Position inside the ListofCDS list.
:return: Nothing.
"""
if self.ForwardDirection == TranscriptEnum.FORWARD:
self.ListofCDS[len(self.ListofCDS)-1][1] = self.LastCDSPosition
elif self.ForwardDirection == TranscriptEnum.REVERSE:
self.ListofCDS[0][0] = self.LastCDSPosition
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "No Direction: " + str(self.TID) + "\n")
def Find_New_Stop(self, nextDNA:str , genetic_code:dict , stopcodon: str):
"""
Uses the IV_Changed_DNA_CDS_Seq and add the nextDNA, translates it and search for a new stopcodon.
:param nextDNA: DNA, which will be added to the existing transcript.
:param genetic_code: Dictionary, used for translation.
:param stopcodon: Char, which will be used as stop.
:return: False, if there is no new stop.
"""
currentRaster = For_Type_Safety_and_statics.calculateRaster(len(self.IV_Changed_DNA_CDS_Seq))
###
# len -1 % 3 --> last position is inside raster x
###
# 0 -> last position + new
# 1 -> last -1 + last + new
# 2 -> last -2 + last -1 + last + new -----> only new
###
# new stop position
# dna to this code -< append changed_cds
###
if self.ForwardDirection == TranscriptEnum.FORWARD:
if currentRaster == 0:
dnaToTest = self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-1] + nextDNA
oldDNA = 1
elif currentRaster == 1:
dnaToTest = self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-2] + self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-1] + nextDNA
oldDNA = 2
elif currentRaster == 2:
dnaToTest = nextDNA
oldDNA = 0
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error in find_New_Stop: " + str(self.TID) + " " + str(currentRaster) + "\n" )
#print ("Error in find_New_Stop: " + str(self.TID) + " " + str(currentRaster) + "\n" )
return False
elif self.ForwardDirection == TranscriptEnum.REVERSE:
if currentRaster == 0:
dnaToTest = self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-1] + For_Type_Safety_and_statics.BioReverseSeq(nextDNA)
oldDNA = 1
elif currentRaster == 1:
dnaToTest = self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-2] + self.IV_Changed_DNA_CDS_Seq[len(self.IV_Changed_DNA_CDS_Seq)-1] + For_Type_Safety_and_statics.BioReverseSeq(nextDNA)
oldDNA = 2
elif currentRaster == 2:
dnaToTest = For_Type_Safety_and_statics.BioReverseSeq(nextDNA)
oldDNA = 0
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG, "Error in find_New_Stop: " + str(self.TID) + " " + str(currentRaster) + "\n" )
#print ("Error in find_New_Stop: " + str(self.TID) + " " + str(currentRaster) + "\n" )
return False
else:
LogOrganizer.addToLog(LogEnums.TRANSCRIPT_BUGHUNTING_LOG,
"Error in find_New_Stop, not transcript direction: " + str(self.TID) + " " + str(currentRaster) + "\n")
return False
new_Amino = For_Type_Safety_and_statics.Translation(For_Type_Safety_and_statics.Transcription(dnaToTest), genetic_code)
position_in_string = new_Amino.find(stopcodon)
if position_in_string != -1:
###