示例#1
0
    def test_readVer8Project(self):
        """
        Tests reading a version 0.8 project file and conversion to 1.0.0
        format.
        """
        self.proj.loadProjectFile('test_data/test_project-0.8.str')

        # Test if the project properties are correct.
        self.assertFalse(self.proj.isProjectEmpty())
        self.assertEqual(self.proj.getFwdTraceSearchStr(), '_F_')
        self.assertEqual(self.proj.getRevTraceSearchStr(), '_R_')
        self.assertEqual(self.proj.getTraceFileDir(), 'tracedir')
        self.assertEqual(self.proj.getAbsTraceFileDir(),
                         os.path.join(os.getcwd(), 'test_data/tracedir'))
        self.assertEqual(getDefaultFont().to_string(),
                         self.proj.getFont().to_string())

        # Test if the consensus settings are correct.
        csettings = self.proj.getConsensSeqSettings()
        self.assertEqual(csettings.getMinConfScore(), 20)
        self.assertEqual(csettings.getConsensusAlgorithm(), 'legacy')
        self.assertFalse(csettings.getTrimConsensus())
        self.assertFalse(csettings.getTrimPrimers())
        self.assertEqual(csettings.getPrimerMatchThreshold(), 0.8)
        self.assertEqual(csettings.getForwardPrimer(), '')
        self.assertEqual(csettings.getReversePrimer(), '')
        self.assertFalse(csettings.getTrimEndGaps())
        self.assertFalse(csettings.getDoQualityTrim())
        self.assertEqual(csettings.getQualityTrimParams(), (10, 6))

        self.proj.setTraceFileDir('.')
        for fname in self.tracefiles:
            self.assertTrue(self.proj.isFileInProject('test_data/' + fname))

        self._checkProjectItems(self.proj, 'fwd2.ztr', 'rev2.ztr')
示例#2
0
    def convertOldProjectFormat(self):
        """
        Converts an older project format to the current project format.
        """
        if self.proj_data['formatversion'] == '0.8':
            self.convertSettings8To9()
            self.proj_data['formatversion'] = '0.9'

        if self.proj_data['formatversion'] == '0.9':
            fontstr = getDefaultFont().to_string()
            self.proj_data['properties']['default_font'] = fontstr
            self.proj_data['formatversion'] = CURRENT_VERSION
示例#3
0
    def test_clearProject(self):
        # First, set all of the various project settings.
        self.proj.addFiles(self.tracefiles)
        self.proj.setFwdTraceSearchStr('_F_')
        self.proj.setFwdTraceSearchStr('_R_')
        self.proj.setTraceFileDir('tracedir')

        newfont = getDefaultFont()
        default_font_str = newfont.to_string()
        newfont.set_size(newfont.get_size() + 1)
        self.proj.setFont(newfont)
        self.assertNotEqual(default_font_str, self.proj.getFont().to_string())

        csettings = self.proj.getConsensSeqSettings()
        csettings.setMinConfScore(20)
        csettings.setConsensusAlgorithm('legacy')
        csettings.setTrimConsensus(False)
        csettings.setTrimPrimers(True)
        csettings.setPrimerMatchThreshold(0.2)
        csettings.setForwardPrimer('AAAT')
        csettings.setReversePrimer('AAAT')
        csettings.setTrimEndGaps(False)
        csettings.setDoQualityTrim(False)
        csettings.setQualityTrimParams(20, 18)

        self.proj.clearProject()

        # Now make sure the project is empty and all settings have default
        # values.
        self.assertTrue(self.proj.isProjectEmpty())
        for file in self.tracefiles:
            self.assertFalse(self.proj.isFileInProject(file))

        self.assertEqual(self.proj.getFwdTraceSearchStr(), '_F')
        self.assertEqual(self.proj.getRevTraceSearchStr(), '_R')
        self.assertEqual(self.proj.getTraceFileDir(), '.')
        self.assertEqual(self.proj.getAbsTraceFileDir(), os.getcwd())

        self.assertEqual(default_font_str, self.proj.getFont().to_string())

        csettings = self.proj.getConsensSeqSettings()
        self.assertEqual(csettings.getMinConfScore(), 30)
        self.assertEqual(csettings.getConsensusAlgorithm(), 'Bayesian')
        self.assertTrue(csettings.getTrimConsensus())
        self.assertFalse(csettings.getTrimEndGaps())
        self.assertFalse(csettings.getTrimPrimers())
        self.assertEqual(csettings.getForwardPrimer(), '')
        self.assertEqual(csettings.getReversePrimer(), '')
        self.assertEqual(csettings.getPrimerMatchThreshold(), 0.8)
        self.assertTrue(csettings.getDoQualityTrim())
        self.assertEqual(csettings.getQualityTrimParams(), (10, 8))
示例#4
0
    def clearProject(self, notify=True):
        # start numbering for node IDs at 0 by default
        self.idnum = 0
        self.project_file = ''
        self.trace_file_dir = '.'

        self.fwd_trace_searchstr = '_F'
        self.rev_trace_searchstr = '_R'

        self.default_font = getDefaultFont()

        # Copy default consensus sequence settings rather than change
        # references to a new settings object in case there are any active
        # users of the existing settings object.
        settings = ConsensSeqSettings()
        self.consseqsettings.copyFrom(settings)

        self.ts.clear()
        self.num_files = 0

        self.setSaveState(True)
        if notify:
            self.notifyObservers('project_cleared', ())
示例#5
0
    def test_readWriteProject(self):
        # Write the test project file in a temporary directory.
        tmpdir = tempfile.mkdtemp()
        tmpfpath = os.path.join(tmpdir, self.filename)
        self.proj.setProjectFileName(tmpfpath)

        self.proj.addFiles(self.tracefiles)
        self.proj.setFwdTraceSearchStr('_F_')
        self.proj.setRevTraceSearchStr('_R_')
        self.proj.setTraceFileDir('tracedir')

        # Set a non-default font.
        newfont = getDefaultFont()
        newfont.set_size(newfont.get_size() + 1)
        newfontstr = newfont.to_string()
        self.assertNotEqual(newfontstr, self.proj.getFont().to_string())
        self.proj.setFont(newfont)

        # Set all consensus settings.
        csettings = self.proj.getConsensSeqSettings()
        csettings.setMinConfScore(20)
        csettings.setConsensusAlgorithm('legacy')
        csettings.setTrimConsensus(False)
        csettings.setTrimPrimers(True)
        csettings.setPrimerMatchThreshold(0.2)
        csettings.setForwardPrimer('AAAT')
        csettings.setReversePrimer('GGGC')
        csettings.setTrimEndGaps(True)
        csettings.setDoQualityTrim(False)
        csettings.setQualityTrimParams(20, 18)

        # Create an associative item.
        a_item = self.proj.associateItems(
            (self.proj.getItemById(2), self.proj.getItemById(3)), 'new item')

        # Set some properties of the associative item and its children.
        a_item.setNotes('sample notes')
        a_item.setConsensusSequence('AATTAATTGGCC', 'AA TT AA TT GGCC')
        a_item.setUseSequence(True)
        child1 = a_item.getChildren()[0]
        child2 = a_item.getChildren()[1]
        child1name = child1.getName()
        child2name = child2.getName()
        child1.setConsensusSequence('CATCATGATCATTAGTAC',
                                    'CATCATGATCAT TAGTAC')
        child2.setIsReverse(True)

        # Set sequences and notes for the remaining items.
        # item 0: ''
        # item 1: 'AT'
        # item 3: 'ATATAT'
        for (cnt, item) in enumerate(self.proj):
            if item.isFile():
                item.setConsensusSequence('AT' * cnt, 'AT' * cnt)
                item.setNotes(str(cnt))

        self.proj.saveProjectFile()
        self.proj.clearProject()
        self.proj.loadProjectFile(tmpfpath)

        # Test if the project properties saved properly.
        self.assertFalse(self.proj.isProjectEmpty())
        self.assertEqual(self.proj.getFwdTraceSearchStr(), '_F_')
        self.assertEqual(self.proj.getRevTraceSearchStr(), '_R_')
        self.assertEqual(self.proj.getTraceFileDir(), 'tracedir')
        self.assertEqual(self.proj.getAbsTraceFileDir(),
                         os.path.join(tmpdir, 'tracedir'))
        self.assertEqual(newfontstr, self.proj.getFont().to_string())

        # Test if the consensus settings saved properly.
        csettings = self.proj.getConsensSeqSettings()
        self.assertEqual(csettings.getMinConfScore(), 20)
        self.assertEqual(csettings.getConsensusAlgorithm(), 'legacy')
        self.assertFalse(csettings.getTrimConsensus())
        self.assertTrue(csettings.getTrimPrimers())
        self.assertEqual(csettings.getPrimerMatchThreshold(), 0.2)
        self.assertEqual(csettings.getForwardPrimer(), 'AAAT')
        self.assertEqual(csettings.getReversePrimer(), 'GGGC')
        self.assertTrue(csettings.getTrimEndGaps())
        self.assertFalse(csettings.getDoQualityTrim())
        self.assertEqual(csettings.getQualityTrimParams(), (20, 18))

        self.proj.setTraceFileDir('.')
        for fname in self.tracefiles:
            self.assertTrue(
                self.proj.isFileInProject(os.path.join(tmpdir, fname)))

        self._checkProjectItems(self.proj, child1name, child2name)

        # Remove the temporary directory.
        shutil.rmtree(tmpdir)
示例#6
0
    def __init__(self, sequencetrace):
        self.min_height = 100
        self.preferred_height = 200

        self.drawingarea = Gtk.DrawingArea()
        self.drawingarea.set_size_request(-1, self.min_height)

        self.seqt = sequencetrace

        # Initialize drawing settings.
        self.tracecolors = {
            'A': parseHTMLColorStr('#009000'),  # green
            'C': parseHTMLColorStr('#0000ff'),  # blue
            'G': parseHTMLColorStr('#000000'),  # black
            'T': parseHTMLColorStr('#ff0000'),  # red
            'W': parseHTMLColorStr('#804800'),  # mix of A and T
            'S': parseHTMLColorStr('#000080'),  # mix of C and G
            'M': parseHTMLColorStr('#004880'),  # mix of A and C
            'K': parseHTMLColorStr('#800000'),  # mix of G and T
            'R': parseHTMLColorStr('#004800'),  # mix of A and G
            'Y': parseHTMLColorStr('#800080'),  # mix of C and T
            'B': parseHTMLColorStr('#550055'),  # mix of C, G, and T
            'D': parseHTMLColorStr('#553000'),  # mix of A, G, and T
            'H': parseHTMLColorStr('#553055'),  # mix of A, C, and T
            'V': parseHTMLColorStr('#003055'),  # mix of A, C, and G
            'N': parseHTMLColorStr('#999')  # gray
        }
        # Set up colors with an alpha channel to use for the lines from
        # the base calls to the trace peaks.
        self.pklinecolors = {}
        self.pklinecolors['A'] = (self.tracecolors['A'].red,
                                  self.tracecolors['A'].green,
                                  self.tracecolors['A'].blue, 0.84)
        self.pklinecolors['C'] = (self.tracecolors['C'].red,
                                  self.tracecolors['C'].green,
                                  self.tracecolors['C'].blue, 0.6)
        self.pklinecolors['G'] = (self.tracecolors['G'].red,
                                  self.tracecolors['G'].green,
                                  self.tracecolors['G'].blue, 0.6)
        self.pklinecolors['T'] = (self.tracecolors['T'].red,
                                  self.tracecolors['T'].green,
                                  self.tracecolors['T'].blue, 0.68)

        self.bottom_margin = 2
        self.bcpadding = 4

        self.show_confidence = True

        self.sigmax = sequencetrace.getMaxTraceVal() + (
            sequencetrace.getMaxTraceVal() / 12)

        self.bcfontdesc = None
        self.bclayout = Pango.Layout(self.drawingarea.create_pango_context())

        # Get the default font used by Gtk+ and use it as the default for the
        # trace display.
        self.setFontDescription(getDefaultFont())

        self.drawingarea.connect('draw', self.doDraw)

        self.highlighted = self.seqt.getNumBaseCalls()
示例#7
0
    def __init__(self, mod_consensseq_builder):
        Gtk.DrawingArea.__init__(self)

        self.cons = mod_consensseq_builder
        self.numseqs = self.cons.getNumSeqs()
        settings = self.cons.getSettings()
        self.drawprimers = (settings.getForwardPrimer() != ''
                            and settings.getReversePrimer() != '')

        self.cons.registerObserver('consensus_changed', self.consensusChanged)

        # Initialize drawing settings.
        self.basecolors = {
            'A': parseHTMLColorStr('#009000'),  # green
            'C': parseHTMLColorStr('#0000ff'),  # blue
            'G': parseHTMLColorStr('#000000'),  # black
            'T': parseHTMLColorStr('#ff0000'),  # red
            'W': parseHTMLColorStr('#804800'),  # mix of A and T
            'S': parseHTMLColorStr('#000080'),  # mix of C and G
            'M': parseHTMLColorStr('#004880'),  # mix of A and C
            'K': parseHTMLColorStr('#800000'),  # mix of G and T
            'R': parseHTMLColorStr('#004800'),  # mix of A and G
            'Y': parseHTMLColorStr('#800080'),  # mix of C and T
            'B': parseHTMLColorStr('#550055'),  # mix of C, G, and T
            'D': parseHTMLColorStr('#553000'),  # mix of A, G, and T
            'H': parseHTMLColorStr('#553055'),  # mix of A, C, and T
            'V': parseHTMLColorStr('#003055'),  # mix of A, C, and G
            'N': parseHTMLColorStr('#999'),  # gray
            '-': parseHTMLColorStr('#000'),  # black
            ' ': parseHTMLColorStr('#999')
        }
        self.bgcolors = {
            # These are mostly lighter versions of the foreground colors above.
            'A': parseHTMLColorStr('#cfc'),
            'C': parseHTMLColorStr('#ccf'),
            'G': parseHTMLColorStr('#ccc'),
            'T': parseHTMLColorStr('#fcc'),
            'W': parseHTMLColorStr('#DFD1BF'),  # mix of A and T
            'S': parseHTMLColorStr('#BFBFDF'),  # mix of C and G
            'M': parseHTMLColorStr('#BFD1DF'),  # mix of A and C
            'K': parseHTMLColorStr('#DFBFBF'),  # mix of G and T
            'R': parseHTMLColorStr('#BFD1BF'),  # mix of A and G
            'Y': parseHTMLColorStr('#DFBFDF'),  # mix of C and T
            'B': parseHTMLColorStr('#D5BFD5'),  # mix of C, G, and T
            'D': parseHTMLColorStr('#D5CBBF'),  # mix of A, G, and T
            'H': parseHTMLColorStr('#D5CBD5'),  # mix of A, C, and T
            'V': parseHTMLColorStr('#BFCBD5'),  # mix of A, C, and G
            'N': parseHTMLColorStr('#fff'),
            '-': parseHTMLColorStr('#ff9')
        }

        # Calculate inverses of the main colors for drawing
        # selected/highlighted bases.
        self.basecolors_inv = {}
        for base in self.basecolors:
            self.basecolors_inv[base] = getInverseColor(self.basecolors[base])
        self.bgcolors_inv = {}
        for base in self.bgcolors:
            self.bgcolors_inv[base] = getInverseColor(self.bgcolors[base])

        # The space before the top of the alignment and after the bottom of the
        # consensus sequence.
        self.margins = 6

        # The space between the alignment and the consensus sequence.
        self.padding = 6

        # The location of the top of the alignment.
        self.al_top = self.margins

        self.txtlayout = Pango.Layout(self.create_pango_context())

        # The working width and height of the current font, in pixels.
        self.fheight = -1
        self.fwidth = -1

        # Get the default font used by Gtk+ and use it as the default for the
        # sequence display.
        self.setFontDescription(getDefaultFont())

        # The index of the currently highlighted position in the alignment.
        self.lastx = -1
        # The index of the currently selected (and highlighted) position in the
        # alignment.
        self.highlighted = -1

        # Keep track of location of an active selection on the consensus
        # sequence. The values are interpreted such that the lower value (which
        # could be either start or end) is the first selected position, and the
        # higher value is 1 beyond the last selected position.
        self.consselect_start = -1
        self.consselect_end = -1
        # Indicates if the user is actively making a selection on the consensus
        # sequence.
        self.selecting_active = False

        # Set up event handling.
        self.connect('destroy', self.onDestroy)
        self.connect('draw', self.onDraw)

        self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK
                        | Gdk.EventMask.BUTTON_RELEASE_MASK
                        | Gdk.EventMask.POINTER_MOTION_MASK
                        | Gdk.EventMask.POINTER_MOTION_HINT_MASK
                        | Gdk.EventMask.LEAVE_NOTIFY_MASK)
        self.connect('button-press-event', self.mouseClick)
        self.connect('button-release-event', self.mouseRelease)
        self.connect('motion-notify-event', self.mouseMove)
        self.connect('leave-notify-event', self.mouseLeave)

        self.clickable_cursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
        self.text_cursor = Gdk.Cursor.new(Gdk.CursorType.XTERM)
        self.curr_cursor = None

        # initialize the observable events for this class
        self.defineObservableEvents([
            'alignment_clicked',
            'consensus_clicked',
            # The 'selection_state' event is triggered when the selection state
            # changes from no selection to one or more bases selected.
            'selection_state'
        ])