def validate_bam_fasta_pairs(bam_path, fasta_sequences, genome): """ Make sure that this BAM is actually aligned to this fasta. Every sequence should be the same length. Sequences can exist in the reference that do not exist in the BAM, but not the other way around. """ handle = pysam.Samfile(bam_path, 'rb') bam_sequences = {(n, s) for n, s in zip(*[handle.references, handle.lengths])} difference = bam_sequences - fasta_sequences if len(difference) > 0: base_err = 'Error: BAM {} has the following sequence/length pairs not found in the {} fasta: {}.' err = base_err.format(bam_path, genome, ','.join(['-'.join(map(str, x)) for x in difference])) raise UserException(err) missing_seqs = fasta_sequences - bam_sequences if len(missing_seqs) > 0: base_msg = 'BAM {} does not have the following sequence/length pairs in its header: {}.' msg = base_msg.format(bam_path, ','.join(['-'.join(map(str, x)) for x in missing_seqs])) logger.warning(msg)
def update_status(self, emoji_name, message=None): try: profile_payload = {} if emoji_name: profile_payload["status_emoji"] = emoji_name else: profile_payload["status_emoji"] = "" if message: profile_payload["status_text"] = message else: profile_payload["status_text"] = "" if profile_payload: print("Contacting Slack Web API") response = self._call_slack_api("users.profile.set", profile=profile_payload) print("\n\nResponse from API:") print(response) except Exception as e: raise UserException("Unable to update slack status.", str(e))
def __init__(self, token): try: self.slack_api = SlackClient(token) except: raise UserException("No API key provided", "")
async def select(self, args): output = "" parameters = { 'min_feas': None, 'max_feas': None, 'min_skill': None, 'max_skill': None, 'min_fun': None, 'max_fun': None, 'min_age': None, 'max_age': None, 'max_freq': None, 'min_freq': None, 'use_list': None, 'positions': [], 'pos_sanity': 'sane', } choices = 1 args_list = [] list_as = None team_mode = False still_listing = False entries = [] for arg in args: arg = arg.lower() print(arg) if arg.isspace(): continue if '-' in arg: arg = re.sub(r'^-+', '', arg) if '=' in arg or still_listing: if '=' not in arg: val = arg else: key = arg.split('=')[0] val = arg.split('=')[1] if key == 'sanity' or key == "s": if val == 'sane' or val == "s": parameters['pos_sanity'] = 'sane' elif val == 'insane' or val == "i": parameters['pos_sanity'] = 'insane' elif val == 'all' or val == "a": parameters['pos_sanity'] = 'all' else: raise UserException( "Invalid value for key 'sanity', valid options include [s]ane, [i]nsane, [a]ll" ) if key == 'position' or key == 'pos' or key == "p": parameters['positions'] = [ 'top', 'jungle', 'mid', 'bottom', 'support' ] remove = [] if val[0] == "-": for pos in parameters['positions']: if pos[0] in val: remove.append(pos) for pos in remove: parameters['positions'].remove(pos) else: for pos in parameters['positions']: if pos[0] not in val: remove.append(pos) for pos in remove: parameters['positions'].remove(pos) opts = "" for pos in parameters['positions']: opts = opts + f'{pos} ' if key == 'choices' or key == "n": choices = int(val) if choices <= 0 or choices > 155: raise UserException( "Invalid value for key 'choices', must be 0 < n <= 155" ) sys.exit(1) if key == 'minfeas' or key == 'mnfs': minfeas = int(val) if minfeas < 0: minfeas = 0 print( "Minimum feasibility below 0 -- Ignored. Defaulting to 0." ) if minfeas > 9: minfeas = 9 print( "Minimum feasibility above 9 -- Ignored. Defaulting to 9." ) parameters['min_feas'] = min_feas if key == 'maxfeas' or key == 'mxfs': maxfeas = int(val) if maxfeas < 0: maxfeas = 0 print( "Maximum feasibility below 0 -- Ignored. Defaulting to 0." ) if maxfeas > 9: maxfeas = 9 print( "Maximum feasibility above 9 -- Ignored. Defaulting to 9." ) parameters['min_feas'] = min_feas if key == 'feas' or key == "f": if val[0] == "-": if val[1:] == "std" or val[1:] == "meta": parameters['max_feas'] = 7 elif val[1:] == "nonmeta": parameters['max_feas'] = 5 elif val[1:] == "troll": parameters['min_feas'] = 5 elif val[1:] == "hell": parameters['min_feas'] = 3 elif val[1:] == "9": parameters['max_feas'] = 8 elif val[1:] == "0": parameters['min_feas'] = 1 else: raise UserException( "Invalid feasibility setting. Valid options are [std|meta|nonmeta|troll|hell|9|0]" ) else: if val == "std" or val == "meta": parameters['min_feas'] = 7 elif val == "nonmeta": parameters['min_feas'] = 5 parameters['max_feas'] = 7 elif val == "troll": parameters['min_feas'] = 3 parameters['max_feas'] = 5 elif val == "hell": parameters['max_feas'] = 3 elif val == "9": parameters['min_feas'] = 9 elif val == "0": parameters['max_feas'] = 0 else: raise UserException( "Invalid feasibility setting. Valid options are [std|meta|nonmeta|troll|hell|9|0]" ) sys.exit(1) print( f"Filtering feasibilty by range {parameters['min_feas']} <= f <= {parameters['max_feas']}" ) if key == 'from' or still_listing: still_listing = bool(']' not in val) print(still_listing) invert_list = False if val[0] == "-": invert_list = True val = val[1:] val = re.sub('^\[|\]$', '', val) try: json_data = None for v in val.split(','): if v.lstrip().rstrip().lower().isspace(): continue entries.append(v.lstrip().rstrip().lower()) print(still_listing) if not still_listing: if "" in entries: entries.remove("") json_data = '["' + ('","').join(entries) + '"]' print(json_data) entered_list = json.loads(json_data) except: raise SystemException("Failed to load from list.") if json_data is None: continue if invert_list: for champ in self.champs.keys(): args_list.append(champ) for item in entered_list: champ = await alias_to_champid(self.ctx, item) if champ not in self.champs.keys(): print(f"Could not find {champ} in data. Ignoring.") continue if invert_list: args_list.remove(champ) else: args_list.append(champ) if key == 'as' or key == "i": list_as = f'{val}' parameters['use_list'] = list_as else: if arg == '5q' or arg == "5": team_mode = True elif arg == 'top' or arg == "t": parameters['positions'].append('top') elif arg == 'mid' or arg == "m" or arg == "middle": parameters['positions'].append('mid') elif arg == 'jg' or arg == "j" or arg == "jungle": parameters['positions'].append('jungle') elif arg == 'bot' or arg == "b" or arg == "bottom" or arg == "adc": parameters['positions'].append('bottom') elif arg == 'sup' or arg == "s" or arg == "support" or arg == "supp": parameters['positions'].append('support') elif arg == 'sysex': if self.debug: raise SystemException("Forced SystemException") elif arg == 'stdex': if self.debug: raise Exception("Forced Exception") elif arg == 'usex': if self.debug: raise UserException("Forced UserException") if still_listing: raise UserException("No closing ']' found in list.") if len(args_list): if list_as is None: list_as = '~~tmp~~' parameters['use_list'] = list_as # TODO: Is this necessary? if list_as == 'champ_data' or list_as == 'game_data': raise SystemException( "Invalid list name-- would overwrite a necessary program file.\n" ) await create_list(self.ctx, list_as, args_list) try: if team_mode: exclude_champs = None for pos in ['top', 'jungle', 'mid', 'bottom', 'support']: parameters['positions'] = [pos] output = output + f"Selection for {pos[0].upper()}{pos[1:].lower()} ======\n" exclude_champs, fragment = await self.do_selection( parameters, choices, exclude_champs) output = output + "\n======================================================\n" else: _, output = await self.do_selection(parameters, choices) return output except UserException as err: return f"```diff\n- {err}\n```" except Exception as err: raise SystemException(err)