Skip to content

Commit 577f01c

Browse files
Simplified how the Dseqrecord __add__ handles features. (#598)
* Simplified how the Dseqrecord __add__ handles features. Now it simply observes the difference between the length of the separate parts and the ligated fragment without calling seq object methods. Also only one loop to push features. * Removed duplication and improved how adding something that is not a Dseqrecord/Dseq is handled. * fixed tailed primer * reset kernel name
1 parent b36f079 commit 577f01c

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

docs/notebooks/Example_Restriction.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@
585585
"name": "stdout",
586586
"output_type": "stream",
587587
"text": [
588-
"ACCATGTCGACATGCAAACAGTAATGATGGA , Tm: 57.24061148156318\n",
589-
"GGCGCGCCATTAAAAGCCTTCTTCTCCC , Tm: 56.64459495003314\n"
588+
"ACCATGTCGACATGCAAACAGTAATGATGGA , Tm: 58.57602926085667\n",
589+
"GGCGCGCCATTAAAAGCCTTCTTCTCCC , Tm: 58.36015907667411\n"
590590
]
591591
}
592592
],
@@ -603,8 +603,8 @@
603603
"amplicon = primer_design(pombe_chromosome_I[min(gene):max(gene)], target_tm=55)\n",
604604
"\n",
605605
"fwd_align, rvs_align = amplicon.primers()\n",
606-
"fwd_primer_ase1 = Dseqrecord(\"ACCATGTCGAC\") + fwd_align # Adding a SalI cut site\n",
607-
"rvs_primer_ase1 = Dseqrecord(\"GGCGCGCCAT\") + rvs_align # Adding a AscI cut site\n",
606+
"fwd_primer_ase1 = \"ACCATGTCGAC\" + fwd_align # Adding a SalI cut site\n",
607+
"rvs_primer_ase1 = \"GGCGCGCCAT\" + rvs_align # Adding a AscI cut site\n",
608608
"\n",
609609
"# Printing out the primers\n",
610610
"\n",
@@ -622,13 +622,13 @@
622622
"output_type": "stream",
623623
"text": [
624624
"LOCUS 2263bp_PCR_prod 2263 bp DNA linear UNK 01-JAN-1980\n",
625-
"DEFINITION pcr_product_description_description.\n",
625+
"DEFINITION pcr_product_f2242 CU329670.1_r2242 CU329670.1.\n",
626626
"ACCESSION 2263bp\n",
627627
"VERSION 2263bp\n",
628628
"DBLINK BioProject: PRJNA13836\n",
629629
" BioSample: SAMEA3138176\n",
630630
"KEYWORDS .\n",
631-
"SOURCE .\n",
631+
"SOURCE \n",
632632
" ORGANISM .\n",
633633
" .\n",
634634
"FEATURES Location/Qualifiers\n",
@@ -653,13 +653,13 @@
653653
" NVPLSPPKQRVVNEHALNIMSEKLQRTNLKEQTPEMDIENSSQNLPFSPMKISPIRASP\n",
654654
" VKTIPSSPSPTTNIFSAPLNNITNCTPMEDEWGEEGF\"\n",
655655
" primer_bind 12..31\n",
656-
" /label=\"name\"\n",
656+
" /label=\"f2242\"\n",
657657
" /PCR_conditions=\"primer\n",
658658
" sequence:ACCATGTCGACATGCAAACAGTAATGATGGA\"\n",
659659
" /ApEinfo_fwdcolor=\"#baffa3\"\n",
660660
" /ApEinfo_revcolor=\"#ffbaba\"\n",
661661
" primer_bind complement(2236..2254)\n",
662-
" /label=\"name\"\n",
662+
" /label=\"r2242\"\n",
663663
" /PCR_conditions=\"primer\n",
664664
" sequence:GGCGCGCCATTAAAAGCCTTCTTCTCCC\"\n",
665665
" /ApEinfo_fwdcolor=\"#baffa3\"\n",
@@ -759,7 +759,7 @@
759759
"ACCESSION id\n",
760760
"VERSION id\n",
761761
"KEYWORDS .\n",
762-
"SOURCE .\n",
762+
"SOURCE \n",
763763
" ORGANISM .\n",
764764
" .\n",
765765
"FEATURES Location/Qualifiers\n",
@@ -861,13 +861,13 @@
861861
" NVPLSPPKQRVVNEHALNIMSEKLQRTNLKEQTPEMDIENSSQNLPFSPMKISPIRASP\n",
862862
" VKTIPSSPSPTTNIFSAPLNNITNCTPMEDEWGEEGF\"\n",
863863
" primer_bind 3918..3937\n",
864-
" /label=\"name\"\n",
864+
" /label=\"f2242\"\n",
865865
" /PCR_conditions=\"primer\n",
866866
" sequence:ACCATGTCGACATGCAAACAGTAATGATGGA\"\n",
867867
" /ApEinfo_fwdcolor=\"#baffa3\"\n",
868868
" /ApEinfo_revcolor=\"#ffbaba\"\n",
869869
" primer_bind complement(6142..6160)\n",
870-
" /label=\"name\"\n",
870+
" /label=\"r2242\"\n",
871871
" /PCR_conditions=\"primer\n",
872872
" sequence:GGCGCGCCATTAAAAGCCTTCTTCTCCC\"\n",
873873
" /ApEinfo_fwdcolor=\"#baffa3\"\n",
@@ -1008,9 +1008,9 @@
10081008
"name": "python",
10091009
"nbconvert_exporter": "python",
10101010
"pygments_lexer": "ipython3",
1011-
"version": "3.12.2"
1011+
"version": "3.12.7"
10121012
}
10131013
},
10141014
"nbformat": 4,
1015-
"nbformat_minor": 2
1015+
"nbformat_minor": 4
10161016
}

src/pydna/dseqrecord.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -812,22 +812,24 @@ def _repr_pretty_(self, p, cycle):
812812

813813
def __add__(self, other):
814814
if hasattr(other, "seq") and hasattr(other.seq, "watson"):
815+
# other is likely another Dseqrecord with a Dseq object
816+
# deepcopy is necessary since we will change other's features
815817
other = copy.deepcopy(other)
816-
other_five_prime = other.seq.five_prime_end()
817-
if other_five_prime[0] == "5'":
818-
# add other.seq.ovhg
819-
for f in other.features:
820-
f.location = f.location + other.seq.ovhg
821-
elif other_five_prime[0] == "3'":
822-
# subtract other.seq.ovhg (sign change)
823-
for f in other.features:
824-
f.location = f.location + (-other.seq.ovhg)
825-
826-
answer = Dseqrecord(SeqRecord.__add__(self, other))
827-
answer.n = min(self.n, other.n)
818+
newseq = self.seq + other.seq
819+
# offset is the length of the self Dseq object added to the
820+
# other Dseq object minus the sum of each length
821+
# offset is <= 0
822+
offset = len(newseq) - (len(self) + len(other))
823+
for f in other.features:
824+
# adding an integer to a feature location shifts it.
825+
f.location = f.location + offset
828826
else:
829-
answer = Dseqrecord(SeqRecord.__add__(self, Dseqrecord(other)))
830-
answer.n = self.n
827+
# If other is not a Dseqrecord with a Dseq object, the Dseq class
828+
# handles the result of adding for consistency.
829+
newseq = self.seq + other
830+
answer = Dseqrecord(SeqRecord.__add__(self, other))
831+
answer.n = min(self.n, getattr(other, "n", self.n))
832+
answer.seq = newseq
831833
return answer
832834

833835
def __mul__(self, number):

0 commit comments

Comments
 (0)