示例#1
0
    def readFile(self, filename):
        """ Convenience wrapper for `decodeFile` to always emit_signals and
        set the `document` argument to `self`

        Args:
            filename (str): full path file name
        """
        return decodeFile(filename, document=self, emit_signals=True)
示例#2
0
    def readFile(self, filename):
        """ Convenience wrapper for `decodeFile` to always emit_signals and
        set the `document` argument to `self`

        Args:
            filename (str): full path file name
        """
        return decodeFile(filename, document=self, emit_signals=True)
示例#3
0
    def openAfterMaybeSaveCallback(self, selected):
        """
        Receives file selection info from the dialog created by
        openAfterMaybeSave, following user input.

        Extracts the file name and passes it to the decode method, which
        returns a new document doc, which is then set as the open document
        by newDocument. Calls finalizeImport and disconnects dialog signaling.
        """
        if isinstance(selected, (list, tuple)):
            fname = selected[0]
        else:
            fname = selected
        if fname is None or fname == '' or os.path.isdir(fname):
            return False
        if not os.path.exists(fname):
            return False
        self._writeFileOpenPath(os.path.dirname(fname))

        self.win.path_graphics_view.setViewportUpdateOn(False)
        self.win.slice_graphics_view.setViewportUpdateOn(False)

        self.newDocument(fname=fname)
        decodeFile(fname, document=self._document)

        self.win.path_graphics_view.setViewportUpdateOn(True)
        self.win.slice_graphics_view.setViewportUpdateOn(True)

        self.win.path_graphics_view.update()
        self.win.slice_graphics_view.update()

        if hasattr(self, "filesavedialog"):  # user did save
            if self.fileopendialog != None:
                self.fileopendialog.filesSelected.disconnect(\
                                              self.openAfterMaybeSaveCallback)
            # manual garbage collection to prevent hang (in osx)
            del self.fileopendialog
            self.fileopendialog = None
    def openAfterMaybeSaveCallback(self, selected):
        """
        Receives file selection info from the dialog created by
        openAfterMaybeSave, following user input.

        Extracts the file name and passes it to the decode method, which
        returns a new document doc, which is then set as the open document
        by newDocument. Calls finalizeImport and disconnects dialog signaling.
        """
        if isinstance(selected, (list, tuple)):
            fname = selected[0]
        else:
            fname = selected
        if fname is None or fname == '' or os.path.isdir(fname):
            return False
        if not os.path.exists(fname):
            return False
        self._writeFileOpenPath(os.path.dirname(fname))

        self.win.path_graphics_view.setViewportUpdateOn(False)
        self.win.slice_graphics_view.setViewportUpdateOn(False)

        self.newDocument(fname=fname)
        decodeFile(fname, document=self._document)

        self.win.path_graphics_view.setViewportUpdateOn(True)
        self.win.slice_graphics_view.setViewportUpdateOn(True)

        self.win.path_graphics_view.update()
        self.win.slice_graphics_view.update()

        if hasattr(self, "filesavedialog"): # user did save
            if self.fileopendialog != None:
                self.fileopendialog.filesSelected.disconnect(\
                                              self.openAfterMaybeSaveCallback)
            # manual garbage collection to prevent hang (in osx)
            del self.fileopendialog
            self.fileopendialog = None
示例#5
0
 def createDocument(self, base_doc=None):
     global DocumentController
     # print("CadnanoQt createDocument begin")
     default_file = self.argns.file or os.environ.get('CADNANO_DEFAULT_DOCUMENT', None)
     if default_file is not None and base_doc is not None:
         default_file = os.path.expanduser(default_file)
         default_file = os.path.expandvars(default_file)
         dc = DocumentController(base_doc)
         # logger.info("Loading cadnano file %s to base document %s", default_file, base_doc)
         decodeFile(default_file, document=base_doc)
         dc.setFileName(default_file)
         print("Loaded default document: %s" % (default_file))
     else:
         doc_ctrlr_count = len(self.document_controllers)
         # logger.info("Creating new empty document...")
         if doc_ctrlr_count == 0:  # first dc
             # dc adds itself to app.document_controllers
             dc = DocumentController(base_doc)
         elif doc_ctrlr_count == 1:  # dc already exists
             dc = list(self.document_controllers)[0]
             dc.newDocument()  # tell it to make a new doucment
     # print("CadnanoQt createDocument done")
     return dc.document()
示例#6
0
 def createDocument(self, base_doc=None):
     global DocumentController
     # print("CadnanoQt createDocument begin")
     default_file = self.argns.file or os.environ.get(
         'CADNANO_DEFAULT_DOCUMENT', None)
     if default_file is not None and base_doc is not None:
         default_file = os.path.expanduser(default_file)
         default_file = os.path.expandvars(default_file)
         dc = DocumentController(base_doc)
         # logger.info("Loading cadnano file %s to base document %s", default_file, base_doc)
         decodeFile(default_file, document=base_doc)
         dc.setFileName(default_file)
         print("Loaded default document: %s" % (default_file))
     else:
         doc_ctrlr_count = len(self.document_controllers)
         # logger.info("Creating new empty document...")
         if doc_ctrlr_count == 0:  # first dc
             # dc adds itself to app.document_controllers
             dc = DocumentController(base_doc)
         elif doc_ctrlr_count == 1:  # dc already exists
             dc = list(self.document_controllers)[0]
             dc.newDocument()  # tell it to make a new doucment
     # print("CadnanoQt createDocument done")
     return dc.document()
示例#7
0
# from nno2stl.halfcylinder import HalfCylinder

root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root_path)
BASE_LENGTH = 0.3

if __name__ == "__main__":

    test1 = 'super_barcode_hex.json'
    test2 = 'Nature09_squarenut.json'

    path_out = 'Nature09_squarenut.stl'

    root_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    test_path = os.path.join(root_path, 'tests', test2)
    doc = nnodecode.decodeFile(test_path)

    solids = []
    part = doc.children()[0]
    # print(part.radius())
    radius = part.radius() + 0.1

    for oligo in part.oligos():
        if not oligo.isStaple():
            strand5p = oligo.strand5p()
            for strand in strand5p.generator3pStrand():
                length = BASE_LENGTH * strand.length()

                idx_low, idx_high = strand.idxs()
                z = BASE_LENGTH * ((idx_high + idx_low) / 2.0)
示例#8
0
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root_path)
BASE_LENGTH = 0.3


if __name__ == "__main__":

    test1 = 'super_barcode_hex.json'
    test2 = 'Nature09_squarenut.json'

    path_out = 'Nature09_squarenut.stl'

    root_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    test_path = os.path.join(root_path, 'tests', test2)
    doc = nnodecode.decodeFile(test_path)

    solids = []
    part = doc.children()[0]
    # print(part.radius())
    radius = part.radius() + 0.1

    for oligo in part.oligos():
        if not oligo.isStaple():
            strand5p = oligo.strand5p()
            for strand in strand5p.generator3pStrand():
                length = BASE_LENGTH*strand.length()

                idx_low, idx_high = strand.idxs()
                z = BASE_LENGTH*((idx_high + idx_low) / 2.0)