Beispiel #1
0
    def run(self):

        df = dd.read_csv(mods.get_file("daskin_" + g.PARAMS['tab']),
                         delimiter=";",
                         header=None,
                         usecols=[0, 1, g.PARAMS['col']],
                         names=["source", "target", "score"],
                         dtype={'score': 'float64'})
        df = df[df['source'] != df['target']]
        a = df.loc[:, ['source', 'target']].min(axis=1)
        b = df.loc[:, ['source', 'target']].max(axis=1)
        df['source'] = a
        df['target'] = b

        if (g.PARAMS['threshold'] == "ev"):
            df = df.groupby(['source', 'target']).min()['score'].reset_index()
        elif (g.PARAMS['threshold'] == "bs"):
            df = df.groupby(['source', 'target']).max()['score'].reset_index()

        df.to_csv(mods.get_file("tmp"),
                  compute=True,
                  index=False,
                  sep=';',
                  header=None)

        queue.pop_queue()

        return
Beispiel #2
0
    def run(self):

        folders = mods.get_folders(g.PARAMS['tab'])

        for folder in folders:
            create_dir(folders[folder])

        if (g.PARAMS['tab'] == "metanodes"):
            new_networks_path = folders['networks'] + "/" + os.path.basename(
                g.FILES['input'])

            try:
                copyfile(g.FILES['input'], new_networks_path)
            except Exception:
                pass

        sys.stderr = mods.RedirectError()
        g.PARAMS['write_to_logfile'] = 1
        print(ssn.text['dsp'] + str(g.PARAMS['dsp']))
        print(ssn.text['input'] + g.FILES['input'])
        print(ssn.text['output'] + g.FOLDERS['output'])

        queue.pop_queue()

        return
Beispiel #3
0
    def run(self):
        if (g.PARAMS['tab'] == "ssn"):
            g.PARAMS['num_seqs'] = mods.HandleFasta.count_fasta(
                g.FILES['input'])

        if (g.PARAMS['threshold'] == "ev"):
            g.PARAMS['parameter'] = "E-value"
            g.PARAMS['col'] = 2
        elif (g.PARAMS['threshold'] == "bs"):
            g.PARAMS['parameter'] = "Bitscore"
            if ((g.PARAMS['tab'] == "ssn") or (g.PARAMS['tab'] == "refine")):
                g.PARAMS['col'] = 3
            elif (g.PARAMS['tab'] == "metanodes"):
                g.PARAMS['col'] = 2

        if ((g.PARAMS['tab'] == "ssn") or (g.PARAMS['tab'] == "refine")):
            if (g.PARAMS['min'] != g.PARAMS['max']):
                even_threshold_max = ceil(
                    (g.PARAMS['max'] - g.PARAMS['min']) /
                    g.PARAMS['step']) * g.PARAMS['step'] + g.PARAMS['min']
                if (even_threshold_max != g.PARAMS['max']):
                    g.PARAMS['max'] = even_threshold_max
                g.PARAMS['num_ssn'] = (g.PARAMS['max'] -
                                       g.PARAMS['min']) / g.PARAMS['step'] + 1
            else:
                g.PARAMS['num_ssn'] = 1

        outfmt = []
        if (g.PARAMS['outfmt_cs'] == 1):
            outfmt.append("Cytoscape")
        if (g.PARAMS['outfmt_pj'] == 1):
            outfmt.append("Pajek")
        if (g.PARAMS['outfmt_gp'] == 1):
            outfmt.append("Gephi")

        g.PARAMS['format'] = ', '.join(outfmt)

        print(ssn.text['outfmt'] + g.PARAMS['format'])
        print(ssn.text['score'] + g.PARAMS['parameter'])
        if ((g.PARAMS['tab'] == "ssn") or (g.PARAMS['tab'] == "refine")):
            print(ssn.text['min'] + str(g.PARAMS['min']))
            print(ssn.text['step'] + str(g.PARAMS['step']))
            print(ssn.text['max'] + str(g.PARAMS['max']))
            print(ssn.text['num_ssn'] + str(g.PARAMS['num_ssn']))
        elif (g.PARAMS['tab'] == "metanodes"):
            print(ssn.text['meta_min'] + str(g.PARAMS['min']))
            print(ssn.text['meta_max'] + str(g.PARAMS['max']))
        elif (g.PARAMS['tab'] == "analysis"):
            print(ssn.text['meta_min'] + str(g.PARAMS['min']))

        queue.pop_queue()

        return
Beispiel #4
0
   def run(self):

      filenames = glob(mods.get_file("master_in"))
      with open(mods.get_file("masterfile"), 'w') as out:
         for fastaheader in SeqIO.parse(mods.get_file("newhead"), "fasta"):
            out.write(fastaheader.description + ";0;0;0;0;0;0\n")
         for fn in filenames:
            if (g.SSN_QUEUE[0] == "stop"):
               break
            with open(fn) as f:
               for line in f:
                  if (len(line.rstrip()) != 0):
                     out.write(line)

      queue.pop_queue()

      return
Beispiel #5
0
    def run(self):
        warning = 0
        infile = glob(mods.get_file("tmp"))

        if ((g.PARAMS['outfmt_pj'] == 1) or (g.PARAMS['outfmt_cs'] == 1)):
            if ((g.PARAMS['tab'] == "ssn") or (g.PARAMS['tab'] == "refine")):
                outfile = mods.get_file("networks_cs") % int(g.PARAMS['min'])
            elif (g.PARAMS['tab'] == "metanodes"):
                outfile = mods.get_file("metanodes_cs") % int(g.PARAMS['max'])
            mods.FormatOutput.cytoscape(infile, outfile, g.PARAMS['min'], ";",
                                        "\t", 1)
            warning = warning + mods.analysis_network(outfile, g.PARAMS['min'],
                                                      "\t")

        if (g.PARAMS['outfmt_gp'] == 1):
            if ((g.PARAMS['tab'] == "ssn") or (g.PARAMS['tab'] == "refine")):
                outfile = mods.get_file("networks_gp") % int(g.PARAMS['min'])
            elif (g.PARAMS['tab'] == "metanodes"):
                outfile = mods.get_file("metanodes_gp") % int(g.PARAMS['max'])
            mods.FormatOutput.gephi(infile, outfile, g.PARAMS['min'], ";", ";",
                                    1)
            warning = warning + mods.analysis_network(outfile, g.PARAMS['min'],
                                                      ";")

        if (g.PARAMS['outfmt_pj'] == 1):
            outfile = mods.get_file("networks_pj") % int(g.PARAMS['min'])
            infile = mods.get_file("networks_cs") % int(g.PARAMS['min'])
            mods.FormatOutput.pajek(infile, outfile)

        if (g.PARAMS['step'] != 0):
            for i in range(g.PARAMS['min'] + g.PARAMS['step'],
                           g.PARAMS['max'] + g.PARAMS['step'],
                           g.PARAMS['step']):
                if (g.SSN_QUEUE[0] == "stop"):
                    break
                if ((g.PARAMS['outfmt_pj'] == 1)
                        or (g.PARAMS['outfmt_cs'] == 1)):
                    infile = [
                        mods.get_file("networks_cs") %
                        int(i - g.PARAMS['step'])
                    ]
                    outfile = mods.get_file("networks_cs") % int(i)
                    mods.FormatOutput.cytoscape(infile, outfile, i, "\t", "\t",
                                                0)
                    warning = warning + mods.analysis_network(outfile, i, "\t")

                if (g.PARAMS['outfmt_gp'] == 1):
                    infile = [
                        mods.get_file("networks_gp") %
                        int(i - g.PARAMS['step'])
                    ]
                    outfile = mods.get_file("networks_gp") % int(i)
                    mods.FormatOutput.gephi(infile, outfile, i, ";", ";", 0)
                    warning = warning + mods.analysis_network(outfile, i, ";")

                if (g.PARAMS['outfmt_pj'] == 1):
                    infile = mods.get_file("networks_cs") % int(i)
                    outfile = mods.get_file("networks_pj") % int(i)
                    mods.FormatOutput.pajek(infile, outfile)

        if (warning >= 1):
            print(ssn.text['edge_warning'] % ssn.settings['edge_limit'] +
                  ssn.text['edge_solution'])

        queue.pop_queue()

        return
Beispiel #6
0
 def kill(self, proc_pid):
    process = psutil.Process(proc_pid)
    for proc in process.children(recursive=True):
          proc.kill()
    process.kill()
    queue.pop_queue()
Beispiel #7
0
 def check_sub(self):
    if self.proc.poll() is not None:
       queue.pop_queue()
Beispiel #8
0
 def write(self, message):
    self.log.write(message)
    queue.pop_queue("error")
Beispiel #9
0
 def run(self):
    rmtree(mods.get_folders(g.PARAMS['tab'])['tmp'])
    queue.pop_queue()
    return
Beispiel #10
0
    def run(self):
        if (g.PARAMS['outfmt_cs'] == 1):
            delimiter = "\t"
        elif (g.PARAMS['outfmt_gp'] == 1):
            delimiter = ";"

        outfile = mods.get_file("metanodes")

        if ((g.PARAMS['tab'] == "metanodes") and (g.PARAMS['outfmt_cs'] == 1)):
            parentfile = mods.get_file("metanodes_info_cs")
        elif ((g.PARAMS['tab'] == "metanodes")
              and (g.PARAMS['outfmt_gp'] == 1)):
            parentfile = mods.get_file("metanodes_info_gp")
        elif ((g.PARAMS['tab'] == "analysis") and
              ((g.PARAMS['outfmt_cs'] == 1) or (g.PARAMS['outfmt_gp'] == 1))):
            parentfile = mods.get_file("analysis")

        if (g.PARAMS['outfmt_cs'] == 1):
            infile = mods.get_file("networks_cs") % int(g.PARAMS['min'])
            mods.FormatOutput.cytoscape([infile], outfile, g.PARAMS['max'],
                                        delimiter, delimiter, 2)

        if (g.PARAMS['outfmt_gp'] == 1):
            infile = mods.get_file("networks_gp") % int(g.PARAMS['min'])
            mods.FormatOutput.gephi([infile], outfile, g.PARAMS['max'],
                                    delimiter, delimiter, 2)

        meta = dict()
        H = nx.read_weighted_edgelist(outfile, delimiter=delimiter)
        connected_components = sorted(nx.connected_components(H),
                                      key=len,
                                      reverse=True)

        with open(parentfile, "w") as parent:
            if (g.PARAMS['tab'] == "metanodes"):
                parent.write("Metanode" + delimiter + "Size" + delimiter +
                             "Subnodes\n")
            elif (g.PARAMS['tab'] == "analysis"):
                parent.write("Node\tSubgroup\n")

            i = 1
            for group in connected_components:
                group = list(group)
                if (g.PARAMS['tab'] == "metanodes"):
                    parent.write(
                        str(group[0]) + delimiter + str(len(group)) +
                        delimiter + str(", ".join(group)) + "\n")
                    for entry in group:
                        meta.update({entry: group[0]})
                elif (g.PARAMS['tab'] == "analysis"):
                    for entry in group:
                        meta.update({entry: group[0]})
                        parent.write(str(entry) + "\t" + str(i) + "\n")
                    i = i + 1

        if (g.PARAMS['tab'] == "metanodes"):
            with open(mods.get_file("daskin_" + g.PARAMS['tab']),
                      "w") as out, open(parentfile, "a") as parent:
                with open(infile) as f:
                    next(f)
                    for line in f:
                        field = line.rstrip().split(delimiter)
                        if (len(field) >= 2):
                            if meta.get(field[0]) is None:
                                f_zero = field[0]
                            else:
                                f_zero = meta.get(field[0])

                            if meta.get(field[1]) is None:
                                f_one = field[1]
                            else:
                                f_one = meta.get(field[1])
                            out.write(
                                str(f_zero) + ";" + str(f_one) + ";" +
                                str(field[2]) + "\n")
                        elif ((len(field) == 1)
                              and (meta.get(field[0]) is None)):
                            parent.write(field[0] + delimiter + "1" +
                                         delimiter + field[0] + "\n")

        if (g.PARAMS['tab'] == "analysis"):
            with open(parentfile, "a") as parent:
                with open(infile) as f:
                    next(f)
                    for line in f:
                        field = line.rstrip().split(delimiter)
                        if ((len(field) == 1)
                                and (meta.get(field[0]) is None)):
                            parent.write(field[0] + delimiter + "0\n")

        queue.pop_queue()