SHARE
TWEET

Untitled

a guest Aug 12th, 2011 108 Never
  1. # -*- coding: cp1252 -*-
  2.  
  3. import csv
  4. from itertools import izip
  5. import time
  6. import shutil
  7. import os
  8. from Bio import SeqIO
  9.  
  10. import wx
  11. import wx.grid as gridlib
  12. import  wx.lib.printout as  printout
  13. import wx.aui as aui
  14. import  wx.lib.scrolledpanel as scrolled
  15.  
  16. import numpy as np
  17. import matplotlib
  18. from matplotlib.figure import Figure
  19. from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
  20. import matplotlib.patches as mpatches
  21.  
  22. class DrawSchema(scrolled.ScrolledPanel):
  23.     """
  24.    Draw schema with matplotlib.
  25.    """
  26.     def __init__(self, parent, id = -1):
  27.         scrolled.ScrolledPanel.__init__(self, parent, -1)
  28.  
  29.         vbox = wx.BoxSizer(wx.VERTICAL)
  30.  
  31.         # Create figure.
  32.         self.fig = matplotlib.figure.Figure(figsize=(20, 15), facecolor='white')
  33.         self.axes = self.fig.add_subplot(111)
  34.         # ----------------------------------------------------------------------------
  35.         # Draw sequence as line.
  36.         seq_x = 0.9
  37.         seq_y = 0.95
  38.         seq_length = -1000
  39.         self.axes.annotate('', xy=(seq_x, seq_y),  xycoords='data',
  40.                 xytext=(seq_length, 0), textcoords='offset points',
  41.                 arrowprops=dict(facecolor='black', arrowstyle="-", linewidth=5),
  42.                 horizontalalignment='right', verticalalignment='bottom',
  43.                 )
  44.         # ----------------------------------------------------------------------------
  45.         # Draw primers.
  46.         # x = pos of primer
  47.         # x = 0 bp = 0.066
  48.         # x = 1000 bp = 0.9
  49.         # 1 bp = 0.000834
  50.         # divide primer by scaled down, because seq is scaled down
  51.         # scaled down = seq_length/1000
  52.         # x = pos * 0,000834 * scaled down
  53.         #---------------------------------------------------------
  54.         # primer_y = up and down in 0.05 steps
  55.         primer_y = 0.9
  56.         primer_length = -70
  57.         #---------------------------------------------------------
  58.         # text_y 0.8 # 0.04 steps
  59.         # 1 bp = 0.143
  60.         # 1000 bp = 0.81
  61.         # x = pos * 0,000667 * scaled down
  62.         text_y = 0.8
  63.         #---------------------------------------------------------
  64.         seq_length = 2054
  65.         scale_factor = float(float(seq_length)/1000.0)
  66.  
  67.         data = ['ARM(BstX-Sbf)R\t-\tMySequence\t1782\tAGACATGGGAACTCGGGAAGGAGAGGCC\tIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t0:G>C,1:A>C,3:T>G\n', 'ARM(BstX-Spe)F\t+\tMySequence\t1786\tATGGGAACTCGGGAAGGAGATGAA\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t23:G>A\n', 'ARM-203R\t-\tMySequence\t2050\tCTATCTCTTCTGCCCCTCAAAGG\tIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-50F\t+\tMySequence\t656\tTAATGATAATCTTCCTAATACCCGTCAG\tIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-IN442R\t-\tMySequence\t350\tGTAATCTTCCCTGGACCCCGG\tIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-OE-454F-SpeI\t+\tMySequence\t440\tCCATACTAGTCATGAGGCCTCATCGATCAGTC\tIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t4:C>A,7:G>A\n', 'ARM-107F\t+\tMySequence\t713\tGATGATACGAGTTCCAGGTGATAGG\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-163F\t+\tMySequence\t769\tTTGCTGACCGTGGGCTTTC\tIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-203R\t-\tMySequence\t787\tCTATCTCTTCTGCCCCTCAAAGG\tIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-278R\t-\tMySequence\t864\tCAGCGGCAAACATCTGACAAG\tIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-318R\t-\tMySequence\t905\tGTCGTTATCCATGGATGCCC\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-50F\t+\tMySequence\t656\tTAATGATAATCTTCCTAATACCCGTCAG\tIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-FL32F\t+\tMySequence\t31\tTGACCGACCAGCCACCAC\tIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-FL40F\t+\tMySequence\t39\tCAGCCACCACCAACCCAAAC\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-INT178-R\t-\tMySequence\t762\tGGAGAGGTTGCTGACCGTGGGC\tIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-INT473-R\t-\tMySequence\t1054\tGGATTGCCATTGCTAATTGTGGGGC\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-INT489-F\t+\tMySequence\t1094\tTGGCCTTCTTCATTCACCCGATGC\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-INT958-R\t-\tMySequence\t1544\tGACTGCGATTGGGCAGGCGC\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-OE-1898R\t-\tMySequence\t1876\tGTTATTGTTGTTGACTGGCGCT\tIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-OE1898R-ApaI\t-\tMySequence\t1876\tGTTATTGTTGTTGACTGGCGCTGGGCCCTGC\tIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t4:A>C,5:T>C,7:T>G\n', 'ARM-OE-1970R\t-\tMySequence\t1946\tCTGGTGGATTAGTTGCTGTGTTTG\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-OE-407F\t+\tMySequence\t406\tTGTGAACCATCCTGAAATCTGA\tIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-OE40F-SpeI\t+\tMySequence\t33\tACCGACTAGTCACCACCAACCCAAACC\tIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t6:C>T,9:C>T\n', 'ARM-OE-454F\t+\tMySequence\t453\tGAGGCCTCATCGATCAGTCTTTAG\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-SPepAS\t-\tMySequence\t480\tATGCAAATGGCTCTGCTAGCAAGGCTTTCTCTTGCAAGTTCTGAAGGAAGAGAGTCTGG\tIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t1:A>G\n', 'ARM-TS-10F\t+\tMySequence\t287\tAGCCTTCAAGATTTGAGCACCACAG\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-11F\t+\tMySequence\t313\tCAACAGCCTCCTACATCCTGTGTCG\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-12R\t-\tMySequence\t577\tCAGAACAATCAACGAAGGAAGCATTTC\tIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-13R\t-\tMySequence\t687\tGACGAGGAGTGTGACATCAACGATG\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-14R\t-\tMySequence\t350\tGTAATCTTCCCTGGACCCCGG\tIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-4F\t+\tMySequence\t32\tGACCGACCAGCCACCACCAAC\tIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-5R\t-\tMySequence\t246\tGTATCCGCCCCTTCCGCAAC\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-6R\t-\tMySequence\t216\tTCCCCCTCACCGCAGCATC\tIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-TS-7R\t-\tMySequence\t49\tCAACCCAAACCAACGCGGC\tIIIIIIIIIIIIIIIIIII\t0\t\n', 'HO14H18_3UTR-F\t+\tMySequence\t1329\tAAGCCTCTCGTGGACTTGCT\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'HO14H18_3UTR-R\t-\tMySequence\t1604\tAGCGAAAGCGAAGGAAAATG\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'N-ARM1231F\t+\tMySequence\t1788\tGGGAACTCGGCGAGGAGATGATG\tIIIIIIIIIIIIIIIIIIIIIII\t0\t10:G>C,11:A>G,21:G>T\n', 'RNR5-598R\t-\tMySequence\t577\tCAGAACAATCAACGAAGGAAGCAT\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'RNR5_RNAi-F\t+\tMySequence\t1218\tCATGTCCTGGAAACAGGGAA\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'RNR5_RNAi-R\t-\tMySequence\t1801\tGGAGATGAGGACGATGGTCC\tIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-RACE4\t-\tMySequence\t466\tTCAGTCTTCAGATTATGCAAATGGCTCTGC\tIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t21:T>C\n', 'ARM-EXON1-F1\t+\tMySequence\t114\tGTGCCGTGCCGTGCCTCA\tIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-EXON1-F1\t+\tMySequence\t109\tGTGCCGTGCCGTGCCTCA\tIIIIIIIIIIIIIIIIII\t1\t15:G>T,16:T>C,17:G>A\n', 'ARM-EXON1-F1\t+\tMySequence\t104\tGTGCCGTGCCGTGCCTCA\tIIIIIIIIIIIIIIIIII\t1\t15:G>T,16:T>C,17:G>A\n', 'ARM-EXON1-R1\t-\tMySequence\t246\tGTATCCGCCCCTTCCGGCAA\tIIIIIIIIIIIIIIIIIIII\t0\t0:C>A,2:A>C,3:C>G\n', 'ARM-EXON2-F1\t+\tMySequence\t293\tCAAGATTTGAGCACCACAGGCAACAG\tIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-EXON2-R1\t-\tMySequence\t350\tGTAATCTTCCCTGGACCCCGGG\tIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'ARM-EXON2-R2\t-\tMySequence\t417\tCTGAAATCTGATGCACATGTGAACCAT\tIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-R1\t-\tMySequence\t406\tTGTGAACCATCCTGAAATCTGATGC\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-F1\t+\tMySequence\t403\tGCATGTGAACCATCCTGAAATCTGA\tIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-R4\t-\tMySequence\t333\tTGTCGGTACTTGGTAGGGTAATCTTCC\tIIIIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-F4\t+\tMySequence\t216\tTTCCCCTCACCGCAGCATC\tIIIIIIIIIIIIIIIIIII\t0\t1:C>T\n', 'WRNR5-R5\t-\tMySequence\t211\tCTCGTTTCCCCTCACCGCA\tIIIIIIIIIIIIIIIIIII\t0\t12:C>T,17:C>T\n', 'WRNR5-cDNA-Seq_1670R\t-\tMySequence\t1726\tGAACACCACGCGCAAGAGAAAAG\tIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_1306R\t-\tMySequence\t1363\tCACGAGGAAAGAAAGATGCGGTTA\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_798R\t-\tMySequence\t855\tCCATCTGTTCGGCGGCAAA\tIIIIIIIIIIIIIIIIIII\t0\t8:A>G,14:T>C\n', 'WRNR5-cDNA-Seq_729R\t-\tMySequence\t786\tTCTGTCTCTTCCGCCCCTCAAA\tIIIIIIIIIIIIIIIIIIIIII\t0\t10:T>C,18:A>G\n', 'WRNR5-cDNA-Seq_530R\t-\tMySequence\t578\tGGAACAATCAACGGAGGAAGCATC\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t0:T>C,10:A>G,23:A>G\n', 'WRNR5-cDNA-Seq_1714F\t+\tMySequence\t1770\tTTCCGCAGCCAAAGACAT\tIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_1670F\t+\tMySequence\t1726\tGAACACCACGCGCAAGAGAAAAG\tIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_1302F\t+\tMySequence\t1359\tAGCCCACGAGGAAAGAAAGATGC\tIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_933F\t+\tMySequence\t990\tATAGAAGGTCAGAGATCAGCAACA\tIIIIIIIIIIIIIIIIIIIIIIII\t0\t\n', 'WRNR5-cDNA-Seq_864F\t+\tMySequence\t921\tGCCCGGGGTGATTTCTCTGC\tIIIIIIIIIIIIIIIIIIII\t0\t7:A>G\n']
  68.  
  69.         for primer in data:
  70.             primer = primer.strip()
  71.             primer = primer.split('\t')
  72.             primer_name = primer[0]
  73.             primer_pos = primer[3]
  74.             orientation = primer[1]
  75.             if orientation == '+':
  76.                 arrow = "->"
  77.                 colour = 'red'
  78.             elif orientation == '-':
  79.                 arrow = "<-"
  80.                 colour = 'blue'
  81.  
  82.             # Calculate primer and text position
  83.             primer_x = (float(primer_pos) / scale_factor) * 0.000834
  84.             text_x = (float(primer_pos) / scale_factor) * 0.000667
  85.  
  86.             self.axes.annotate('', xy=(primer_x+0.06, primer_y),  xycoords='data',
  87.                     xytext=(primer_length, -0.1), textcoords='offset points',    # -50 = length, 0= direction
  88.                     arrowprops=dict(edgecolor=colour, arrowstyle=arrow, linewidth=3),
  89.                     horizontalalignment='right', verticalalignment='bottom',
  90.                     )
  91.  
  92.             self.fig.text(text_x+0.15, text_y, primer_name + ' (' + str(primer_pos) + ')', ha="center", size=14)
  93.  
  94.             primer_y = primer_y - 0.05
  95.             text_y = text_y - 0.04
  96.  
  97.         # ----------------------------------------------------------------------------
  98.         # Description
  99.         self.fig.text(0.186, 0.97, 'Primer Factory 2 Results', ha="center", size=14)
  100.         self.fig.text(0.189, 0.95, str(time.ctime()), ha="center", size=14)
  101.         self.fig.text(0.189, 0.93, 'Query Sequence ' + str(seq_length) +' bp', ha="center", size=14)
  102.         self.fig.text(0.185, 0.91, str(len(data)) +' Primers where found', ha="center", size=14)
  103.         # Scale
  104.         self.fig.text(0.14, 0.87, '0 bp', ha="center", size=14)
  105.         self.fig.text(0.805, 0.87, str(seq_length) +' bp', ha="center", size=14)
  106.  
  107.         self.axes.set_frame_on(False)
  108.         self.axes.set_axis_off()
  109.  
  110.         self.canvas = FigureCanvas(self, -1, self.fig)
  111.  
  112.         vbox.Add(self.canvas, 0, wx.ALIGN_LEFT|wx.ALL, 5)
  113.         self.SetSizer(vbox)
  114.         self.SetAutoLayout(1)
  115.         self.SetupScrolling()
  116.  
  117.  
  118.  
  119. class ShowResults(wx.Frame):
  120.     def __init__(self):
  121.         wx.Frame.__init__(self, None, wx.ID_ANY,
  122.                           "Primer Factory Results",
  123.                           size=(1350,1000))
  124.  
  125.         self._mgr = aui.AuiManager()
  126.  
  127.         self._mgr.SetManagedWindow(self)
  128.  
  129.         self.notebook = aui.AuiNotebook(self, wx.aui.AUI_NB_SCROLL_BUTTONS)
  130.         panelTwo = DrawSchema(self.notebook)
  131.  
  132.         self.notebook.AddPage(panelTwo, "Schema", False)
  133.  
  134.         self._mgr.AddPane(self.notebook,
  135.                           aui.AuiPaneInfo().Name("notebook_content").
  136.                           CenterPane().PaneBorder(False))
  137.         self._mgr.Update()
  138.  
  139.  
  140. if __name__ == '__main__':
  141.     app = wx.PySimpleApp()
  142.     frame = ShowResults()
  143.     frame.Show(True)
  144.     app.MainLoop()
RAW Paste Data
Top