Ejemplo n.º 1
0
    def Activated(self):
        mw = FreeCADGui.getMainWindow()

        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there's nothing open in the code pane, we don't need to close it
        if cqCodePane is None or len(cqCodePane.file.path) == 0:
            return

        # Check to see if we need to save the script
        if cqCodePane.dirty:
            reply = QtGui.QMessageBox.question(cqCodePane, "Save CadQuery Script", "Save script before closing?",
                                               QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel)

            if reply == QtGui.QMessageBox.Cancel:
                return

            if reply == QtGui.QMessageBox.Yes:
                # If we've got a file name already save it there, otherwise give a save-as dialog
                if len(cqCodePane.file.path) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), "/home/",
                                                                 mw.tr("CadQuery Files (*.py)"))
                else:
                    filename = cqCodePane.file.path

                # Make sure we got a valid file name
                if filename is not None:
                    ExportCQ.save(filename)

        Shared.closeActiveCodeWindow()
Ejemplo n.º 2
0
    def Activated(self):
        mw = FreeCADGui.getMainWindow()

        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there's nothing open in the code pane, we don't need to close it
        if cqCodePane is None or len(cqCodePane.get_path()) == 0:
            return

        # Check to see if we need to save the script
        if cqCodePane.is_dirty():
            reply = QtGui.QMessageBox.question(cqCodePane, "Save CadQuery Script", "Save script before closing?",
                                               QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel)

            if reply == QtGui.QMessageBox.Cancel:
                return

            if reply == QtGui.QMessageBox.Yes:
                # If we've got a file name already save it there, otherwise give a save-as dialog
                if len(cqCodePane.get_path()) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), "/home/",
                                                                 mw.tr("CadQuery Files (*.py)"))
                else:
                    filename = cqCodePane.get_path()

                # Make sure we got a valid file name
                if filename is not None:
                    ExportCQ.save(filename)

        Shared.closeActiveCodeWindow()
Ejemplo n.º 3
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there is no script to check, ignore this command
        if cqCodePane is None:
            FreeCAD.Console.PrintMessage("There is no script to validate.")
            return

        # Clear the old render before re-rendering
        Shared.clearActiveDocument()

        scriptText = cqCodePane.toPlainText().encode('utf-8')

        if (b"show_object(" not in scriptText) and  (b"debug(" not in scriptText):
            FreeCAD.Console.PrintError("Script did not call show_object or debug, no output available. Script must be CQGI compliant to get build output, variable editing and validation.\r\n")
            return

        # A repreentation of the CQ script with all the metadata attached
        cqModel = cqgi.parse(scriptText)

        # Allows us to present parameters to users later that they can alter
        parameters = cqModel.metadata.parameters

        Shared.populateParameterEditor(parameters)
Ejemplo n.º 4
0
    def Activated(self):
        # So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = Shared.getActiveCodePane()

        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        # Make sure the user didn't click cancel
        if filename[0]:
            # Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.get_path()))[0]
                FreeCAD.closeDocument(docname)
            except:
                # Assume that there was no 3D view to close
                pass

            # Change the name of our script window's tab
            Shared.setActiveWindowTitle(os.path.basename(filename[0]))

            # Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
Ejemplo n.º 5
0
def process(entry, result):
    # Auction - margin
    margin = round(float(entry["margin"]), 2)
    sd.add_to_result(result, margin, margins_)

    # Auction - tmax
    tmax = entry["tmax"]
    if not tmax == "None":
        # Determine if tmax is multiple of 5 or 10
        if tmax % 5 == 0:
            result.append(1)
        else:
            result.append(0)

        if tmax % 10 == 0:
            result.append(1)
        else:
            result.append(0)

        for thres in [500, 700]:
            if tmax <= thres:
                result.append(1)
            else:
                result.append(0)

        index = 0
        tmax_list = [30, 45, 50, 70, 85, 1000]
        for item in tmax_list:
            if tmax == item:
                result.append(1)
                result.extend([0]*(len(tmax_list)-index-1))
                break
            result.append(0)
            index += 1
        if index >= len(tmax_list):
            result.append(1)
        else:
            result.append(0)

        result.append(0)
    else:
        result.extend([0]*11)
        result.append(1)    # Use the last column to indicate missing tmax

    # Auction - bkc
    bkc_result = [0]*(len(bkcids_)+2)
    bkc_str = entry["bkc"]
    if len(bkc_str) == 0:
        bkc_result[len(bkc_result)-1] = 1
    else:
        bkc_list = bkc_str.split(",")
        for item in bkc_list:
            try:
                index = bkcids_.index(item)
            except:
                index = len(bkc_result)-2
            bkc_result[index] = 1
    result.extend(bkc_result)

    return margin
Ejemplo n.º 6
0
 def operate_on(self,G):
     # Operate on a hairy graph by deleting an edge and adding a hair to one of the vertices adjacent to the
     # deleted edge.
     sgn0 = -1 if G.order() % 2 else 1
     image=[]
     for (i, e) in enumerate(G.edges(labels=False)):
         (u, v) = e
         # Only edges not connected to a hair-vertex can be cut
         if u >= self.domain.n_vertices or v >= self.domain.n_vertices:
             continue
         G1 = copy(G)
         if not self.domain.even_edges:
             Shared.enumerate_edges(G1)
             e_label = G1.edge_label(u, v)
         G1.delete_edge((u, v))
         new_hair_idx = self.domain.n_vertices + self.domain.n_hairs
         G1.add_vertex(new_hair_idx)
         G2 = copy(G1)
         G1.add_edge((u, new_hair_idx))
         G2.add_edge((v, new_hair_idx))
         if not self.domain.even_edges:
             G1.set_edge_label(u, new_hair_idx, e_label)
             G2.set_edge_label(v, new_hair_idx, e_label)
             sgn1 = Shared.edge_perm_sign(G1)
             sgn2 = Shared.edge_perm_sign(G2)
         else:
             sgn1 = 1
             sgn2 = -1
         image.append((G1, sgn1*sgn0))
         image.append((G2, sgn2*sgn0))
     return image
Ejemplo n.º 7
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there is no script to check, ignore this command
        if cqCodePane is None:
            FreeCAD.Console.PrintMessage("There is no script to validate.")
            return

        # Clear the old render before re-rendering
        Shared.clearActiveDocument()

        scriptText = cqCodePane.toPlainText().encode('utf-8')

        if ("show_object(" not in scriptText and "# show_object(" in scriptText and "#show_boject(" in scriptText) or ("debug(" not in scriptText and "# debug(" in scriptText and "#debug(" in scriptText):
            FreeCAD.Console.PrintError("Script did not call show_object or debug, no output available. Script must be CQGI compliant to get build output, variable editing and validation.\r\n")
            return

        # A repreentation of the CQ script with all the metadata attached
        cqModel = cqgi.parse(scriptText)

        # Allows us to present parameters to users later that they can alter
        parameters = cqModel.metadata.parameters

        Shared.populateParameterEditor(parameters)
Ejemplo n.º 8
0
 def operate_on(self, G):
     # Operates on the graph G by contracting an edge and unifying the adjacent vertices.
     image = []
     for (i, e) in enumerate(G.edges(labels=False)):
         (u, v) = e
         # print("contract", u, v)
         pp = Shared.permute_to_left((u, v), range(0,
                                                   self.domain.n_vertices))
         sgn = self.domain.perm_sign(G, pp)
         G1 = copy(G)
         G1.relabel(pp, inplace=True)
         Shared.enumerate_edges(G1)
         previous_size = G1.size()
         G1.merge_vertices([0, 1])
         if (previous_size - G1.size()) != 1:
             continue
         # print(sgn)
         G1.relabel(list(range(0, G1.order())), inplace=True)
         if not self.domain.even_edges:
             # p = [j for (a, b, j) in G1.edges()]
             # sgn *= Permutation(p).signature()
             sgn *= Shared.shifted_edge_perm_sign(G1)
         else:
             sgn *= -1  # TODO overall sign for even edges
         image.append((G1, sgn))
     return image
Ejemplo n.º 9
0
    async def mmr_handle(self, message: discord.Message):
        if not Shared.has_prefix(message.content):
            return False
        if self.is_mmr_check(message.content):
            await self.send_mmr(message)
            return True
        elif message.content == "!runners":
            runner_list = []
            for member in message.guild.members:
                if Shared.has_runner_role(member):
                    runner_list.append(
                        (member.display_name,
                         Shared.get_runner_role_ids(member, True)))

            runner_list.sort()
            print("Members with a runner role:\n")
            for runner in runner_list:
                print(runner[0] + "\t\t" + str(runner[1][0]))
        elif message.content == "!baggers":
            bagger_list = []
            for member in message.guild.members:
                if Shared.has_bagger_role(member):
                    bagger_list.append(
                        (member.display_name,
                         Shared.get_bagger_role_ids(member, True)))

            bagger_list.sort()
            print("Members with a bagger role:\n")
            for bagger in bagger_list:
                print(bagger[0] + "\t\t" + str(bagger[1][0]))

        return False
Ejemplo n.º 10
0
def get_calb_orths_in_sp():
    pom_db = GenomicFeatures.default_pom_db()
    
    ortholog_table = pd.read_csv(Shared.get_dependency("albicans", "C_albicans_SC5314_S_pombe_orthologs.txt"),
                                 skiprows=8,
                                 delimiter='\t',
                                 header=None,
                                 usecols=['albicans standard name', 'pombe standard name'],
                                 names=['albicans standard name', 'albicans common name', 'albicans alb_db id',
                                        'pombe standard name', 'pombe common name', 'pombe alb_db id'])
    
    # TODO: we probably don't want to use the hit table, though the InParanoid
    # table is very stringent.
    best_hit_table = pd.read_csv(Shared.get_dependency("albicans", "C_albicans_SC5314_S_pombe_best_hits.txt"),
                                 skiprows=8,
                                 delimiter='\t',
                                 header=None,
                                 usecols=['albicans standard name', 'pombe standard name'],
                                 names=['albicans standard name', 'albicans common name', 'albicans alb_db id',
                                        'pombe standard name', 'pombe common name', 'pombe alb_db id'])
    
    joined_table = pd.concat([ortholog_table, best_hit_table])
    
    result = {}
    for alb_feature in GenomicFeatures.default_alb_db().get_all_features():
        ortholog_row = joined_table[joined_table["albicans standard name"] == alb_feature.standard_name]
        if ortholog_row.empty:
            continue
        
        pom_feature = pom_db.get_feature_by_name(ortholog_row["pombe standard name"].iloc[0])
        if pom_feature:
            result[alb_feature.standard_name] = pom_feature.name
    
    return result
Ejemplo n.º 11
0
 async def send_bag_message(self, message: discord.Message, error_code=0):
     if error_code == 0:
         await message.channel.send(message.author.display_name +
                                    " has joined the war as a bagger",
                                    delete_after=quick_delete)
     elif error_code == 1:
         await message.channel.send(message.author.display_name +
                                    " is already in the war as a bagger",
                                    delete_after=quick_delete)
     elif error_code == 2:
         msg_str = message.author.display_name + " cannot bag in this tier"
         required_role_names = Shared.get_required_bagger_role_names(
             Shared.get_tier_number(self.channel))
         if required_role_names != None and len(required_role_names) > 0:
             msg_str += " - must be "
             for role_name in required_role_names:
                 msg_str += role_name + " or "
             msg_str = msg_str[:-4]
         await message.channel.send(msg_str, delete_after=quick_delete)
     elif error_code == 3:
         await message.channel.send(
             message.author.display_name +
             " cannot join the war because it already has " +
             str(DEFAULT_BAGGER_SIZE) + " baggers",
             delete_after=quick_delete)
     elif error_code == 4:
         await message.channel.send(
             message.author.display_name +
             " cannot join the war because it is completely full",
             delete_after=quick_delete)
     elif error_code == 5:
         await message.channel.send(message.author.display_name +
                                    " has changed to a bagger",
                                    delete_after=quick_delete)
Ejemplo n.º 12
0
 def can_bag(self, message: discord.message):
     player = self.get(message.author)
     tier_number = Shared.get_tier_number(message.channel)
     if player == None:  #They are joining as a new player
         if self.isFull():
             if len(self.mogi_list) >= DEFAULT_MOGI_SIZE + MAX_SUBS:
                 return 4
             else:
                 if Shared.can_bag_in_tier(message.author, tier_number):
                     return 0
                 else:
                     return 2
         elif self.countBaggers() >= DEFAULT_BAGGER_SIZE:
             return 3
         else:
             if Shared.can_bag_in_tier(message.author, tier_number):
                 return 0
             else:
                 return 2
     elif player.is_bagger():
         return 1
     else:
         if self.countBaggers() >= DEFAULT_BAGGER_SIZE:
             return 3
         elif Shared.can_bag_in_tier(message.author, tier_number):
             return 5
         else:
             return 2
Ejemplo n.º 13
0
    def Activated(self):
        # So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = Shared.getActiveCodePane()

        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        # Make sure the user didn't click cancel
        if filename[0]:
            # Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
                FreeCAD.closeDocument(docname)
            except:
                # Assume that there was no 3D view to close
                pass

            # Change the name of our script window's tab
            Shared.setActiveWindowTitle(os.path.basename(filename[0]))

            # Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
Ejemplo n.º 14
0
 def get_nominal_annotations(self):
     """Get nominal essentials and non-essentails in cerevisiae.
     
     Returns
     -------
     (set, set)
         A pair sets, denoting the essential and non-essential genes, using
         their standard names.
     """
     
     viable_filepath = Shared.get_dependency("cerevisiae", "cerevisiae_viable_annotations.txt")
     inviable_filepath = Shared.get_dependency("cerevisiae", "cerevisiae_inviable_annotations.txt")
     
     viable_table = pd.read_csv(viable_filepath, skiprows=8, delimiter="\t")
     inviable_table = pd.read_csv(inviable_filepath, skiprows=8, delimiter="\t")
     
     annotated_as_viable = set(self.feature_db.get_feature_by_name(f) for f in set(viable_table[viable_table["Mutant Information"] == "null"]["Gene"])) - set([None])
     annotated_as_inviable = set(self.feature_db.get_feature_by_name(f) for f in set(inviable_table[inviable_table["Mutant Information"] == "null"]["Gene"])) - set([None])
     
     # TODO: the dubious genes shouldn't be filtered here.
     consensus_viable_orfs = [f for f in annotated_as_viable if f.is_orf and f.feature_qualifier != "Dubious"]
     consensus_inviable_orfs = [f for f in annotated_as_inviable if f.is_orf and f.feature_qualifier != "Dubious"]
     
     return (set(f.standard_name for f in consensus_inviable_orfs),
             set(f.standard_name for f in consensus_viable_orfs))
def on_exit():
    Shared.backup_files()
    Leaderboard.pickle_stats()
    Leaderboard.pickle_player_countries()
    Shared.pickle_blacklisted_users()

    print("Exiting...")
Ejemplo n.º 16
0
async def on_ready():
    """global user_flag_exceptions
    unlockCheck.start()"""

    global tier_mogi_instances
    global bot_started

    if not bot_started:
        if tier_mogi_instances is None:
            tier_mogi_instances = {}
            #TODO: COme back here
            if os.path.exists(pickle_dump_path):
                guild = client.get_guild(new_pug_lounge_server_id)
                members = guild.members
                channels = guild.text_channels
                picklable_dict = {}
                with open(pickle_dump_path, "rb") as pickle_in:
                    try:
                        picklable_dict = p.load(pickle_in)
                    except:
                        print("Could not read tier instances in.")
                        picklable_dict = {}
                        raise

                new_tier_instances = {}
                for channel_id, picklable_tier_mogi in picklable_dict.items():
                    cur_channel = get_channel(channels,
                                              picklable_tier_mogi.channel_id)
                    if cur_channel == None:
                        continue

                    mogi_list = []
                    player_error = False
                    for picklable_player in picklable_tier_mogi.mogi_list:
                        curPlayer = Player.Player(None, None)
                        curMember = get_member(members,
                                               picklable_player.member_id)
                        if curMember == None:
                            player_error = True
                        else:
                            curPlayer.reconstruct(picklable_player, curMember)
                            mogi_list.append(curPlayer)
                    curTier = TierMogi.TierMogi(None)
                    curTier.reconstruct(mogi_list, cur_channel,
                                        picklable_tier_mogi)
                    if player_error:
                        curTier.recalculate()
                    new_tier_instances[channel_id] = curTier

                tier_mogi_instances = new_tier_instances

        if Shared.player_fcs == None:
            Shared.load_player_fc_pickle()

        routine_tier_checks.start()
        backup_data.start()
        routine_force_vote_checks.start()
        print("Finished on ready.")
        bot_started = True
Ejemplo n.º 17
0
    def _test_anti_commutativity_for_quadruple(self, quadruple, commute=False, eps=Parameters.commute_test_eps):
        (op1a, op1b, op2a, op2b) = quadruple
        if not ((op1a.is_valid() and op2b.is_valid()) or (op2a.is_valid() and op1b.is_valid())):
            return 'triv'

        if op1a.is_valid() and op2b.is_valid() and (not (op2a.is_valid() and op1b.is_valid())):
            try:
                if op1a.is_trivial() or op2b.is_trivial():
                    return 'triv'
                M1a = op1a.get_matrix()
                M2b = op2b.get_matrix()
            except StoreLoad.FileNotFoundError:
                return 'inc'
            if Shared.matrix_norm(M2b * M1a) < eps:
                return 'succ'
            return 'fail'

        if (not (op1a.is_valid() and op2b.is_valid())) and op2a.is_valid() and op1b.is_valid():
            try:
                if op2a.is_trivial() or op1b.is_trivial():
                    return 'triv'
                M1b = op1b.get_matrix()
                M2a = op2a.get_matrix()
            except StoreLoad.FileNotFoundError:
                return 'inc'
            if Shared.matrix_norm(M1b * M2a) < eps:
                return 'succ'
            return 'fail'

        try:
            if (op1a.is_trivial() or op2b.is_trivial()) and (op2a.is_trivial() or op1b.is_trivial()):
                return 'triv'
            if (not (op1a.is_trivial() or op2b.is_trivial())) and (op2a.is_trivial() or op1b.is_trivial()):
                M1a = op1a.get_matrix()
                M2b = op2b.get_matrix()
                if Shared.matrix_norm(M2b * M1a) < eps:
                    return 'succ'
                else:
                    return 'fail'
            if (op1a.is_trivial() or op2b.is_trivial()) and (not (op2a.is_trivial() or op1b.is_trivial())):
                M1b = op1b.get_matrix()
                M2a = op2a.get_matrix()
                if Shared.matrix_norm(M1b * M2a) < eps:
                    return 'succ'
                else:
                    return 'fail'
            M1a = op1a.get_matrix()
            M2b = op2b.get_matrix()
            M1b = op1b.get_matrix()
            M2a = op2a.get_matrix()
            if Shared.matrix_norm(M2b * M1a + (-1 if commute else 1) * M1b * M2a) < eps:
                return 'succ'
            return 'fail'
        except StoreLoad.FileNotFoundError:
            return 'inc'
Ejemplo n.º 18
0
    def operate_on(self, G):
        # Operate on a bi colored hairy graph by deleting an edge and adding a hair of colour a to one of the adjacent
        # vertices and a hair of colour b to the other adjacent vertex.
        sgn0 = -1 if G.order() % 2 else 1
        image = []
        for (i, e) in enumerate(G.edges(labels=False)):
            (u, v) = e
            # Only edges not connected to a hair-vertex can be split.
            if u >= self.domain.n_vertices or v >= self.domain.n_vertices:
                continue
            G1 = copy(G)
            if not self.domain.even_edges:
                Shared.enumerate_edges(G1)
                e_label = G1.edge_label(u, v)
            G1.delete_edge((u, v))

            new_hair_idx_1 = self.domain.n_vertices + self.domain.n_hairs
            new_hair_idx_2 = new_hair_idx_1 + 1

            G1.add_vertex(new_hair_idx_1)
            G1.add_edge((u, new_hair_idx_1))
            G1.add_vertex(new_hair_idx_2)
            G1.add_edge((v, new_hair_idx_2))
            G2 = copy(G1)

            vertices = list(range(0, self.domain.n_vertices))
            vertices = [] if vertices is None else vertices
            start_idx_a = self.domain.n_vertices
            start_idx_b = self.domain.n_vertices + self.domain.n_hairs_a + 1
            hairs_a = list(range(start_idx_a + 1, start_idx_b))
            hairs_a = [] if hairs_a is None else hairs_a
            hairs_b = list(range(start_idx_b, new_hair_idx_2))
            hairs_b = [] if hairs_b is None else hairs_b
            p = vertices + hairs_a + hairs_b

            p1 = p + [start_idx_a, new_hair_idx_2]
            G1.relabel(p1)
            p2 = p + [new_hair_idx_2, start_idx_a]
            G2.relabel(p2)

            if not self.domain.even_edges:
                G1.set_edge_label(u, start_idx_a, e_label)
                G1.set_edge_label(v, new_hair_idx_2, G1.size() - 1)
                sgn1 = Shared.edge_perm_sign(G1)
                G2.set_edge_label(v, start_idx_a, e_label)
                G2.set_edge_label(u, new_hair_idx_2, G2.size() - 1)
                sgn2 = Shared.edge_perm_sign(G2)
            else:
                sgn1 = 1
                sgn2 = -1
            image.append((G1, sgn1 * sgn0))
            image.append((G2, sgn2 * sgn0))
        return image
Ejemplo n.º 19
0
def dashboard():

    error = None
    completedExps = None
    u = None
    try:
        if Shared.isLoggedIn():

            import models
            u = Shared.getLoggedInUser()

            exps = models.Experiment.query.filter_by(userId=int(session['u']))
            completedExps = exps.filter(
                Experiment.endDateTime != '--RUNNING--')
            cDataSets = [
                json.loads(ce.pars)['datasets'] for ce in completedExps
            ]

            md5Names = [
                ExpDA.generateViolinPlots(cexp) for cexp in completedExps
            ]
            plotFiles = [[
                '/static/plots/' + m + '/' + file
                for file in os.listdir(config.plotsPath + m)
                if file.endswith('.svg') and file.startswith('Method')
            ] for m in md5Names]
            runningExps = exps.filter(Experiment.endDateTime == '--RUNNING--')
            runningValid = []
            for r in runningExps:
                pid = json.loads(r.pars)['pid']
                if not Security.check_pid(pid):
                    runningValid.append(False)
                else:
                    runningValid.append(True)
                    #r.delete()
                    #db.session.commit()
            return render_template('users/dashboard.html',
                                   error=error,
                                   completedExps=completedExps,
                                   u=u,
                                   runningExps=runningExps,
                                   cDataSets=cDataSets,
                                   plotFiles=plotFiles,
                                   runningValid=runningValid)
    except Exception as exep:
        file = open('error.txt', 'w')
        file.write(str(exep))
        file.close()

    return redirect(url_for('BPUsers.login'))
Ejemplo n.º 20
0
def create_app(**config):
    app = Flask("4ops", debug=True)
    app.config.update(FSA_AUTH="fake",
                      FSA_GET_USER_PASS=get_user_pass,
                      FSA_USER_IN_GROUP=user_in_group)
    app.config.update(**config)
    app.register_blueprint(subapp, url_prefix="/b")

    # self permission
    def check_users_access(user, val, mode):
        return user == val if val in UP else None

    app.object_perms("users", check_users_access)

    # shared stuff
    Shared.init_app(something="AppFact")

    @app.get("/mul", authorize=ALL)
    def get_mul(i: int, j: int):
        return str(i * j), 200

    @app.get("/add", authorize=ALL)
    def get_add(i: int, j: int):
        return str(i + j), 200

    @app.get("/div", authorize=ALL)
    def get_div(i: int, j: int):
        return str(i // j), 200

    @app.get("/sub", authorize=ALL)
    def get_sub(i: int, j: int):
        return str(i - j), 200

    @app.get("/something", authorize=ALL)
    def get_something():
        return str(something), 200

    @app.get("/admin", authorize=ADMIN)
    def get_admin():
        return "admin!", 200

    @app.get("/self/<login>", authorize=("users", "login"))
    def get_self_login(login: str):
        return f"hello: {login}", 200

    @app.get("/hits", authorize=ADMIN)
    def get_hits():
        return json((len(app._fsa._cache), app._fsa._cache.hits())), 200

    return app
Ejemplo n.º 21
0
    def perm_sign(self, G, p):
        if self.even_edges:
            # The total sign is:
            # (a:induced sign on vertices)
            # * (b:induced sign of the unmarked-edge-permutation)
            # * (c:induced sign unmarked-edge orientations)
            # * (d:induced sign marked-edge orientations)
            # note that we have no tadpoles in case of even edges

            # This is a*b
            sign = Shared.Perm([
                j for j in p if (j < self.n_vertices + self.n_unmarked_edges)
            ]).signature()
            # Now  * d
            for (u, v) in G.edges(labels=False):
                if (u < self.n_vertices and v < self.n_vertices):
                    # We assume the edge is always directed from the larger to smaller index
                    if (u < v and p[u] > p[v]) or (u > v and p[u] < p[v]):
                        sign *= -1
            # Finally * c
            for i in range(self.n_vertices,
                           self.n_vertices + self.n_unmarked_edges):
                nb = G.neighbors(i)
                if len(nb) != 2:
                    # This is a graph with a tadpole, and hence zero... we return zero for now, although this is not ideal.
                    return 0
                    # raise ValueError(
                    #    '%s: Vertices of second colour should have 2 neighbours' % str(self))
                u = nb[0]
                v = nb[1]
                if (u < v and p[u] > p[v]) or (u > v and p[u] < p[v]):
                    sign *= -1
            return sign
        else:
            # The sign is (induced sign of the marked-edge-permutation)
            # We assume the edges are always lexicographically ordered
            # For the computation we use that G.edges() returns the edges in lex ordering
            # We first label the edges on a copy of G lexicographically
            G1 = copy(G)
            self.label_marked_edges(G1)
            # print("edges before ", [j for (u, v, j) in G1.edges()])
            # We permute the graph, and read of the new labels, ...
            # but only those between internal vertices of the first color, i.e., the first n_vertices ones
            G1.relabel(p, inplace=True)
            # print("edges after ", [(u, v, j) for (u, v, j) in G1.edges()])

            return Shared.Perm([
                j for (u, v, j) in G1.edges()
                if (u < self.n_vertices and v < self.n_vertices)
            ]).signature()
Ejemplo n.º 22
0
def Update_Clients(new_client, new_address):
    new_client = Shared.Client(new_client, new_address)
    for client in sockets_client:
        try:
            Shared.send_address_list_tcp(client.socket, [new_address])
        except socket.timeout:
            sockets_closed.append(client)
            sockets_client.remove(client)
            addresses_client.remove(client.address)

    Shared.send_address_list_tcp(new_client.socket, addresses_client)

    sockets_client.append(new_client)
    addresses_client.append(new_address)
Ejemplo n.º 23
0
def initGame(game, **kwargs):
    Log.log("Firing up Loltris version {} from {!r}".format(
        VERSION, sys.argv[0]))

    ## Run setup (will decide for itself whether or not it is necessary)
    Setup.setupFiles()

    if CENTER_WINDOW:
        os.environ["SDL_VIDEO_CENTERED"] = "1"

    pygame.font.init()
    Shared.load()

    instance = game(**kwargs)
    instance.setup()
    return instance
Ejemplo n.º 24
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.get_path()) == 0 or os.path.basename(cqCodePane.get_path()) == 'script_template.py' \
                or os.path.split(cqCodePane.get_path())[0].endswith('FreeCAD'):
            FreeCAD.Console.PrintError(
                "You cannot save over a blank file, example file or template file.\r\n"
            )

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module"
        ).GetBool("executeOnSave"):
            CadQueryExecuteScript().Activated()
Ejemplo n.º 25
0
def init_db_data():
    user = Shared.getLoggedInUser()
    if user is not None:
        if user.utype == 1:
            pass

    return abort(403)
Ejemplo n.º 26
0
    def __on_word(self, word):
        current = Shared.get_or_create_node(self.nodeByWords, [word])

        for i in range(self.depth):
            previous_nodes = self.history[i:]
            previous_words = map(lambda node: node.key, previous_nodes)
            previous_node = Shared.get_or_create_node(self.nodeByWords,
                                                      previous_words)
            previous_node.increment(current)

        self.history.append(current)

        if len(self.history) > self.depth:
            self.history.pop(0)

        self.wordCount += 1
Ejemplo n.º 27
0
 async def send_stats(self, message:discord.Message, prefix=Shared.prefix):
     for_who = Shared.strip_prefix_and_command(message.content, mmr_lookup_terms, prefix)
     embed = discord.Embed(
                             title = "Stats - Coming soon...",
                             colour = discord.Colour.dark_blue()
                         )
     await message.channel.send(embed=embed, delete_after=long_delete)
Ejemplo n.º 28
0
 def get_ordered_cohomology_param_range_dict(self):
     deg_range = self.sum_vector_space.deg_range
     h_min_min = min(self.sum_vector_space.h_min_range)
     h_min_max = max(self.sum_vector_space.h_min_range) + (max(deg_range) -
                                                           min(deg_range))
     h_range = range(h_min_min, h_min_max + 1)
     return Shared.OrderedDict([('deg', deg_range), ('min_hairs', h_range)])
Ejemplo n.º 29
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py' \
                or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'):
            FreeCAD.Console.PrintError(
                "You cannot save over a blank file, example file or template file.\r\n"
            )

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if Settings.execute_on_save:
            CadQueryExecuteScript().Activated()
Ejemplo n.º 30
0
 def operate_on(self, G):
     # Operates on the graph G by contracting a marked edge and unifying the adjacent vertices.
     image = []
     for (u, v) in G.edges(labels=False):
         # only contract marked edges
         if (u < self.domain.n_vertices and v < self.domain.n_vertices):
             # move the two vertices to be merged to the first two positions
             pp = Shared.permute_to_left((u, v), range(0, G.order()))
             sgn = self.domain.perm_sign(G, pp)
             G1 = copy(G)
             G1.relabel(pp, inplace=True)
             self.domain.label_marked_edges(G1)
             # previous_size = G1.size()
             G1.merge_vertices([0, 1])
             # if (previous_size - G1.size()) != 1:
             #     continue
             G1.relabel(list(range(0, G1.order())), inplace=True)
             if not self.domain.even_edges:
                 # for odd edges compute the sign of the permutation of internal edges
                 p = [
                     j for (a, b, j) in G1.edges()
                     if (a < self.target.n_vertices
                         and b < self.target.n_vertices)
                 ]
                 # If we removed more then one marked edge stop
                 if len(p) < self.domain.n_marked_edges - 1:
                     print("This should not happen....")
                     continue
                 sgn *= Permutation(p).signature()
             else:
                 # There is no further sign for even edges
                 sgn *= 1  # TODO overall sign for even edges
             image.append((G1, sgn))
     return image
Ejemplo n.º 31
0
def show(cqObject, rgba=(204, 204, 204, 0.0)):
    import FreeCAD
    from random import random
    import os, tempfile
    import Shared

    #Convert our rgba values
    r = rgba[0] / 255.0
    g = rgba[1] / 255.0
    b = rgba[2] / 255.0
    a = int(rgba[3] * 100.0)

    # Grab our code editor so we can interact with it
    cqCodePane = Shared.getActiveCodePane()

    if cqCodePane != None:
        # Save our code to a tempfile and render it
        tempFile = tempfile.NamedTemporaryFile(delete=False)
        tempFile.write(cqCodePane.toPlainText().encode('utf-8'))
        tempFile.close()

        docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]

        # Make sure we replace any troublesome characters
        for ch in ['&', '#', '.', '$', '%', ',', ' ']:
            if ch in docname:
                docname = docname.replace(ch, "")

        # Translate dashes so that they can be safetly used since theyare common
        if '-' in docname:
            docname = docname.replace('-', "__")

        # If the matching 3D view has been closed, we need to open a new one
        try:
            FreeCAD.getDocument(docname)
        except NameError:
            # FreeCAD.Console.PrintError("Could not find the model document or invalid characters were used in the filename.\r\n")

            FreeCAD.newDocument(docname)

    ad = FreeCAD.activeDocument()

    # If we've got a blank shape name, we have to create a random ID
    if not cqObject.val().label:
        #Generate a random name for this shape in case we are doing multiple shapes
        newName = "Shape" + str(random())
    else:
        # We're going to trust the user to keep labels unique between shapes
        newName = cqObject.val().label

    #Set up the feature in the tree so we can manipulate its properties
    newFeature = ad.addObject("Part::Feature", newName)

    #Change our shape's properties accordingly
    newFeature.ViewObject.ShapeColor = (r, g, b)
    newFeature.ViewObject.Transparency = a
    newFeature.Shape = cqObject.toFreecad()

    ad.recompute()
Ejemplo n.º 32
0
def get_calb_orths_in_sp():
    pom_db = GenomicFeatures.default_pom_db()

    ortholog_table = pd.read_csv(
        Shared.get_dependency("albicans",
                              "C_albicans_SC5314_S_pombe_orthologs.txt"),
        skiprows=8,
        delimiter='\t',
        header=None,
        usecols=['albicans standard name', 'pombe standard name'],
        names=[
            'albicans standard name', 'albicans common name',
            'albicans alb_db id', 'pombe standard name', 'pombe common name',
            'pombe alb_db id'
        ])

    # TODO: we probably don't want to use the hit table, though the InParanoid
    # table is very stringent.
    best_hit_table = pd.read_csv(
        Shared.get_dependency("albicans",
                              "C_albicans_SC5314_S_pombe_best_hits.txt"),
        skiprows=8,
        delimiter='\t',
        header=None,
        usecols=['albicans standard name', 'pombe standard name'],
        names=[
            'albicans standard name', 'albicans common name',
            'albicans alb_db id', 'pombe standard name', 'pombe common name',
            'pombe alb_db id'
        ])

    joined_table = pd.concat([ortholog_table, best_hit_table])

    result = {}
    for alb_feature in GenomicFeatures.default_alb_db().get_all_features():
        ortholog_row = joined_table[joined_table["albicans standard name"] ==
                                    alb_feature.standard_name]
        if ortholog_row.empty:
            continue

        pom_feature = pom_db.get_feature_by_name(
            ortholog_row["pombe standard name"].iloc[0])
        if pom_feature:
            result[alb_feature.standard_name] = pom_feature.name

    return result
Ejemplo n.º 33
0
    def movePlayersTo(self, otherMogi):
        if self.start_time != None:
            return ALREADY_STARTED, None
        if otherMogi.start_time != None:
            return OTHER_ALREADY_STARTED, None
        if self.channel.category_id != otherMogi.channel.category_id:
            return OUTSIDE_OF_CATEGORY, None
        if Shared.get_tier_number(otherMogi.channel) == None:
            return NO_TIER_NUMBER, None

        hypothetical_new_mogi_list = [player for player in otherMogi.mogi_list]
        for player in self.mogi_list:
            if player not in otherMogi:
                hypothetical_new_mogi_list.append(player)
            elif player.is_runner() != otherMogi.get(player).is_runner():
                return BAGGER_RUNNER_TYPE_MISMATCH, None

        hypothetical_new_mogi_list.sort(key=lambda p: p.get_join_time())
        if len(hypothetical_new_mogi_list) > (DEFAULT_MOGI_SIZE + MAX_SUBS):
            return COMBINED_MOGI_TOO_LARGE, None

        bagger_count = sum(1 for p in hypothetical_new_mogi_list[:11]
                           if p.is_bagger())
        runner_count = sum(1 for p in hypothetical_new_mogi_list[:11]
                           if p.is_runner())

        if bagger_count > DEFAULT_BAGGER_SIZE:
            return TOO_MANY_BAGGERS, None
        if runner_count > DEFAULT_RUNNER_SIZE:
            return TOO_MANY_RUNNERS, None

        #check if each person could play in the new tier
        tier_num = Shared.get_tier_number(otherMogi.channel)
        for p in hypothetical_new_mogi_list:
            if p.is_runner():
                if not Shared.can_run_in_tier(p.member, tier_num):
                    return COULD_NOT_PLAY_IN_TIER, None
            else:
                if not Shared.can_bag_in_tier(p.member, tier_num):
                    return COULD_NOT_PLAY_IN_TIER, None

        moved_players = [p for p in self.mogi_list]
        self.mogi_list.clear()
        otherMogi.mogi_list = hypothetical_new_mogi_list
        otherMogi.recalculate()
        return SUCCESSFUL_APPEND, moved_players
Ejemplo n.º 34
0
def on_exit():
    print("Exiting...")
    global tier_mogi_instances
    global pickle_dump_path
    
    with open(pickle_dump_path, "wb") as pickle_out:
        try:
            mogis = {}
            for channel_id, mogi in tier_mogi_instances.items():
                mogis[channel_id] = mogi.getPicklableTierMogi()
            p.dump(mogis, pickle_out)
        except:
            print("Could not dump pickle for tier instances.")
            Shared.player_fc_pickle_dump()
            raise
        
    Shared.player_fc_pickle_dump()
Ejemplo n.º 35
0
 def _get_spom_essentials(self):
     viability_table = pd.read_csv(Shared.get_dependency("pombe/FYPOviability.tsv"),
                                   header=None,
                                   delimiter='\t',
                                   names=["pombe standard name", "essentiality"])
     
     return set(r[0] for _ix, r in viability_table.iterrows() if r[1] == "inviable"), \
         set(r[0] for _ix, r in viability_table.iterrows() if r[1] == "viable")
Ejemplo n.º 36
0
def main():
    parser = argparse.ArgumentParser(usage=usage)

    parser.add_argument("-1st", "--first-input-dir", required=True)
    parser.add_argument("-2nd", "--second-input-dir", required=True)
    parser.add_argument("-out", "--output-dir", default='.')
    parser.add_argument("-d",
                        "--histo-dist",
                        default=False,
                        action='store_true')
    parser.add_argument("-v",
                        "--venn-draw",
                        default=False,
                        action='store_true')

    args = parser.parse_args()

    first_input_dir = args.first_input_dir
    second_input_dir = args.second_input_dir
    output_dir = args.output_dir
    histo_dist = args.histo_dist
    venn_draw = args.venn_draw
    correlations = args.correlations

    Shared.make_dir(output_dir)

    first_name_path = get_filename_path(first_input_dir)
    first_name = first_name_path[0]
    second_name_path = get_filename_path(second_input_dir)
    second_name = second_name_path[0]

    first_analyzed_tupled = analyze_folder(first_name_path)
    first_analyzed_dataset = first_analyzed_tupled[0]
    second_analyzed_tupled = analyze_folder(second_name_path)
    second_analyzed_dataset = second_analyzed_tupled[0]

    data = compare_two_analyzed_datasets(first_name, first_analyzed_dataset,
                                         second_name, second_analyzed_dataset,
                                         output_dir, venn_draw, correlations)

    if venn_draw:
        draw_venn_diag(data, first_name, second_name, output_dir)

    if histo_dist:
        plot_s_scores(first_name, first_analyzed_dataset, second_name,
                      second_analyzed_dataset, output_dir)
async def on_ready():
    global finished_on_ready
    if not finished_on_ready:
        Leaderboard.load_player_pickle_data()
        Leaderboard.load_player_country_mapping()
        Leaderboard.load_stats_in()
        Shared.load_blacklisted_users()
        #Leaderboard.dump_data_to_csv() #Uncomment to dump the pulled data to a csv

        leaderboard_pull.start()
        removeInactiveInstances.start()
        updatePresence.start()
        checkBotAbuse.start()
        backup.start()

        print("Finished on ready.")
        finished_on_ready = True
Ejemplo n.º 38
0
def getMCN(trade, tradesmen, population):
    fig, ax = plt.subplots()
    neighbourhood = [x[trade] for n, x in tradesmen.items()]
    totalTradesmen = sum(neighbourhood)
    if(totalTradesmen > 20):
        perCapita = [n / p for n, p in zip(neighbourhood, population)]
        plt.title(Shared.getTradeName(trade))
        bimodal = analyze(fig, ax, trade, perCapita)
        return bimodal
    return -1
Ejemplo n.º 39
0
def recolourMap(values, trade):
    with open("florence-map-small.png", 'rb') as fp:
        fm = Image.open(fp)
        pixels = fm.load()
        for x in range(fm.width):
            for y in range(fm.height):
                px = pixels[x, y]
                for i, n in enumerate(Shared.getNeighbourhoods().keys()):
                    g = int(n / 10)
                    b = n % 10
                    if px[0] == 0 and px[1] == g and px[2] == b:
                        pixels[x, y] = (int(values[i] * 255), 0, 0, 255)
        fm.save("results/trademap_" + str(trade) + ".png")
    return fm
Ejemplo n.º 40
0
def main():
    parser = argparse.ArgumentParser(usage=usage)
    
    parser.add_argument("-1st", "--first-input-dir", required=True)
    parser.add_argument("-2nd", "--second-input-dir", required=True)
    parser.add_argument("-out", "--output-dir", default='.')
    parser.add_argument("-d", "--histo-dist", default=False, action='store_true')
    parser.add_argument("-v", "--venn-draw", default=False, action='store_true')
    
    args = parser.parse_args()
    
    first_input_dir = args.first_input_dir
    second_input_dir = args.second_input_dir
    output_dir = args.output_dir
    histo_dist = args.histo_dist
    venn_draw = args.venn_draw
    correlations = args.correlations
    
    Shared.make_dir(output_dir)
       
    first_name_path = get_filename_path(first_input_dir)
    first_name = first_name_path[0]    
    second_name_path = get_filename_path(second_input_dir)
    second_name = second_name_path[0]

    first_analyzed_tupled = analyze_folder(first_name_path)
    first_analyzed_dataset = first_analyzed_tupled[0]
    second_analyzed_tupled = analyze_folder(second_name_path)
    second_analyzed_dataset = second_analyzed_tupled[0]

    data = compare_two_analyzed_datasets(first_name, first_analyzed_dataset, second_name, second_analyzed_dataset, output_dir, venn_draw, correlations)

    if venn_draw:
        draw_venn_diag(data, first_name, second_name, output_dir)

    if histo_dist:
        plot_s_scores(first_name, first_analyzed_dataset, second_name, second_analyzed_dataset, output_dir)
Ejemplo n.º 41
0
 def parse_friend_connecting(self, value):
     a = value.split(',')
     friend_username = a[0]
     ip = a[1]
     port = a[2]
     print 'friend connecting: ' + friend_username + ' at ' + ip + ':'+  port
     
     friend = Shared.get_friend_by_username(friend_username)
     if friend:
         friend.sock = Shared.server.sock
         Shared.server.create_new_socket()
         Shared.server.login()
         threading.Thread(target=friend.start_punching, args=[(ip, int(port))]).start()
     else:
         print 'Connecting friend is not on friends list'
Ejemplo n.º 42
0
def parse_friend_connecting(value):
    a = value.split(',')
    friend_username = a[0]
    ip = a[1]
    port = a[2]
    print 'friend connecting: ' + friend_username + ' at ' + ip + ':' +  port
    
    friend = Shared.get_peer_by_username(friend_username)
    if friend:
        friend.sock = Shared.server.sleeping_sockets[0]
        Shared.server.sleeping_sockets.pop(0)
        friend.sock.setblocking(0)
        threading.Thread(target=friend.start_punching, args=[(ip, int(port))]).start()
        Shared.server.append_sleeping_socket() # TODO: maybe move into that thread ^
    else:
        print 'Connecting friend is not on friends list'
Ejemplo n.º 43
0
def save(filename=None):
    """
    Allows us to save the CQ script file to disk.
    :param filename: The path and file name to save to. If not provided we try to pull it from the code pane itself
    """

    #Grab our code editor so we can interact with it
    cqCodePane = Shared.getActiveCodePane()

    cqCodePane.save(filename)

    msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "Saved ",
            None)
    FreeCAD.Console.PrintMessage(msg + cqCodePane.get_path() + "\r\n")
Ejemplo n.º 44
0
 def parse(self, input):
     if input.strip() == 'exit':
         return True
     if input.strip() == 'help':
         print '''\nAvailable commands:
 > connect to friend: friend_username
 > send: friend_username: message to send
 > friend request: friend_username
 > accept friend request: friend_username
 > decline friend request: friend_username
 '''
         return False
         
     a = input.split(':')
     a[0] = a[0].lower().strip()
     a[1] = a[1].strip()
     
     
     #connect to friend: friend_username
     if a[0].startswith('connect to friend'):
         Shared.server.message(OpCodes.connect_to_friend, a[1])
     
     #send: friend_username: message to send
     elif a[0].startswith('send'):
         friend = Shared.get_friend_by_username(a[1])
         if friend:
             friend.message(input[input.find(':',input.find(':')+1) + 1:])
         else:
             print 'User ' + a[1] + ' not on friends list'
     
     #send friend request: friend_username
     elif a[0].startswith('friend request'):
         Shared.server.message(OpCodes.send_friend_request, a[1])
     
     #accept friend request: friend_username
     elif a[0].startswith('accept friend request'):
         Shared.server.message(OpCodes.accept_friend_request, a[1])
         Shared.friends_list.append(Friend.Friend(a[1], True))
     
     #decline friend request: friend_username
     elif a[0].startswith('decline friend request'):
         Shared.server.message(OpCodes.decline_friend_request, a[1])
         
     return False
def analyze_deletions(bam_file, threshold=50):
    bam_reader = pysam.AlignmentFile(bam_file, "rb")
    
    fasta_file = Shared.get_dependency(os.path.join("albicans", "reference genome", "C_albicans_SC5314_version_A22-s07-m01-r08_chromosomes_HapA.fasta"))
    chrom_names = []
    chrom_lens = {}
    for record in SeqIO.parse(fasta_file, "fasta"):
        chrom_names.append(record.id)
        chrom_lens[record.id] = RangeSet([(1, len(record))])
    
    seen = {chrom: [] for chrom in chrom_names}
    
    for read in bam_reader.fetch():
        chrom_name = bam_reader.getrname(read.reference_id)
        if "chrM" in chrom_name:
            continue
        seen[chrom_name].append((read.reference_start+1, read.reference_end-1+1))
            
    unseen = {chrom: chrom_lens[chrom] - RangeSet(seen[chrom]) for chrom in chrom_names}
    write_ranges(unseen, "/Users/bermanlab/dev/transposon-pipeline/dependencies/albicans/deleted_regions.csv")
    ranges = {chrom: [r for r in unseen[chrom] if r[1] - r[0] >= threshold] for chrom in chrom_names}
    
    pprint(ranges)
    
    print "Total unseen:", sum(r.coverage for r in unseen.values())
    print "Total filtered unseen:", sum(sum(r[1]-r[0]+1 for r in rs) for rs in ranges.values())
    
    for chrom in chrom_names:
        print chrom
        print "Total subranges:", len(unseen[chrom])
        print "Total length:", unseen[chrom].coverage
        print "Ignored long subranges:", len(ranges[chrom])
        print "Total length:", sum(r[1]-r[0]+1 for r in ranges[chrom])
        print "\n"
        
        import GenomicFeatures
        alb_db = GenomicFeatures.default_alb_db()
        for r in unseen[chrom]:
            fs = alb_db.get_features_at_range(chrom, r)
            if fs:
                print chrom, r, ", ".join(f.standard_name for f in fs)
                
        print "\n"
Ejemplo n.º 46
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.get_path()) == 0 or os.path.basename(cqCodePane.get_path()) == 'script_template.py' \
                or os.path.split(cqCodePane.get_path())[0].endswith('FreeCAD'):
            FreeCAD.Console.PrintError("You cannot save over a blank file, example file or template file.\r\n")

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetBool("executeOnSave"):
            CadQueryExecuteScript().Activated()
Ejemplo n.º 47
0
from matplotlib.collections import PatchCollection
import scipy.stats
import sklearn.cluster
import networkx as nx

def analyze(t1Data, t2Data):
    m1 = max(t1Data)
    m2 = max(t2Data)
    normalized1 = [x/m1 for x in t1Data]
    normalized2 = [x/m2 for x in t2Data]
    #plt.scatter(normalized1,normalized2)
    #plt.show()
    return scipy.stats.linregress(t1Data,t2Data)[2]


tradesmen, population, tradeWealth = Shared.getCatastoData()

threshold = 20
centralized = []
decentralized = []
cormap = []
validTrades = []
for trade1 in range(1,100):
    t1Data = [x[trade1] for n, x in tradesmen.items()]
    t1Sum = sum(t1Data)
    if(t1Sum > threshold):
        validTrades.append(trade1)
        tmp = []
        for trade2 in range(1,100):
            t2Data = [x[trade2] for n, x in tradesmen.items()]
            t2Sum = sum(t2Data)
Ejemplo n.º 48
0
 def _get_deleted_regions(self):
     ranges = self._read_range_data(Shared.get_dependency(os.path.join("albicans", "deleted_regions.csv")))
 
     return {chrom: RangeSet(r for r in range_set if r[1] - r[0] + 1 >= self._ignore_region_threshold) for chrom, range_set in ranges.iteritems()}
Ejemplo n.º 49
0
import Shared as sd
from datetime import datetime


countries_ = ["None", "US", "GB", "CA", "DE", "FR", "NL", "IT"]
regions_ = sd.get_dict("region")


def process(entry, result):
    # Event - time
    t = entry["t"] / 1000

    min = datetime.fromtimestamp(t).minute
    sd.binarize(result, min, 60)

    hour = datetime.fromtimestamp(t).hour
    sd.binarize(result, hour, 24)

    day = datetime.fromtimestamp(t).weekday()
    sd.binarize(result, day, 7)

    hour_of_week = day*24+hour
    sd.binarize(result, hour_of_week, 7*24)

    # Event - country
    sd.add_to_result(result, entry["cc"], countries_)

    # Event - region
    sd.add_to_result(result, entry["rg"], regions_)
Ejemplo n.º 50
0
 def _get_genes_with_paralogs(self):
     return Organism._get_genes_with_paralogs(self, Shared.get_dependency(os.path.join("pombe", "hasParalogs_sp.txt")))
Ejemplo n.º 51
0
def process(entry, result):
    # Event - time
    t = entry["t"] / 1000

    min = datetime.fromtimestamp(t).minute
    sd.binarize(result, min, 60)

    hour = datetime.fromtimestamp(t).hour
    sd.binarize(result, hour, 24)

    day = datetime.fromtimestamp(t).weekday()
    sd.binarize(result, day, 7)

    hour_of_week = day*24+hour
    sd.binarize(result, hour_of_week, 7*24)

    # Event - country
    sd.add_to_result(result, entry["cc"], countries_)

    # Event - region
    sd.add_to_result(result, entry["rg"], regions_)
Ejemplo n.º 52
0
 def _get_genes_with_paralogs(self):
     return Organism._get_genes_with_paralogs(self, Shared.get_dependency(os.path.join("albicans", "hasParalogs_ca.txt")))
Ejemplo n.º 53
0
 def _get_homologous_regions(self):
     ranges = self._read_range_data(Shared.get_dependency(os.path.join("cerevisiae", "homologous_regions.csv")))
 
     return {chrom: RangeSet(r for r in range_set if r[1] - r[0] + 1 >= self._ignore_region_threshold) for chrom, range_set in ranges.iteritems()}
Ejemplo n.º 54
0
 def parse_friend_state_changed(self, value):
     friend_username, state = value.split(',')
     friend = Shared.get_friend_by_username(friend_username)
     if friend:
         print 'Friend ' + friend_username + ' is now ' + state
         friend.change_state(state)
Ejemplo n.º 55
0
    ignored_features = [organism.feature_db.get_feature_by_name(n) for n in sorted(organism.ignored_features)]
    data = [
        [f.standard_name,
         f.common_name,
         f.type,
         (f.exons & organism.deleted_regions[f.chromosome]).coverage / float(len(f)),
         (f.exons & organism.homologous_regions[f.chromosome]).coverage / float(len(f))]
        for f in ignored_features
    ]
    
    for row in data:
        ignore_reasons = []
        
        if "ORF" not in row[3-1].upper():
            ignore_reasons.append("Not ORF")
#         if "dubious" in f.type.lower():
#             ignore_reasons.append("Dubious ORF")
        if row[-2] > 0.05:
            ignore_reasons.append("More than 5% deleted")
        if row[-1] > 0.05:
            ignore_reasons.append("More than 5% duplicated")
        
        row.append("; ".join(ignore_reasons))
    
    with pd.ExcelWriter(out_file) as excel_writer:
        result = pd.DataFrame(columns=columns, data=data)
        result.to_excel(excel_writer, sheet_name="Ignored genes", index=False)

if __name__ == "__main__":
    write_ignored_genes_table(alb, os.path.join(Shared.get_script_dir(), "output", "ignored_alb_genes.xlsx"))
Ejemplo n.º 56
0
   -r  --reverse-strand             Search with reverse complement sequence for R2 files.
                                     (Adaptor cleaning works the same as with R1.)
   -d  --delete-originals           Delete input FASTQ files.
   -k  --keep-clean-fqs             Keep the cleaned FASTQ files.
   -p  --primer-check               Check primer specificity if percent transposon in reads is low.
   -h  --help                       Show this help message and exit 
'''

TnPrimerAndTail = 'GTATTTTACCGACCGTTACCGACCGTTTTCATCCCTA'
TnRev = 'TAGGGATGAAAACGGTCGGTAACGGTCGGTAAAATAC'
PrimerOnly = 'GTATTTTACCGACCGTTACCGACC'
PrimerRev = 'GGTCGGTAACGGTCGGTAAAATAC'
AdapterSeq = 'AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC'

# NB: bowtie2 requires spaces to be escapes with a backslash for the -x parameter.
CInd = Shared.get_dependency("albicans", "reference genome", "C_albicans_SC5314_version_A22-s07-m01-r08_chromosomes_HapA").replace(' ', '\ ')
CORES = 4 # Cores on the machine = how many threads should the external tools utilize

def GetCmdPath(Program):
    """Gets the path to a desired program file on given computer.

    Parameters
    ----------
        Program :   string  
            Name of program wish to have path for.

    Returns
    -------
        CmdPath :   string
            Path for calling program as a command in the POSIX terminal.
    """
Ejemplo n.º 57
0
                px = pixels[x, y]
                for i, n in enumerate(Shared.getNeighbourhoods().keys()):
                    g = int(n / 10)
                    b = n % 10
                    if px[0] == 0 and px[1] == g and px[2] == b:
                        pixels[x, y] = (int(values[i] * 255), 0, 0, 255)
        fm.save("results/trademap_" + str(trade) + ".png")
    return fm

def getMCN(trade, tradesmen, population):
    fig, ax = plt.subplots()
    neighbourhood = [x[trade] for n, x in tradesmen.items()]
    totalTradesmen = sum(neighbourhood)
    if(totalTradesmen > 20):
        perCapita = [n / p for n, p in zip(neighbourhood, population)]
        plt.title(Shared.getTradeName(trade))
        bimodal = analyze(fig, ax, trade, perCapita)
        return bimodal
    return -1

tradesmen, population, tradeWealth = Shared.getCatastoData()
centralized = []
decentralized = []
for trade in range(0,100):
    bimodal = getMCN(trade, tradesmen, population)
    if bimodal:
        centralized.append(Shared.getTradeName(trade))
    else:
        decentralized.append(Shared.getTradeName(trade))
print(centralized)
print(decentralized)
Ejemplo n.º 58
0
def process(margin, entry, result, mode):
    """
    Given a JSON object formatted by Extractor.py, parse variables "bidderid", "verticalid", "bidfloor", "format", "product", "w", and "h",
    and the results to the list of possible results.
    :param entry: the JSON object that represents one impression
    :param result: the list of possible results
    :return: None
    """

    # Auction - Bidrequests - bidder id
    bidder_id = entry["bidderid"]
    if bidder_id == 36:  # Adjusting the index for DSP 36 since we ignore DSP 35 and 37
        bidder_id = 35
    sd.binarize(result, bidder_id-1, 35)

    # Auction - Bidrequests - vertical id
    sd.binarize(result, entry["verticalid"]-1, 16)

    # Auction - Bidrequests - Impressions - bid Floor
    bid_floor = round(float(entry["bidfloor"]), 2)

    if bid_floor-margin == 0:
        result.append(0)
    else:
        result.append(1)

    # If bid floor is to be parsed into binary format, create a boolean variable for every interval of size 0.5 from 0 to 28,
    # and according to the value of the bid floor, set the associated boolean variable to 1.
    # Otherwise, just record the value of bid floor.
    if mode == "bin":
        index = 0
        if bid_floor < 28:
            index = int(bid_floor*20)
        bid_floor_list = [0]*560
        bid_floor_list[index] = 1
        result.extend(bid_floor_list)
    else:
        result.append(bid_floor)

    # Determine if bid floor is a multiple of 0.05 or of 0.1
    for n in [20, 10]:
        bid_floor_tmp = n*bid_floor
        if bid_floor_tmp == int(bid_floor_tmp):
            result.append(1)
        else:
            result.append(0)

    # Determine if bid floor is greater than the values in thres_list
    index = 0
    thres_list = [1.5, 2, 2.5, 3, 28]
    for thres in thres_list:
        if bid_floor > thres:
            result.append(1)
            index += 1
        else:
            n = len(thres_list) - index
            result.extend([0]*n)
            break

    # Auction - Bidrequests - Impressions - format
    sd.binarize(result, formats_.index(entry["format"]), len(formats_))

    # Auction - Bidrequests - Impressions - product
    sd.binarize(result, entry["product"]-1, 6)

    # Auction - Bidrequests - Impressions - banner
    width = entry["w"]
    height = entry["h"]

    # Determine if banner belongs to any of the following types:
    #   1) h in (0, 200] and w in (0, 500]
    #   2) h in (0, 200] and w in (500, infinity)
    #   3) h in (200, infinity) and w in (0, 500]
    banner_cat = [0, 0, 0]
    if 0 < height <= 200:
        if 0 < width <= 500:
            banner_cat[0] = 1
        elif width > 500:
            banner_cat[1] = 1
    elif (height > 200) and (width <= 500):
        banner_cat[2] = 1

    sd.add_to_result(result, (width, height), banners_)
    result.extend(banner_cat)
Ejemplo n.º 59
0
 def enumerate_hashes(rootdir, file_filter):
   rootdir = os.path.abspath(rootdir)
   command = ['git', 'hash-object']
   for file in Shared.find_files(rootdir, file_filter):
     args = list(command) + [file]
     yield file, subprocess.check_output(args).strip()
Ejemplo n.º 60
0
class TestKeyring(Shared.TestCase):

    def setUp(self):
        self.keyring = Keyring('Gmail Notifier Test', 'Test')
        self.defkeyring = gnomekeyring.get_default_keyring_sync()
        self.auth_token = None

    def test_save_password(self):
        self.auth_token = self.keyring.save_password('*****@*****.**', 'testpass')
        self.assert_(self.auth_token > 0)

    def test_retrive_password(self):
        self.auth_token = self.keyring.save_password('*****@*****.**', 'testpass')
        password = self.keyring.get_password(self.auth_token)
        self.assertEqual(password, 'testpass')

    def test_delete_password(self):
        self.auth_token = self.keyring.save_password('*****@*****.**', 'testpass')
        self.keyring.remove_password(self.auth_token)
        password = self.keyring.get_password(self.auth_token)
        self.assertEqual(password, None)

    def tearDown(self):
        if self.auth_token:
            gnomekeyring.item_delete_sync(self.defkeyring, self.auth_token)


if __name__ == '__main__':
    Shared.main()