From 54150395a95309adb4da103259f0628453d5d93c Mon Sep 17 00:00:00 2001
From: pinyili2 <pinyili2@illinois.edu>
Date: Fri, 2 Aug 2024 22:05:14 -0500
Subject: [PATCH] add

---
 mrdna/readers/Untitled.ipynb | 385 +++++++++++++++++++++++++++++++----
 1 file changed, 349 insertions(+), 36 deletions(-)

diff --git a/mrdna/readers/Untitled.ipynb b/mrdna/readers/Untitled.ipynb
index fad743d..cedb210 100644
--- a/mrdna/readers/Untitled.ipynb
+++ b/mrdna/readers/Untitled.ipynb
@@ -3,9 +3,332 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "id": "5ec2e6b1",
+   "id": "94113dfa",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "             _\n",
+      " _____ ___ _| |___ ___\n",
+      "|     |  _| . |   | .'|\n",
+      "|_|_|_|_| |___|_|_|__,|  v1.0a.dev74  \n",
+      "it/its\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "\n",
+    "\n",
+    "from mrdna.readers.cadnano_segments import *\n",
+    "from cadnano.document import Document\n",
+    "import cadnano"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "40d7cdcf",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Found cadnano version 2 file\n"
+     ]
+    }
+   ],
+   "source": [
+    "json_data=read_json_file(\"test.json\")\n",
+    "part=decode_cadnano_part(json_data)\n",
+    "model=cadnano_part(part)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "id": "4b3748a8",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Found cadnano version 2 file\n"
+     ]
+    }
+   ],
+   "source": [
+    "doc=Document()\n",
+    "cadnano.fileio.v2decode.decode(doc, json_data)\n",
+    "parts = [p for p in doc.getParts()]\n",
+    "part=parts[0]\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "id": "aa8a8cd9",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Oligo_(0.1[38])_1328\t23\t'None\n",
+      "Oligo_(2.1[34])_9584\t35\t'None\n",
+      "Oligo_(1.1[36])_7488\t188\t'None\n",
+      "Oligo_(4.1[39])_4384\t33\t'None\n",
+      "Oligo_(5.0[9])_0240\t23\t'None\n",
+      "Oligo_(1.0[3])_8256\t37\t'None\n",
+      "Oligo_(3.0[0])_3296\t33\t'None\n",
+      "Oligo_(0.1[23])_9088\t21\t'None\n",
+      "VH0\n",
+      "\t <fwd_StrandSet(0)> \t [(5, 36)] \n",
+      "\t\t\t\t ['#0066cc']\n",
+      "\t <rev_StrandSet(0)> \t [(2, 20), (21, 23), (24, 27), (28, 38)] \n",
+      "\t\t\t\t ['#cc0000', '#b8056c', '#f74308', '#1700de']\n",
+      "VH1\n",
+      "\t <fwd_StrandSet(1)> \t [(3, 20), (21, 38)] \n",
+      "\t\t\t\t ['#cc0000', '#b8056c']\n",
+      "\t <rev_StrandSet(1)> \t [(5, 18), (19, 36)] \n",
+      "\t\t\t\t ['#0066cc', '#0066cc']\n",
+      "VH2\n",
+      "\t <fwd_StrandSet(2)> \t [(2, 18), (19, 32)] \n",
+      "\t\t\t\t ['#0066cc', '#0066cc']\n",
+      "\t <rev_StrandSet(2)> \t [(0, 34)] \n",
+      "\t\t\t\t ['#888888']\n",
+      "VH3\n",
+      "\t <fwd_StrandSet(3)> \t [(0, 20), (21, 34)] \n",
+      "\t\t\t\t ['#cc0000', '#888888']\n",
+      "\t <rev_StrandSet(3)> \t [(2, 15), (16, 32)] \n",
+      "\t\t\t\t ['#0066cc', '#0066cc']\n",
+      "VH4\n",
+      "\t <fwd_StrandSet(4)> \t [(9, 15), (16, 39)] \n",
+      "\t\t\t\t ['#0066cc', '#0066cc']\n",
+      "\t <rev_StrandSet(4)> \t [(9, 20), (21, 39)] \n",
+      "\t\t\t\t ['#cc0000', '#888888']\n",
+      "VH5\n",
+      "\t <fwd_StrandSet(5)> \t [(9, 27), (28, 39)] \n",
+      "\t\t\t\t ['#f74308', '#1700de']\n",
+      "\t <rev_StrandSet(5)> \t [(9, 39)] \n",
+      "\t\t\t\t ['#0066cc']\n"
+     ]
+    }
+   ],
+   "source": [
+    "part.__dict__.keys()\n",
+    "\n",
+    "oligos = part.oligos()\n",
+    "for oligo in oligos:\n",
+    "    print(\"{0}\\t{1}\\t\\'{2}\".format(oligo,\n",
+    "                                          oligo.length(),\n",
+    "                                          oligo.sequence()))\n",
+    "\n",
+    "vhs = list(part.getIdNums())  # convert set to list\n",
+    "for vh_id in vhs:         # display first 3 vhs\n",
+    "    fwd_ss, rev_ss = part.getStrandSets(vh_id)\n",
+    "    print('VH{0}'.format(vh_id))\n",
+    "    print('\\t', fwd_ss, '\\t', [s.idxs() for s in fwd_ss.strands()], '\\n\\t\\t\\t\\t',\n",
+    "          [s.getColor() for s in fwd_ss.strands()])\n",
+    "    print('\\t', rev_ss, '\\t', [s.idxs() for s in rev_ss.strands()], '\\n\\t\\t\\t\\t',\n",
+    "          [s.getColor() for s in rev_ss.strands()])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "id": "e0cab15d",
    "metadata": {},
    "outputs": [],
+   "source": [
+    "strands5 = [o.strand5p() for o in part.oligos()]\n",
+    "strands3 = [o.strand3p() for o in part.oligos()]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 26,
+   "id": "9811bf9a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "['__class__',\n",
+       " '__delattr__',\n",
+       " '__dict__',\n",
+       " '__dir__',\n",
+       " '__doc__',\n",
+       " '__eq__',\n",
+       " '__format__',\n",
+       " '__ge__',\n",
+       " '__getattribute__',\n",
+       " '__gt__',\n",
+       " '__hash__',\n",
+       " '__init__',\n",
+       " '__init_subclass__',\n",
+       " '__le__',\n",
+       " '__lt__',\n",
+       " '__module__',\n",
+       " '__ne__',\n",
+       " '__new__',\n",
+       " '__reduce__',\n",
+       " '__reduce_ex__',\n",
+       " '__repr__',\n",
+       " '__setattr__',\n",
+       " '__sizeof__',\n",
+       " '__slots__',\n",
+       " '__str__',\n",
+       " '__subclasshook__',\n",
+       " '__weakref__',\n",
+       " '_decrementLength',\n",
+       " '_incrementLength',\n",
+       " '_is_circular',\n",
+       " '_parent',\n",
+       " '_part',\n",
+       " '_props',\n",
+       " '_setColor',\n",
+       " '_setLength',\n",
+       " '_setLoop',\n",
+       " '_setProperty',\n",
+       " '_signals',\n",
+       " '_strand5p',\n",
+       " '_strandMergeUpdate',\n",
+       " '_strandSplitUpdate',\n",
+       " 'addToPart',\n",
+       " 'applyAbstractSequences',\n",
+       " 'applyColor',\n",
+       " 'applySequence',\n",
+       " 'applySequenceCMD',\n",
+       " 'clearAbstractSequences',\n",
+       " 'connect',\n",
+       " 'deleteLater',\n",
+       " 'destroy',\n",
+       " 'disconnect',\n",
+       " 'displayAbstractSequences',\n",
+       " 'dump',\n",
+       " 'editable_properties',\n",
+       " 'getAbsolutePositionAtLength',\n",
+       " 'getColor',\n",
+       " 'getModelProperties',\n",
+       " 'getName',\n",
+       " 'getNumberOfBasesToEachXover',\n",
+       " 'getOutlineProperties',\n",
+       " 'getProperty',\n",
+       " 'getStrandLengths',\n",
+       " 'isCircular',\n",
+       " 'length',\n",
+       " 'locString',\n",
+       " 'oligoPropertyChangedSignal',\n",
+       " 'oligoRemovedSignal',\n",
+       " 'oligoSelectedChangedSignal',\n",
+       " 'oligoSequenceAddedSignal',\n",
+       " 'oligoSequenceClearedSignal',\n",
+       " 'parent',\n",
+       " 'part',\n",
+       " 'refreshLength',\n",
+       " 'remove',\n",
+       " 'removeFromPart',\n",
+       " 'sequence',\n",
+       " 'sequenceExport',\n",
+       " 'setParent',\n",
+       " 'setPart',\n",
+       " 'setProperty',\n",
+       " 'setStrand5p',\n",
+       " 'shallowCopy',\n",
+       " 'shouldHighlight',\n",
+       " 'signals',\n",
+       " 'splitAtAbsoluteLengths',\n",
+       " 'strand3p',\n",
+       " 'strand5p',\n",
+       " 'undoStack']"
+      ]
+     },
+     "execution_count": 26,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "L=[o for o in part.oligos()]\n",
+    "dir(L[2])\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 25,
+   "id": "86403b4b",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "defaultdict(dict, {0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}})"
+      ]
+     },
+     "execution_count": 25,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "part.insertions()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "5c7cea80",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "{'name': 'NaPart1',\n",
+       " 'color': '#0066cc',\n",
+       " 'is_visible': True,\n",
+       " 'active_phos': None,\n",
+       " 'crossover_span_angle': 45,\n",
+       " 'max_vhelix_length': 42,\n",
+       " 'neighbor_active_angle': '',\n",
+       " 'grid_type': <GridEnum.HONEYCOMB: 2>,\n",
+       " 'virtual_helix_order': [0, 1, 2, 3, 4, 5],\n",
+       " 'is_lattice': True,\n",
+       " <GridEnum.HONEYCOMB: 2>: <GridEnum.NONE: 0>}"
+      ]
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "part.getModelProperties()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "136dcf08",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "             _\n",
+      " _____ ___ _| |___ ___\n",
+      "|     |  _| . |   | .'|\n",
+      "|_|_|_|_| |___|_|_|__,|  v1.0a.dev74  \n",
+      "it/its\n",
+      "\n"
+     ]
+    }
+   ],
    "source": [
     "import pdb\n",
     "import numpy as np\n",
@@ -486,17 +809,19 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 42,
-   "id": "94a01b2d",
+   "execution_count": 3,
+   "id": "88f7d20e",
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "<SingleStrandedSegment'> 1[2]> <DoubleStrandedSegment'> 0[2]> 1 2 True True\n",
-      "<DoubleStrandedSegment'> 0[2]> <SingleStrandedSegment'> 2[1]> 4 6 True True\n",
-      "<SingleStrandedSegment'> 2[1]> <SingleStrandedSegment'> 1[2]> 6 0 True True\n"
+      "<DoubleStrandedSegment'> 1[1]> <DoubleStrandedSegment'> 0[1]> 5 3 True True\n",
+      "<SingleStrandedSegment'> 2[2]> <DoubleStrandedSegment'> 0[1]> 1 2 True True\n",
+      "<DoubleStrandedSegment'> 0[1]> <DoubleStrandedSegment'> 1[1]> 2 4 True True\n",
+      "<DoubleStrandedSegment'> 1[1]> <SingleStrandedSegment'> 3[1]> 4 6 True True\n",
+      "<SingleStrandedSegment'> 3[1]> <SingleStrandedSegment'> 2[2]> 6 0 True True\n"
      ]
     }
    ],
@@ -504,7 +829,7 @@
     "coordinate = [(0,0,3.4*i) for i in range(7)]\n",
     "three_prime = [ 1, 2, 4,-1, 6, 3, 0]\n",
     "basepair    = [-1,-1, 3, 2, 5, 4,-1]\n",
-    "stack       = [-1,-1, 4,-1,-1, 3,-1]\n",
+    "stack       = [-1,-1, -1,-1,-1, -1,-1]\n",
     "for i in [3,5]:\n",
     "    coordinate[i] = (1,0,3.4*i)\n",
     "\n",
@@ -518,16 +843,16 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 45,
-   "id": "0a98fa8c",
+   "execution_count": 4,
+   "id": "69d29f1e",
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[[<SegmentParticle DNA on <DoubleStrandedSegment'> 0[2]>[0.00]>, <SegmentParticle DNA on <DoubleStrandedSegment'> 0[2]>[0.50]>, <SegmentParticle DNA on <DoubleStrandedSegment'> 0[2]>[1.00]>], [<SegmentParticle NAS on <SingleStrandedSegment'> 1[2]>[0.00]>, <SegmentParticle NAS on <SingleStrandedSegment'> 1[2]>[0.50]>, <SegmentParticle NAS on <SingleStrandedSegment'> 1[2]>[1.00]>], [<SegmentParticle NAS on <SingleStrandedSegment'> 2[1]>[0.50]>]]\n",
-      "[[<Connection <Location 1.end3[1,on_fwd_strand]>--sscrossover--<Location 0.end5[0,on_fwd_strand]>]>, <Connection <Location 0.end3[1,on_fwd_strand]>--intrahelical--<Location 2.end5[0,on_fwd_strand]>]>], [<Connection <Location 1.end3[1,on_fwd_strand]>--sscrossover--<Location 0.end5[0,on_fwd_strand]>]>, <Connection <Location 2.end3[0,on_fwd_strand]>--intrahelical--<Location 1.end5[0,on_fwd_strand]>]>], [<Connection <Location 0.end3[1,on_fwd_strand]>--intrahelical--<Location 2.end5[0,on_fwd_strand]>]>, <Connection <Location 2.end3[0,on_fwd_strand]>--intrahelical--<Location 1.end5[0,on_fwd_strand]>]>]]\n"
+      "[[<SegmentParticle DNA on <DoubleStrandedSegment'> 0[1]>[1.00]>], [<SegmentParticle DNA on <DoubleStrandedSegment'> 1[1]>[0.00]>, <SegmentParticle DNA on <DoubleStrandedSegment'> 1[1]>[1.00]>], [<SegmentParticle NAS on <SingleStrandedSegment'> 2[2]>[0.00]>, <SegmentParticle NAS on <SingleStrandedSegment'> 2[2]>[0.50]>, <SegmentParticle NAS on <SingleStrandedSegment'> 2[2]>[1.00]>], [<SegmentParticle NAS on <SingleStrandedSegment'> 3[1]>[0.50]>]]\n",
+      "[[<Connection <Location 1.end3[0,on_fwd_strand]>--intrahelical--<Location 0.end5[0,on_fwd_strand]>]>, <Connection <Location 2.end3[1,on_fwd_strand]>--sscrossover--<Location 0.end5[0,on_rev_strand]>]>, <Connection <Location 0.end3[0,on_rev_strand]>--intrahelical--<Location 1.end5[0,on_rev_strand]>]>], [<Connection <Location 1.end3[0,on_fwd_strand]>--intrahelical--<Location 0.end5[0,on_fwd_strand]>]>, <Connection <Location 0.end3[0,on_rev_strand]>--intrahelical--<Location 1.end5[0,on_rev_strand]>]>, <Connection <Location 1.end3[0,on_rev_strand]>--intrahelical--<Location 3.end5[0,on_fwd_strand]>]>], [<Connection <Location 2.end3[1,on_fwd_strand]>--sscrossover--<Location 0.end5[0,on_rev_strand]>]>, <Connection <Location 3.end3[0,on_fwd_strand]>--intrahelical--<Location 2.end5[0,on_fwd_strand]>]>], [<Connection <Location 1.end3[0,on_rev_strand]>--intrahelical--<Location 3.end5[0,on_fwd_strand]>]>, <Connection <Location 3.end3[0,on_fwd_strand]>--intrahelical--<Location 2.end5[0,on_fwd_strand]>]>]]\n"
      ]
     }
    ],
@@ -538,51 +863,39 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 46,
-   "id": "fff9bd6e",
+   "execution_count": 5,
+   "id": "e103e8b4",
    "metadata": {},
-   "outputs": [
-    {
-     "ename": "AttributeError",
-     "evalue": "'SegmentModel' object has no attribute 'basepair'",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
-      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
-      "\u001b[0;32m<ipython-input-46-71d700bd1aa3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ms\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbasepair\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
-      "\u001b[0;31mAttributeError\u001b[0m: 'SegmentModel' object has no attribute 'basepair'"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "s=model.basepair"
+    "s=model.children[0]"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 43,
-   "id": "c5297019",
+   "execution_count": 6,
+   "id": "a30b582d",
    "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "<SingleStrandedSegment'> 1[2]>"
+       "'0'"
       ]
      },
-     "execution_count": 43,
+     "execution_count": 6,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "s"
+    "s.segname"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 31,
-   "id": "ef6893ff",
+   "execution_count": 7,
+   "id": "dcd8bf8a",
    "metadata": {},
    "outputs": [
     {
@@ -597,7 +910,7 @@
        " (0, 0, 20.4)]"
       ]
      },
-     "execution_count": 31,
+     "execution_count": 7,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -609,7 +922,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "464b709d",
+   "id": "bf20c9ef",
    "metadata": {},
    "outputs": [],
    "source": []
-- 
GitLab