Exemplo n.º 1
0
    def generate(self):
        files = self.find_files(self.input_directory, '.fastq')
        if not files:
            files = self.find_files(self.input_directory, '_001.fastq')

        scripts = []
        
        for file in files:
            root = file.split(os.sep)[-1]

            directory = self.working_directory + os.sep + root
            script = Script(root, directory, self.query, self.input_directory, self.output_directory)
            
            pipeline = self.pipeline
 
            if self.pipeline == 'denovota':
                read_length = self.find_read_length(self.input_directory + os.sep + file)
                if read_length == 150:
                    pipeline = 'denovota150'
                else:
                    pipeline = 'denovota250'

                print('Detected read length', read_length, 'for input', root) 

            script.load_pipeline(pipeline)
            scripts.append(script)

        return scripts
Exemplo n.º 2
0
 def __init__(self, parent=None):
     super(ScriptEdit, self).__init__(parent)
     self.current_format = 'Human'
     self.script = Script()
     self.textChanged.connect(self.on_text_changed)
     self.setFont(monospace_font)
     # For tooltips
     self.context = []
Exemplo n.º 3
0
 def set_data(self, text, fmt):
     script = None
     if fmt == 'Hex' and len(text) % 2 == 0:
         try:
             script = Script(text.decode('hex'))
         except Exception:
             pass
     elif fmt == 'Human':
         txt, self.context = transform_human_script(text, self.gui)
         script = Script.from_human(txt)
     self.script = script
Exemplo n.º 4
0
 def __init__(self, editor=None):
     super(MyScriptEdit, self).__init__(editor)
     self.editor = editor
     self.current_format = known_script_formats[0]
     self.script = Script()
     self.textChanged.connect(self.on_text_changed)
     self.setFont(monospace_font)
Exemplo n.º 5
0
class MyScriptEdit(QPlainTextEdit):
    def __init__(self, editor=None):
        super(MyScriptEdit, self).__init__(editor)
        self.editor = editor
        self.current_format = known_script_formats[0]
        self.script = Script()
        self.textChanged.connect(self.on_text_changed)
        self.setFont(monospace_font)

    def on_text_changed(self):
        txt = str(self.toPlainText())
        self.set_data(txt, self.current_format)

    def copy_hex(self):
        txt = self.get_data('Hex')
        QApplication.clipboard().setText(txt)

    def contextMenuEvent(self, e):
        menu = self.createStandardContextMenu()
        menu.addAction('Copy Hex', self.copy_hex)
        menu.exec_(e.globalPos())

    def set_format(self, fmt):
        self.current_format = fmt
        self.setPlainText(self.get_data())

    def set_data(self, text, fmt):
        script = None
        if fmt == 'Hex' and len(text) % 2 == 0:
            try:
                script = Script(text.decode('hex'))
            except Exception:
                pass
        elif fmt == 'Human':
            txt = transform_human(text, self.editor.gui)
            script = Script.from_human(txt)
        self.script = script

    def get_data(self, fmt=None):
        if fmt is None:
            fmt = self.current_format
        if not self.script: return ''
        if fmt == 'Hex':
            return self.script.get_hex()
        elif fmt == 'Human':
            return self.script.get_human()
Exemplo n.º 6
0
class MyScriptEdit(QPlainTextEdit):
    def __init__(self, parent=None):
        super(MyScriptEdit, self).__init__(parent)
        self.current_format = known_script_formats[0]
        self.script = Script()
        self.textChanged.connect(self.on_text_changed)
        self.setFont(monospace_font)

    def on_text_changed(self):
        txt = str(self.toPlainText())
        self.set_data(txt, self.current_format)

    def copy_hex(self):
        txt = self.get_data('Hex')
        QApplication.clipboard().setText(txt)

    def contextMenuEvent(self, e):
        menu = self.createStandardContextMenu()
        menu.addAction('Copy Hex', self.copy_hex)
        menu.exec_(e.globalPos())

    def set_format(self, fmt):
        self.current_format = fmt
        self.setPlainText(self.get_data())

    def set_data(self, text, fmt):
        script = None
        if fmt == 'Hex' and len(text) % 2 == 0:
            try:
                script = Script(text.decode('hex'))
            except Exception:
                pass
        elif fmt == 'Human':
            txt = transform_human(text)
            script = Script.from_human(txt)
        self.script = script

    def get_data(self, fmt=None):
        if fmt is None:
            fmt = self.current_format
        if not self.script: return ''
        if fmt == 'Hex':
            return self.script.get_hex()
        elif fmt == 'Human':
            return self.script.get_human()
Exemplo n.º 7
0
 def set_data(self, text, fmt):
     script = None
     if fmt == 'Hex' and len(text) % 2 == 0:
         try:
             script = Script(text.decode('hex'))
         except Exception:
             pass
     elif fmt == 'Human':
         txt, self.context = transform_human_script(text, self.gui)
         script = Script.from_human(txt)
     self.script = script
Exemplo n.º 8
0
def main():
    scripts = Script.get_scripts()
    scripts_names = list(
        map(lambda script: f'{script.__name__} - {script.Meta.description}',
            scripts))

    response = questionary.select('Which script you want to run?',
                                  scripts_names).ask()

    index = scripts_names.index(response)

    script = scripts[index]
    script()
Exemplo n.º 9
0
 def __init__(self, parent=None):
     super(MyScriptEdit, self).__init__(parent)
     self.current_format = known_script_formats[0]
     self.script = Script()
     self.textChanged.connect(self.on_text_changed)
     self.setFont(monospace_font)
Exemplo n.º 10
0
class ScriptEdit(QTextEdit):
    """Script editor.

    Keeps an internal Script instance that it updates
    with its text, and uses to convert formats.
    """
    def __init__(self, parent=None):
        super(ScriptEdit, self).__init__(parent)
        self.current_format = 'Human'
        self.script = Script()
        self.textChanged.connect(self.on_text_changed)
        self.setFont(monospace_font)
        # For tooltips
        self.context = []

    def on_text_changed(self):
        txt = str(self.toPlainText())
        self.set_data(txt, self.current_format)

    def copy_hex(self):
        txt = self.get_data('Hex')
        QApplication.clipboard().setText(txt)

    def contextMenuEvent(self, e):
        menu = self.createStandardContextMenu()
        menu.addAction('Copy Hex', self.copy_hex)
        menu.exec_(e.globalPos())

    def set_format(self, fmt):
        self.current_format = fmt
        self.setPlainText(self.get_data())

    def set_data(self, text, fmt):
        script = None
        if fmt == 'Hex' and len(text) % 2 == 0:
            try:
                script = Script(text.decode('hex'))
            except Exception:
                pass
        elif fmt == 'Human':
            txt, self.context = transform_human(text)
            script = Script.from_human(txt)
        self.script = script

    def get_data(self, fmt=None):
        if fmt is None:
            fmt = self.current_format
        if not self.script: return ''
        if fmt == 'Hex':
            return self.script.get_hex()
        elif fmt == 'Human':
            return self.script.get_human()

    def event(self, e):
        if e.type() == QEvent.ToolTip:
            cursor = self.cursorForPosition(e.pos())
            context = self.get_tooltip(cursor.position())
            if not context:
                QToolTip.hideText()
            else:
                QToolTip.showText(e.globalPos(), context)
            return True
        return super(ScriptEdit, self).event(e)

    def get_tooltip(self, index):
        """Returns the contextual tip for the word at index."""
        if index < 0 or len(self.toPlainText()) < index:
            return ''
        for start, end, value, match_type in self.context:
            if index >= start and index < end:
                return '{} ({})'.format(value, match_type)