repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
sequencelengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
sequencelengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
allianceauth/allianceauth
allianceauth/timerboard/views.py
AddUpdateMixin.get_form_kwargs
def get_form_kwargs(self): """ Inject the request user into the kwargs passed to the form """ kwargs = super(AddUpdateMixin, self).get_form_kwargs() kwargs.update({'user': self.request.user}) return kwargs
python
def get_form_kwargs(self): """ Inject the request user into the kwargs passed to the form """ kwargs = super(AddUpdateMixin, self).get_form_kwargs() kwargs.update({'user': self.request.user}) return kwargs
[ "def", "get_form_kwargs", "(", "self", ")", ":", "kwargs", "=", "super", "(", "AddUpdateMixin", ",", "self", ")", ".", "get_form_kwargs", "(", ")", "kwargs", ".", "update", "(", "{", "'user'", ":", "self", ".", "request", ".", "user", "}", ")", "return", "kwargs" ]
Inject the request user into the kwargs passed to the form
[ "Inject", "the", "request", "user", "into", "the", "kwargs", "passed", "to", "the", "form" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/timerboard/views.py#L58-L64
allianceauth/allianceauth
allianceauth/services/abstract.py
ServicesCRUDMixin.get_object
def get_object(self, queryset=None): """ Returns the object the view is displaying. """ if queryset is None: queryset = self.get_queryset() try: return queryset.get(user__pk=self.request.user.pk) except ObjectDoesNotExist: raise Http404
python
def get_object(self, queryset=None): """ Returns the object the view is displaying. """ if queryset is None: queryset = self.get_queryset() try: return queryset.get(user__pk=self.request.user.pk) except ObjectDoesNotExist: raise Http404
[ "def", "get_object", "(", "self", ",", "queryset", "=", "None", ")", ":", "if", "queryset", "is", "None", ":", "queryset", "=", "self", ".", "get_queryset", "(", ")", "try", ":", "return", "queryset", ".", "get", "(", "user__pk", "=", "self", ".", "request", ".", "user", ".", "pk", ")", "except", "ObjectDoesNotExist", ":", "raise", "Http404" ]
Returns the object the view is displaying.
[ "Returns", "the", "object", "the", "view", "is", "displaying", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/abstract.py#L79-L89
allianceauth/allianceauth
allianceauth/groupmanagement/managers.py
GroupManager.can_manage_groups
def can_manage_groups(cls, user): """ For use with user_passes_test decorator. Check if the user can manage groups. Either has the auth.group_management permission or is a leader of at least one group and is also a Member. :param user: django.contrib.auth.models.User for the request :return: bool True if user can manage groups, False otherwise """ if user.is_authenticated: return cls.has_management_permission(user) or user.leads_groups.all() return False
python
def can_manage_groups(cls, user): """ For use with user_passes_test decorator. Check if the user can manage groups. Either has the auth.group_management permission or is a leader of at least one group and is also a Member. :param user: django.contrib.auth.models.User for the request :return: bool True if user can manage groups, False otherwise """ if user.is_authenticated: return cls.has_management_permission(user) or user.leads_groups.all() return False
[ "def", "can_manage_groups", "(", "cls", ",", "user", ")", ":", "if", "user", ".", "is_authenticated", ":", "return", "cls", ".", "has_management_permission", "(", "user", ")", "or", "user", ".", "leads_groups", ".", "all", "(", ")", "return", "False" ]
For use with user_passes_test decorator. Check if the user can manage groups. Either has the auth.group_management permission or is a leader of at least one group and is also a Member. :param user: django.contrib.auth.models.User for the request :return: bool True if user can manage groups, False otherwise
[ "For", "use", "with", "user_passes_test", "decorator", ".", "Check", "if", "the", "user", "can", "manage", "groups", ".", "Either", "has", "the", "auth", ".", "group_management", "permission", "or", "is", "a", "leader", "of", "at", "least", "one", "group", "and", "is", "also", "a", "Member", ".", ":", "param", "user", ":", "django", ".", "contrib", ".", "auth", ".", "models", ".", "User", "for", "the", "request", ":", "return", ":", "bool", "True", "if", "user", "can", "manage", "groups", "False", "otherwise" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/groupmanagement/managers.py#L31-L42
allianceauth/allianceauth
allianceauth/groupmanagement/managers.py
GroupManager.can_manage_group
def can_manage_group(cls, user, group): """ Check user has permission to manage the given group :param user: User object to test permission of :param group: Group object the user is attempting to manage :return: True if the user can manage the group """ if user.is_authenticated: return cls.has_management_permission(user) or user.leads_groups.filter(group=group).exists() return False
python
def can_manage_group(cls, user, group): """ Check user has permission to manage the given group :param user: User object to test permission of :param group: Group object the user is attempting to manage :return: True if the user can manage the group """ if user.is_authenticated: return cls.has_management_permission(user) or user.leads_groups.filter(group=group).exists() return False
[ "def", "can_manage_group", "(", "cls", ",", "user", ",", "group", ")", ":", "if", "user", ".", "is_authenticated", ":", "return", "cls", ".", "has_management_permission", "(", "user", ")", "or", "user", ".", "leads_groups", ".", "filter", "(", "group", "=", "group", ")", ".", "exists", "(", ")", "return", "False" ]
Check user has permission to manage the given group :param user: User object to test permission of :param group: Group object the user is attempting to manage :return: True if the user can manage the group
[ "Check", "user", "has", "permission", "to", "manage", "the", "given", "group", ":", "param", "user", ":", "User", "object", "to", "test", "permission", "of", ":", "param", "group", ":", "Group", "object", "the", "user", "is", "attempting", "to", "manage", ":", "return", ":", "True", "if", "the", "user", "can", "manage", "the", "group" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/groupmanagement/managers.py#L45-L54
allianceauth/allianceauth
allianceauth/groupmanagement/models.py
create_auth_group
def create_auth_group(sender, instance, created, **kwargs): """ Creates the AuthGroup model when a group is created """ if created: AuthGroup.objects.create(group=instance)
python
def create_auth_group(sender, instance, created, **kwargs): """ Creates the AuthGroup model when a group is created """ if created: AuthGroup.objects.create(group=instance)
[ "def", "create_auth_group", "(", "sender", ",", "instance", ",", "created", ",", "*", "*", "kwargs", ")", ":", "if", "created", ":", "AuthGroup", ".", "objects", ".", "create", "(", "group", "=", "instance", ")" ]
Creates the AuthGroup model when a group is created
[ "Creates", "the", "AuthGroup", "model", "when", "a", "group", "is", "created" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/groupmanagement/models.py#L81-L86
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Proto.construct_command
def construct_command(self, command, keys=None, opts=None): """ Constructs a TS3 formatted command string Keys can have a single nested list to construct a nested parameter @param command: Command list @type command: string @param keys: Key/Value pairs @type keys: dict @param opts: Options @type opts: list """ cstr = [command] # Add the keys and values, escape as needed if keys: for key in keys: if isinstance(keys[key], list): ncstr = [] for nest in keys[key]: ncstr.append("%s=%s" % (key, self._escape_str(nest))) cstr.append("|".join(ncstr)) else: cstr.append("%s=%s" % (key, self._escape_str(keys[key]))) # Add in options if opts: for opt in opts: cstr.append("-%s" % opt) return " ".join(cstr)
python
def construct_command(self, command, keys=None, opts=None): """ Constructs a TS3 formatted command string Keys can have a single nested list to construct a nested parameter @param command: Command list @type command: string @param keys: Key/Value pairs @type keys: dict @param opts: Options @type opts: list """ cstr = [command] # Add the keys and values, escape as needed if keys: for key in keys: if isinstance(keys[key], list): ncstr = [] for nest in keys[key]: ncstr.append("%s=%s" % (key, self._escape_str(nest))) cstr.append("|".join(ncstr)) else: cstr.append("%s=%s" % (key, self._escape_str(keys[key]))) # Add in options if opts: for opt in opts: cstr.append("-%s" % opt) return " ".join(cstr)
[ "def", "construct_command", "(", "self", ",", "command", ",", "keys", "=", "None", ",", "opts", "=", "None", ")", ":", "cstr", "=", "[", "command", "]", "# Add the keys and values, escape as needed", "if", "keys", ":", "for", "key", "in", "keys", ":", "if", "isinstance", "(", "keys", "[", "key", "]", ",", "list", ")", ":", "ncstr", "=", "[", "]", "for", "nest", "in", "keys", "[", "key", "]", ":", "ncstr", ".", "append", "(", "\"%s=%s\"", "%", "(", "key", ",", "self", ".", "_escape_str", "(", "nest", ")", ")", ")", "cstr", ".", "append", "(", "\"|\"", ".", "join", "(", "ncstr", ")", ")", "else", ":", "cstr", ".", "append", "(", "\"%s=%s\"", "%", "(", "key", ",", "self", ".", "_escape_str", "(", "keys", "[", "key", "]", ")", ")", ")", "# Add in options", "if", "opts", ":", "for", "opt", "in", "opts", ":", "cstr", ".", "append", "(", "\"-%s\"", "%", "opt", ")", "return", "\" \"", ".", "join", "(", "cstr", ")" ]
Constructs a TS3 formatted command string Keys can have a single nested list to construct a nested parameter @param command: Command list @type command: string @param keys: Key/Value pairs @type keys: dict @param opts: Options @type opts: list
[ "Constructs", "a", "TS3", "formatted", "command", "string", "Keys", "can", "have", "a", "single", "nested", "list", "to", "construct", "a", "nested", "parameter" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L103-L133
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Proto.parse_command
def parse_command(self, commandstr): """ Parses a TS3 command string into command/keys/opts tuple @param commandstr: Command string @type commandstr: string """ if len(commandstr.split('|')) > 1: vals = [] for cmd in commandstr.split('|'): vals.append(self.parse_command(cmd)) return vals cmdlist = commandstr.strip().split(' ') command = None keys = {} opts = [] for key in cmdlist: v = key.strip().split('=') if len(v) > 1: # Key if len(v) > 2: # Fix the stupidities in TS3 escaping v = [v[0], '='.join(v[1:])] key, value = v keys[key] = self._unescape_str(value) elif not v == ['']: if v[0][0] and v[0][0] == '-': # Option opts.append(v[0][1:]) else: command = v[0] d = {'keys': keys, 'opts': opts} if command: d['command'] = command return d
python
def parse_command(self, commandstr): """ Parses a TS3 command string into command/keys/opts tuple @param commandstr: Command string @type commandstr: string """ if len(commandstr.split('|')) > 1: vals = [] for cmd in commandstr.split('|'): vals.append(self.parse_command(cmd)) return vals cmdlist = commandstr.strip().split(' ') command = None keys = {} opts = [] for key in cmdlist: v = key.strip().split('=') if len(v) > 1: # Key if len(v) > 2: # Fix the stupidities in TS3 escaping v = [v[0], '='.join(v[1:])] key, value = v keys[key] = self._unescape_str(value) elif not v == ['']: if v[0][0] and v[0][0] == '-': # Option opts.append(v[0][1:]) else: command = v[0] d = {'keys': keys, 'opts': opts} if command: d['command'] = command return d
[ "def", "parse_command", "(", "self", ",", "commandstr", ")", ":", "if", "len", "(", "commandstr", ".", "split", "(", "'|'", ")", ")", ">", "1", ":", "vals", "=", "[", "]", "for", "cmd", "in", "commandstr", ".", "split", "(", "'|'", ")", ":", "vals", ".", "append", "(", "self", ".", "parse_command", "(", "cmd", ")", ")", "return", "vals", "cmdlist", "=", "commandstr", ".", "strip", "(", ")", ".", "split", "(", "' '", ")", "command", "=", "None", "keys", "=", "{", "}", "opts", "=", "[", "]", "for", "key", "in", "cmdlist", ":", "v", "=", "key", ".", "strip", "(", ")", ".", "split", "(", "'='", ")", "if", "len", "(", "v", ")", ">", "1", ":", "# Key", "if", "len", "(", "v", ")", ">", "2", ":", "# Fix the stupidities in TS3 escaping", "v", "=", "[", "v", "[", "0", "]", ",", "'='", ".", "join", "(", "v", "[", "1", ":", "]", ")", "]", "key", ",", "value", "=", "v", "keys", "[", "key", "]", "=", "self", ".", "_unescape_str", "(", "value", ")", "elif", "not", "v", "==", "[", "''", "]", ":", "if", "v", "[", "0", "]", "[", "0", "]", "and", "v", "[", "0", "]", "[", "0", "]", "==", "'-'", ":", "# Option", "opts", ".", "append", "(", "v", "[", "0", "]", "[", "1", ":", "]", ")", "else", ":", "command", "=", "v", "[", "0", "]", "d", "=", "{", "'keys'", ":", "keys", ",", "'opts'", ":", "opts", "}", "if", "command", ":", "d", "[", "'command'", "]", "=", "command", "return", "d" ]
Parses a TS3 command string into command/keys/opts tuple @param commandstr: Command string @type commandstr: string
[ "Parses", "a", "TS3", "command", "string", "into", "command", "/", "keys", "/", "opts", "tuple" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L135-L172
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Proto._escape_str
def _escape_str(value): """ Escape a value into a TS3 compatible string @param value: Value @type value: string/int """ if isinstance(value, int): return "%d" % value value = value.replace("\\", r'\\') for i, j in ts3_escape.items(): value = value.replace(i, j) return value
python
def _escape_str(value): """ Escape a value into a TS3 compatible string @param value: Value @type value: string/int """ if isinstance(value, int): return "%d" % value value = value.replace("\\", r'\\') for i, j in ts3_escape.items(): value = value.replace(i, j) return value
[ "def", "_escape_str", "(", "value", ")", ":", "if", "isinstance", "(", "value", ",", "int", ")", ":", "return", "\"%d\"", "%", "value", "value", "=", "value", ".", "replace", "(", "\"\\\\\"", ",", "r'\\\\'", ")", "for", "i", ",", "j", "in", "ts3_escape", ".", "items", "(", ")", ":", "value", "=", "value", ".", "replace", "(", "i", ",", "j", ")", "return", "value" ]
Escape a value into a TS3 compatible string @param value: Value @type value: string/int
[ "Escape", "a", "value", "into", "a", "TS3", "compatible", "string" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L175-L187
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Proto._unescape_str
def _unescape_str(value): """ Unescape a TS3 compatible string into a normal string @param value: Value @type value: string/int """ if isinstance(value, int): return "%d" % value value = value.replace(r"\\", "\\") for i, j in ts3_escape.items(): value = value.replace(j, i) return value
python
def _unescape_str(value): """ Unescape a TS3 compatible string into a normal string @param value: Value @type value: string/int """ if isinstance(value, int): return "%d" % value value = value.replace(r"\\", "\\") for i, j in ts3_escape.items(): value = value.replace(j, i) return value
[ "def", "_unescape_str", "(", "value", ")", ":", "if", "isinstance", "(", "value", ",", "int", ")", ":", "return", "\"%d\"", "%", "value", "value", "=", "value", ".", "replace", "(", "r\"\\\\\"", ",", "\"\\\\\"", ")", "for", "i", ",", "j", "in", "ts3_escape", ".", "items", "(", ")", ":", "value", "=", "value", ".", "replace", "(", "j", ",", "i", ")", "return", "value" ]
Unescape a TS3 compatible string into a normal string @param value: Value @type value: string/int
[ "Unescape", "a", "TS3", "compatible", "string", "into", "a", "normal", "string" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L190-L202
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Server.login
def login(self, username, password): """ Login to the TS3 Server @param username: Username @type username: str @param password: Password @type password: str """ d = self.send_command('login', keys={'client_login_name': username, 'client_login_password': password}) if d == 0: self._log.info('Login Successful') return True return False
python
def login(self, username, password): """ Login to the TS3 Server @param username: Username @type username: str @param password: Password @type password: str """ d = self.send_command('login', keys={'client_login_name': username, 'client_login_password': password}) if d == 0: self._log.info('Login Successful') return True return False
[ "def", "login", "(", "self", ",", "username", ",", "password", ")", ":", "d", "=", "self", ".", "send_command", "(", "'login'", ",", "keys", "=", "{", "'client_login_name'", ":", "username", ",", "'client_login_password'", ":", "password", "}", ")", "if", "d", "==", "0", ":", "self", ".", "_log", ".", "info", "(", "'Login Successful'", ")", "return", "True", "return", "False" ]
Login to the TS3 Server @param username: Username @type username: str @param password: Password @type password: str
[ "Login", "to", "the", "TS3", "Server" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L223-L235
allianceauth/allianceauth
allianceauth/services/modules/teamspeak3/util/ts3.py
TS3Server.use
def use(self, id): """ Use a particular Virtual Server instance @param id: Virtual Server ID @type id: int """ if self._connected and id > 0: self.send_command('use', keys={'sid': id})
python
def use(self, id): """ Use a particular Virtual Server instance @param id: Virtual Server ID @type id: int """ if self._connected and id > 0: self.send_command('use', keys={'sid': id})
[ "def", "use", "(", "self", ",", "id", ")", ":", "if", "self", ".", "_connected", "and", "id", ">", "0", ":", "self", ".", "send_command", "(", "'use'", ",", "keys", "=", "{", "'sid'", ":", "id", "}", ")" ]
Use a particular Virtual Server instance @param id: Virtual Server ID @type id: int
[ "Use", "a", "particular", "Virtual", "Server", "instance" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/teamspeak3/util/ts3.py#L253-L260
allianceauth/allianceauth
allianceauth/services/modules/example/auth_hooks.py
ExampleService.render_services_ctrl
def render_services_ctrl(self, request): """ Example for rendering the service control panel row You can override the default template and create a custom one if you wish. :param request: :return: """ urls = self.Urls() urls.auth_activate = 'auth_example_activate' urls.auth_deactivate = 'auth_example_deactivate' urls.auth_reset_password = 'auth_example_reset_password' urls.auth_set_password = 'auth_example_set_password' return render_to_string(self.service_ctrl_template, { 'service_name': self.title, 'urls': urls, 'service_url': self.service_url, 'username': 'example username' }, request=request)
python
def render_services_ctrl(self, request): """ Example for rendering the service control panel row You can override the default template and create a custom one if you wish. :param request: :return: """ urls = self.Urls() urls.auth_activate = 'auth_example_activate' urls.auth_deactivate = 'auth_example_deactivate' urls.auth_reset_password = 'auth_example_reset_password' urls.auth_set_password = 'auth_example_set_password' return render_to_string(self.service_ctrl_template, { 'service_name': self.title, 'urls': urls, 'service_url': self.service_url, 'username': 'example username' }, request=request)
[ "def", "render_services_ctrl", "(", "self", ",", "request", ")", ":", "urls", "=", "self", ".", "Urls", "(", ")", "urls", ".", "auth_activate", "=", "'auth_example_activate'", "urls", ".", "auth_deactivate", "=", "'auth_example_deactivate'", "urls", ".", "auth_reset_password", "=", "'auth_example_reset_password'", "urls", ".", "auth_set_password", "=", "'auth_example_set_password'", "return", "render_to_string", "(", "self", ".", "service_ctrl_template", ",", "{", "'service_name'", ":", "self", ".", "title", ",", "'urls'", ":", "urls", ",", "'service_url'", ":", "self", ".", "service_url", ",", "'username'", ":", "'example username'", "}", ",", "request", "=", "request", ")" ]
Example for rendering the service control panel row You can override the default template and create a custom one if you wish. :param request: :return:
[ "Example", "for", "rendering", "the", "service", "control", "panel", "row", "You", "can", "override", "the", "default", "template", "and", "create", "a", "custom", "one", "if", "you", "wish", ".", ":", "param", "request", ":", ":", "return", ":" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/example/auth_hooks.py#L19-L37
allianceauth/allianceauth
allianceauth/eveonline/models.py
EveCharacter.alliance
def alliance(self) -> Union[EveAllianceInfo, None]: """ Pseudo foreign key from alliance_id to EveAllianceInfo :raises: EveAllianceInfo.DoesNotExist :return: EveAllianceInfo or None """ if self.alliance_id is None: return None return EveAllianceInfo.objects.get(alliance_id=self.alliance_id)
python
def alliance(self) -> Union[EveAllianceInfo, None]: """ Pseudo foreign key from alliance_id to EveAllianceInfo :raises: EveAllianceInfo.DoesNotExist :return: EveAllianceInfo or None """ if self.alliance_id is None: return None return EveAllianceInfo.objects.get(alliance_id=self.alliance_id)
[ "def", "alliance", "(", "self", ")", "->", "Union", "[", "EveAllianceInfo", ",", "None", "]", ":", "if", "self", ".", "alliance_id", "is", "None", ":", "return", "None", "return", "EveAllianceInfo", ".", "objects", ".", "get", "(", "alliance_id", "=", "self", ".", "alliance_id", ")" ]
Pseudo foreign key from alliance_id to EveAllianceInfo :raises: EveAllianceInfo.DoesNotExist :return: EveAllianceInfo or None
[ "Pseudo", "foreign", "key", "from", "alliance_id", "to", "EveAllianceInfo", ":", "raises", ":", "EveAllianceInfo", ".", "DoesNotExist", ":", "return", ":", "EveAllianceInfo", "or", "None" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/models.py#L96-L104
allianceauth/allianceauth
allianceauth/eveonline/autogroups/signals.py
pre_save_config
def pre_save_config(sender, instance, *args, **kwargs): """ Checks if enable was toggled on group config and deletes groups if necessary. """ logger.debug("Received pre_save from {}".format(instance)) if not instance.pk: # new model being created return try: old_instance = AutogroupsConfig.objects.get(pk=instance.pk) # Check if enable was toggled, delete groups? if old_instance.alliance_groups is True and instance.alliance_groups is False: instance.delete_alliance_managed_groups() if old_instance.corp_groups is True and instance.corp_groups is False: instance.delete_corp_managed_groups() except AutogroupsConfig.DoesNotExist: pass
python
def pre_save_config(sender, instance, *args, **kwargs): """ Checks if enable was toggled on group config and deletes groups if necessary. """ logger.debug("Received pre_save from {}".format(instance)) if not instance.pk: # new model being created return try: old_instance = AutogroupsConfig.objects.get(pk=instance.pk) # Check if enable was toggled, delete groups? if old_instance.alliance_groups is True and instance.alliance_groups is False: instance.delete_alliance_managed_groups() if old_instance.corp_groups is True and instance.corp_groups is False: instance.delete_corp_managed_groups() except AutogroupsConfig.DoesNotExist: pass
[ "def", "pre_save_config", "(", "sender", ",", "instance", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "logger", ".", "debug", "(", "\"Received pre_save from {}\"", ".", "format", "(", "instance", ")", ")", "if", "not", "instance", ".", "pk", ":", "# new model being created", "return", "try", ":", "old_instance", "=", "AutogroupsConfig", ".", "objects", ".", "get", "(", "pk", "=", "instance", ".", "pk", ")", "# Check if enable was toggled, delete groups?", "if", "old_instance", ".", "alliance_groups", "is", "True", "and", "instance", ".", "alliance_groups", "is", "False", ":", "instance", ".", "delete_alliance_managed_groups", "(", ")", "if", "old_instance", ".", "corp_groups", "is", "True", "and", "instance", ".", "corp_groups", "is", "False", ":", "instance", ".", "delete_corp_managed_groups", "(", ")", "except", "AutogroupsConfig", ".", "DoesNotExist", ":", "pass" ]
Checks if enable was toggled on group config and deletes groups if necessary.
[ "Checks", "if", "enable", "was", "toggled", "on", "group", "config", "and", "deletes", "groups", "if", "necessary", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/signals.py#L13-L32
allianceauth/allianceauth
allianceauth/eveonline/autogroups/signals.py
check_groups_on_profile_update
def check_groups_on_profile_update(sender, instance, created, *args, **kwargs): """ Trigger check when main character or state changes. """ AutogroupsConfig.objects.update_groups_for_user(instance.user)
python
def check_groups_on_profile_update(sender, instance, created, *args, **kwargs): """ Trigger check when main character or state changes. """ AutogroupsConfig.objects.update_groups_for_user(instance.user)
[ "def", "check_groups_on_profile_update", "(", "sender", ",", "instance", ",", "created", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "AutogroupsConfig", ".", "objects", ".", "update_groups_for_user", "(", "instance", ".", "user", ")" ]
Trigger check when main character or state changes.
[ "Trigger", "check", "when", "main", "character", "or", "state", "changes", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/signals.py#L45-L49
allianceauth/allianceauth
allianceauth/eveonline/autogroups/signals.py
autogroups_states_changed
def autogroups_states_changed(sender, instance, action, reverse, model, pk_set, *args, **kwargs): """ Trigger group membership update when a state is added or removed from an autogroup config. """ if action.startswith('post_'): for pk in pk_set: try: state = State.objects.get(pk=pk) instance.update_group_membership_for_state(state) except State.DoesNotExist: # Deleted States handled by the profile state change pass
python
def autogroups_states_changed(sender, instance, action, reverse, model, pk_set, *args, **kwargs): """ Trigger group membership update when a state is added or removed from an autogroup config. """ if action.startswith('post_'): for pk in pk_set: try: state = State.objects.get(pk=pk) instance.update_group_membership_for_state(state) except State.DoesNotExist: # Deleted States handled by the profile state change pass
[ "def", "autogroups_states_changed", "(", "sender", ",", "instance", ",", "action", ",", "reverse", ",", "model", ",", "pk_set", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "action", ".", "startswith", "(", "'post_'", ")", ":", "for", "pk", "in", "pk_set", ":", "try", ":", "state", "=", "State", ".", "objects", ".", "get", "(", "pk", "=", "pk", ")", "instance", ".", "update_group_membership_for_state", "(", "state", ")", "except", "State", ".", "DoesNotExist", ":", "# Deleted States handled by the profile state change", "pass" ]
Trigger group membership update when a state is added or removed from an autogroup config.
[ "Trigger", "group", "membership", "update", "when", "a", "state", "is", "added", "or", "removed", "from", "an", "autogroup", "config", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/signals.py#L53-L65
allianceauth/allianceauth
allianceauth/authentication/admin.py
make_service_hooks_update_groups_action
def make_service_hooks_update_groups_action(service): """ Make a admin action for the given service :param service: services.hooks.ServicesHook :return: fn to update services groups for the selected users """ def update_service_groups(modeladmin, request, queryset): for user in queryset: # queryset filtering doesn't work here? service.update_groups(user) update_service_groups.__name__ = str('update_{}_groups'.format(slugify(service.name))) update_service_groups.short_description = "Sync groups for selected {} accounts".format(service.title) return update_service_groups
python
def make_service_hooks_update_groups_action(service): """ Make a admin action for the given service :param service: services.hooks.ServicesHook :return: fn to update services groups for the selected users """ def update_service_groups(modeladmin, request, queryset): for user in queryset: # queryset filtering doesn't work here? service.update_groups(user) update_service_groups.__name__ = str('update_{}_groups'.format(slugify(service.name))) update_service_groups.short_description = "Sync groups for selected {} accounts".format(service.title) return update_service_groups
[ "def", "make_service_hooks_update_groups_action", "(", "service", ")", ":", "def", "update_service_groups", "(", "modeladmin", ",", "request", ",", "queryset", ")", ":", "for", "user", "in", "queryset", ":", "# queryset filtering doesn't work here?", "service", ".", "update_groups", "(", "user", ")", "update_service_groups", ".", "__name__", "=", "str", "(", "'update_{}_groups'", ".", "format", "(", "slugify", "(", "service", ".", "name", ")", ")", ")", "update_service_groups", ".", "short_description", "=", "\"Sync groups for selected {} accounts\"", ".", "format", "(", "service", ".", "title", ")", "return", "update_service_groups" ]
Make a admin action for the given service :param service: services.hooks.ServicesHook :return: fn to update services groups for the selected users
[ "Make", "a", "admin", "action", "for", "the", "given", "service", ":", "param", "service", ":", "services", ".", "hooks", ".", "ServicesHook", ":", "return", ":", "fn", "to", "update", "services", "groups", "for", "the", "selected", "users" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/authentication/admin.py#L15-L27
allianceauth/allianceauth
allianceauth/authentication/admin.py
make_service_hooks_sync_nickname_action
def make_service_hooks_sync_nickname_action(service): """ Make a sync_nickname admin action for the given service :param service: services.hooks.ServicesHook :return: fn to sync nickname for the selected users """ def sync_nickname(modeladmin, request, queryset): for user in queryset: # queryset filtering doesn't work here? service.sync_nickname(user) sync_nickname.__name__ = str('sync_{}_nickname'.format(slugify(service.name))) sync_nickname.short_description = "Sync nicknames for selected {} accounts".format(service.title) return sync_nickname
python
def make_service_hooks_sync_nickname_action(service): """ Make a sync_nickname admin action for the given service :param service: services.hooks.ServicesHook :return: fn to sync nickname for the selected users """ def sync_nickname(modeladmin, request, queryset): for user in queryset: # queryset filtering doesn't work here? service.sync_nickname(user) sync_nickname.__name__ = str('sync_{}_nickname'.format(slugify(service.name))) sync_nickname.short_description = "Sync nicknames for selected {} accounts".format(service.title) return sync_nickname
[ "def", "make_service_hooks_sync_nickname_action", "(", "service", ")", ":", "def", "sync_nickname", "(", "modeladmin", ",", "request", ",", "queryset", ")", ":", "for", "user", "in", "queryset", ":", "# queryset filtering doesn't work here?", "service", ".", "sync_nickname", "(", "user", ")", "sync_nickname", ".", "__name__", "=", "str", "(", "'sync_{}_nickname'", ".", "format", "(", "slugify", "(", "service", ".", "name", ")", ")", ")", "sync_nickname", ".", "short_description", "=", "\"Sync nicknames for selected {} accounts\"", ".", "format", "(", "service", ".", "title", ")", "return", "sync_nickname" ]
Make a sync_nickname admin action for the given service :param service: services.hooks.ServicesHook :return: fn to sync nickname for the selected users
[ "Make", "a", "sync_nickname", "admin", "action", "for", "the", "given", "service", ":", "param", "service", ":", "services", ".", "hooks", ".", "ServicesHook", ":", "return", ":", "fn", "to", "sync", "nickname", "for", "the", "selected", "users" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/authentication/admin.py#L30-L42
allianceauth/allianceauth
allianceauth/thirdparty/navhelper/templatetags/navactive.py
renavactive
def renavactive(request, pattern): """ {% renavactive request "^/a_regex" %} """ if re.search(pattern, request.path): return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active") return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
python
def renavactive(request, pattern): """ {% renavactive request "^/a_regex" %} """ if re.search(pattern, request.path): return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active") return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
[ "def", "renavactive", "(", "request", ",", "pattern", ")", ":", "if", "re", ".", "search", "(", "pattern", ",", "request", ".", "path", ")", ":", "return", "getattr", "(", "settings", ",", "\"NAVHELPER_ACTIVE_CLASS\"", ",", "\"active\"", ")", "return", "getattr", "(", "settings", ",", "\"NAVHELPER_NOT_ACTIVE_CLASS\"", ",", "\"\"", ")" ]
{% renavactive request "^/a_regex" %}
[ "{", "%", "renavactive", "request", "^", "/", "a_regex", "%", "}" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/thirdparty/navhelper/templatetags/navactive.py#L33-L39
allianceauth/allianceauth
allianceauth/thirdparty/navhelper/templatetags/navactive.py
navactive
def navactive(request, urls): """ {% navactive request "view_name another_view_name" %} """ url_list = set(urls.split()) resolved = resolve(request.path) resolved_urls = set() if resolved.url_name: resolved_urls.add(resolved.url_name) if resolved.namespaces: resolved_urls = resolved_urls.union(["{}:{}".format(namespace, resolved.url_name) for namespace in resolved.namespaces]) resolved_urls = resolved_urls.union(["{}:".format(namespace) for namespace in resolved.namespaces]) if getattr(resolved, 'app_name', None): resolved_urls = resolved_urls.union(["{}:{}".format(resolved.app_name, resolved.url_name), "{}:".format(resolved.app_name)]) if getattr(resolved, 'app_names', []): resolved_urls = resolved_urls.union(["{}:{}".format(app_name, resolved.url_name) for app_name in resolved.app_names]) resolved_urls = resolved_urls.union(["{}:".format(app_name) for app_name in resolved.app_names]) if url_list and resolved_urls and bool(resolved_urls & url_list): return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active") return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
python
def navactive(request, urls): """ {% navactive request "view_name another_view_name" %} """ url_list = set(urls.split()) resolved = resolve(request.path) resolved_urls = set() if resolved.url_name: resolved_urls.add(resolved.url_name) if resolved.namespaces: resolved_urls = resolved_urls.union(["{}:{}".format(namespace, resolved.url_name) for namespace in resolved.namespaces]) resolved_urls = resolved_urls.union(["{}:".format(namespace) for namespace in resolved.namespaces]) if getattr(resolved, 'app_name', None): resolved_urls = resolved_urls.union(["{}:{}".format(resolved.app_name, resolved.url_name), "{}:".format(resolved.app_name)]) if getattr(resolved, 'app_names', []): resolved_urls = resolved_urls.union(["{}:{}".format(app_name, resolved.url_name) for app_name in resolved.app_names]) resolved_urls = resolved_urls.union(["{}:".format(app_name) for app_name in resolved.app_names]) if url_list and resolved_urls and bool(resolved_urls & url_list): return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active") return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
[ "def", "navactive", "(", "request", ",", "urls", ")", ":", "url_list", "=", "set", "(", "urls", ".", "split", "(", ")", ")", "resolved", "=", "resolve", "(", "request", ".", "path", ")", "resolved_urls", "=", "set", "(", ")", "if", "resolved", ".", "url_name", ":", "resolved_urls", ".", "add", "(", "resolved", ".", "url_name", ")", "if", "resolved", ".", "namespaces", ":", "resolved_urls", "=", "resolved_urls", ".", "union", "(", "[", "\"{}:{}\"", ".", "format", "(", "namespace", ",", "resolved", ".", "url_name", ")", "for", "namespace", "in", "resolved", ".", "namespaces", "]", ")", "resolved_urls", "=", "resolved_urls", ".", "union", "(", "[", "\"{}:\"", ".", "format", "(", "namespace", ")", "for", "namespace", "in", "resolved", ".", "namespaces", "]", ")", "if", "getattr", "(", "resolved", ",", "'app_name'", ",", "None", ")", ":", "resolved_urls", "=", "resolved_urls", ".", "union", "(", "[", "\"{}:{}\"", ".", "format", "(", "resolved", ".", "app_name", ",", "resolved", ".", "url_name", ")", ",", "\"{}:\"", ".", "format", "(", "resolved", ".", "app_name", ")", "]", ")", "if", "getattr", "(", "resolved", ",", "'app_names'", ",", "[", "]", ")", ":", "resolved_urls", "=", "resolved_urls", ".", "union", "(", "[", "\"{}:{}\"", ".", "format", "(", "app_name", ",", "resolved", ".", "url_name", ")", "for", "app_name", "in", "resolved", ".", "app_names", "]", ")", "resolved_urls", "=", "resolved_urls", ".", "union", "(", "[", "\"{}:\"", ".", "format", "(", "app_name", ")", "for", "app_name", "in", "resolved", ".", "app_names", "]", ")", "if", "url_list", "and", "resolved_urls", "and", "bool", "(", "resolved_urls", "&", "url_list", ")", ":", "return", "getattr", "(", "settings", ",", "\"NAVHELPER_ACTIVE_CLASS\"", ",", "\"active\"", ")", "return", "getattr", "(", "settings", ",", "\"NAVHELPER_NOT_ACTIVE_CLASS\"", ",", "\"\"", ")" ]
{% navactive request "view_name another_view_name" %}
[ "{", "%", "navactive", "request", "view_name", "another_view_name", "%", "}" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/thirdparty/navhelper/templatetags/navactive.py#L43-L63
allianceauth/allianceauth
allianceauth/eveonline/autogroups/models.py
AutogroupsConfigManager.update_groups_for_state
def update_groups_for_state(self, state: State): """ Update all the Group memberships for the users who have State :param state: State to update for :return: """ users = get_users_for_state(state) for config in self.filter(states=state): logger.debug("in state loop") for user in users: logger.debug("in user loop for {}".format(user)) config.update_group_membership_for_user(user)
python
def update_groups_for_state(self, state: State): """ Update all the Group memberships for the users who have State :param state: State to update for :return: """ users = get_users_for_state(state) for config in self.filter(states=state): logger.debug("in state loop") for user in users: logger.debug("in user loop for {}".format(user)) config.update_group_membership_for_user(user)
[ "def", "update_groups_for_state", "(", "self", ",", "state", ":", "State", ")", ":", "users", "=", "get_users_for_state", "(", "state", ")", "for", "config", "in", "self", ".", "filter", "(", "states", "=", "state", ")", ":", "logger", ".", "debug", "(", "\"in state loop\"", ")", "for", "user", "in", "users", ":", "logger", ".", "debug", "(", "\"in user loop for {}\"", ".", "format", "(", "user", ")", ")", "config", ".", "update_group_membership_for_user", "(", "user", ")" ]
Update all the Group memberships for the users who have State :param state: State to update for :return:
[ "Update", "all", "the", "Group", "memberships", "for", "the", "users", "who", "have", "State", ":", "param", "state", ":", "State", "to", "update", "for", ":", "return", ":" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/models.py#L18-L30
allianceauth/allianceauth
allianceauth/eveonline/autogroups/models.py
AutogroupsConfigManager.update_groups_for_user
def update_groups_for_user(self, user: User, state: State = None): """ Update the Group memberships for the given users state :param user: User to update for :param state: State to update user for :return: """ if state is None: state = user.profile.state for config in self.filter(states=state): # grant user new groups for their state config.update_group_membership_for_user(user) for config in self.exclude(states=state): # ensure user does not have groups from previous state config.remove_user_from_alliance_groups(user) config.remove_user_from_corp_groups(user)
python
def update_groups_for_user(self, user: User, state: State = None): """ Update the Group memberships for the given users state :param user: User to update for :param state: State to update user for :return: """ if state is None: state = user.profile.state for config in self.filter(states=state): # grant user new groups for their state config.update_group_membership_for_user(user) for config in self.exclude(states=state): # ensure user does not have groups from previous state config.remove_user_from_alliance_groups(user) config.remove_user_from_corp_groups(user)
[ "def", "update_groups_for_user", "(", "self", ",", "user", ":", "User", ",", "state", ":", "State", "=", "None", ")", ":", "if", "state", "is", "None", ":", "state", "=", "user", ".", "profile", ".", "state", "for", "config", "in", "self", ".", "filter", "(", "states", "=", "state", ")", ":", "# grant user new groups for their state", "config", ".", "update_group_membership_for_user", "(", "user", ")", "for", "config", "in", "self", ".", "exclude", "(", "states", "=", "state", ")", ":", "# ensure user does not have groups from previous state", "config", ".", "remove_user_from_alliance_groups", "(", "user", ")", "config", ".", "remove_user_from_corp_groups", "(", "user", ")" ]
Update the Group memberships for the given users state :param user: User to update for :param state: State to update user for :return:
[ "Update", "the", "Group", "memberships", "for", "the", "given", "users", "state", ":", "param", "user", ":", "User", "to", "update", "for", ":", "param", "state", ":", "State", "to", "update", "user", "for", ":", "return", ":" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/models.py#L32-L47
allianceauth/allianceauth
allianceauth/eveonline/autogroups/models.py
AutogroupsConfig._replace_spaces
def _replace_spaces(self, name: str) -> str: """ Replace the spaces in the given name based on the config :param name: name to replace spaces in :return: name with spaces replaced with the configured character(s) or unchanged if configured """ if self.replace_spaces: return name.strip().replace(' ', str(self.replace_spaces_with)) return name
python
def _replace_spaces(self, name: str) -> str: """ Replace the spaces in the given name based on the config :param name: name to replace spaces in :return: name with spaces replaced with the configured character(s) or unchanged if configured """ if self.replace_spaces: return name.strip().replace(' ', str(self.replace_spaces_with)) return name
[ "def", "_replace_spaces", "(", "self", ",", "name", ":", "str", ")", "->", "str", ":", "if", "self", ".", "replace_spaces", ":", "return", "name", ".", "strip", "(", ")", ".", "replace", "(", "' '", ",", "str", "(", "self", ".", "replace_spaces_with", ")", ")", "return", "name" ]
Replace the spaces in the given name based on the config :param name: name to replace spaces in :return: name with spaces replaced with the configured character(s) or unchanged if configured
[ "Replace", "the", "spaces", "in", "the", "given", "name", "based", "on", "the", "config", ":", "param", "name", ":", "name", "to", "replace", "spaces", "in", ":", "return", ":", "name", "with", "spaces", "replaced", "with", "the", "configured", "character", "(", "s", ")", "or", "unchanged", "if", "configured" ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/eveonline/autogroups/models.py#L225-L233
allianceauth/allianceauth
allianceauth/services/modules/discord/manager.py
api_backoff
def api_backoff(func): """ Decorator, Handles HTTP 429 "Too Many Requests" messages from the Discord API If blocking=True is specified, this function will block and retry the function up to max_retries=n times, or 3 if retries is not specified. If the API call still recieves a backoff timer this function will raise a <DiscordApiTooBusy> exception. If the caller chooses blocking=False, the decorator will raise a DiscordApiBackoff exception and the caller can choose to retry after the given timespan available in the retry_after property in seconds. """ class PerformBackoff(Exception): def __init__(self, retry_after, retry_datetime, global_ratelimit): super(Exception, self).__init__() self.retry_after = int(retry_after) self.retry_datetime = retry_datetime self.global_ratelimit = global_ratelimit @wraps(func) def decorated(*args, **kwargs): blocking = kwargs.get('blocking', False) retries = kwargs.get('max_retries', 3) # Strip our parameters if 'max_retries' in kwargs: del kwargs['max_retries'] if 'blocking' in kwargs: del kwargs['blocking'] cache_key = 'DISCORD_BACKOFF_' + func.__name__ cache_global_key = 'DISCORD_BACKOFF_GLOBAL' while retries > 0: try: try: # Check global backoff first, then route backoff existing_global_backoff = cache.get(cache_global_key) existing_backoff = existing_global_backoff or cache.get(cache_key) if existing_backoff: backoff_timer = datetime.datetime.strptime(existing_backoff, cache_time_format) if backoff_timer > datetime.datetime.utcnow(): backoff_seconds = (backoff_timer - datetime.datetime.utcnow()).total_seconds() logger.debug("Still under backoff for %s seconds, backing off" % backoff_seconds) # Still under backoff raise PerformBackoff( retry_after=backoff_seconds, retry_datetime=backoff_timer, global_ratelimit=bool(existing_global_backoff) ) logger.debug("Calling API calling function") return func(*args, **kwargs) except requests.HTTPError as e: if e.response.status_code == 429: try: retry_after = int(e.response.headers['Retry-After']) except (TypeError, KeyError): # Pick some random time retry_after = 5000 logger.info("Received backoff from API of %s seconds, handling" % retry_after) # Store value in redis backoff_until = (datetime.datetime.utcnow() + datetime.timedelta(milliseconds=retry_after)) global_backoff = bool(e.response.headers.get('X-RateLimit-Global', False)) if global_backoff: logger.info("Global backoff!!") cache.set(cache_global_key, backoff_until.strftime(cache_time_format), retry_after) else: cache.set(cache_key, backoff_until.strftime(cache_time_format), retry_after) raise PerformBackoff(retry_after=retry_after, retry_datetime=backoff_until, global_ratelimit=global_backoff) else: # Not 429, re-raise raise e except PerformBackoff as bo: # Sleep if we're blocking if blocking: logger.info("Blocking Back off from API calls for %s seconds" % bo.retry_after) time.sleep((10 if bo.retry_after > 10 else bo.retry_after) / 1000) else: # Otherwise raise exception and let caller handle the backoff raise DiscordApiBackoff(retry_after=bo.retry_after, global_ratelimit=bo.global_ratelimit) finally: retries -= 1 if retries == 0: raise DiscordApiTooBusy() return decorated
python
def api_backoff(func): """ Decorator, Handles HTTP 429 "Too Many Requests" messages from the Discord API If blocking=True is specified, this function will block and retry the function up to max_retries=n times, or 3 if retries is not specified. If the API call still recieves a backoff timer this function will raise a <DiscordApiTooBusy> exception. If the caller chooses blocking=False, the decorator will raise a DiscordApiBackoff exception and the caller can choose to retry after the given timespan available in the retry_after property in seconds. """ class PerformBackoff(Exception): def __init__(self, retry_after, retry_datetime, global_ratelimit): super(Exception, self).__init__() self.retry_after = int(retry_after) self.retry_datetime = retry_datetime self.global_ratelimit = global_ratelimit @wraps(func) def decorated(*args, **kwargs): blocking = kwargs.get('blocking', False) retries = kwargs.get('max_retries', 3) # Strip our parameters if 'max_retries' in kwargs: del kwargs['max_retries'] if 'blocking' in kwargs: del kwargs['blocking'] cache_key = 'DISCORD_BACKOFF_' + func.__name__ cache_global_key = 'DISCORD_BACKOFF_GLOBAL' while retries > 0: try: try: # Check global backoff first, then route backoff existing_global_backoff = cache.get(cache_global_key) existing_backoff = existing_global_backoff or cache.get(cache_key) if existing_backoff: backoff_timer = datetime.datetime.strptime(existing_backoff, cache_time_format) if backoff_timer > datetime.datetime.utcnow(): backoff_seconds = (backoff_timer - datetime.datetime.utcnow()).total_seconds() logger.debug("Still under backoff for %s seconds, backing off" % backoff_seconds) # Still under backoff raise PerformBackoff( retry_after=backoff_seconds, retry_datetime=backoff_timer, global_ratelimit=bool(existing_global_backoff) ) logger.debug("Calling API calling function") return func(*args, **kwargs) except requests.HTTPError as e: if e.response.status_code == 429: try: retry_after = int(e.response.headers['Retry-After']) except (TypeError, KeyError): # Pick some random time retry_after = 5000 logger.info("Received backoff from API of %s seconds, handling" % retry_after) # Store value in redis backoff_until = (datetime.datetime.utcnow() + datetime.timedelta(milliseconds=retry_after)) global_backoff = bool(e.response.headers.get('X-RateLimit-Global', False)) if global_backoff: logger.info("Global backoff!!") cache.set(cache_global_key, backoff_until.strftime(cache_time_format), retry_after) else: cache.set(cache_key, backoff_until.strftime(cache_time_format), retry_after) raise PerformBackoff(retry_after=retry_after, retry_datetime=backoff_until, global_ratelimit=global_backoff) else: # Not 429, re-raise raise e except PerformBackoff as bo: # Sleep if we're blocking if blocking: logger.info("Blocking Back off from API calls for %s seconds" % bo.retry_after) time.sleep((10 if bo.retry_after > 10 else bo.retry_after) / 1000) else: # Otherwise raise exception and let caller handle the backoff raise DiscordApiBackoff(retry_after=bo.retry_after, global_ratelimit=bo.global_ratelimit) finally: retries -= 1 if retries == 0: raise DiscordApiTooBusy() return decorated
[ "def", "api_backoff", "(", "func", ")", ":", "class", "PerformBackoff", "(", "Exception", ")", ":", "def", "__init__", "(", "self", ",", "retry_after", ",", "retry_datetime", ",", "global_ratelimit", ")", ":", "super", "(", "Exception", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "retry_after", "=", "int", "(", "retry_after", ")", "self", ".", "retry_datetime", "=", "retry_datetime", "self", ".", "global_ratelimit", "=", "global_ratelimit", "@", "wraps", "(", "func", ")", "def", "decorated", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "blocking", "=", "kwargs", ".", "get", "(", "'blocking'", ",", "False", ")", "retries", "=", "kwargs", ".", "get", "(", "'max_retries'", ",", "3", ")", "# Strip our parameters", "if", "'max_retries'", "in", "kwargs", ":", "del", "kwargs", "[", "'max_retries'", "]", "if", "'blocking'", "in", "kwargs", ":", "del", "kwargs", "[", "'blocking'", "]", "cache_key", "=", "'DISCORD_BACKOFF_'", "+", "func", ".", "__name__", "cache_global_key", "=", "'DISCORD_BACKOFF_GLOBAL'", "while", "retries", ">", "0", ":", "try", ":", "try", ":", "# Check global backoff first, then route backoff", "existing_global_backoff", "=", "cache", ".", "get", "(", "cache_global_key", ")", "existing_backoff", "=", "existing_global_backoff", "or", "cache", ".", "get", "(", "cache_key", ")", "if", "existing_backoff", ":", "backoff_timer", "=", "datetime", ".", "datetime", ".", "strptime", "(", "existing_backoff", ",", "cache_time_format", ")", "if", "backoff_timer", ">", "datetime", ".", "datetime", ".", "utcnow", "(", ")", ":", "backoff_seconds", "=", "(", "backoff_timer", "-", "datetime", ".", "datetime", ".", "utcnow", "(", ")", ")", ".", "total_seconds", "(", ")", "logger", ".", "debug", "(", "\"Still under backoff for %s seconds, backing off\"", "%", "backoff_seconds", ")", "# Still under backoff", "raise", "PerformBackoff", "(", "retry_after", "=", "backoff_seconds", ",", "retry_datetime", "=", "backoff_timer", ",", "global_ratelimit", "=", "bool", "(", "existing_global_backoff", ")", ")", "logger", ".", "debug", "(", "\"Calling API calling function\"", ")", "return", "func", "(", "*", "args", ",", "*", "*", "kwargs", ")", "except", "requests", ".", "HTTPError", "as", "e", ":", "if", "e", ".", "response", ".", "status_code", "==", "429", ":", "try", ":", "retry_after", "=", "int", "(", "e", ".", "response", ".", "headers", "[", "'Retry-After'", "]", ")", "except", "(", "TypeError", ",", "KeyError", ")", ":", "# Pick some random time", "retry_after", "=", "5000", "logger", ".", "info", "(", "\"Received backoff from API of %s seconds, handling\"", "%", "retry_after", ")", "# Store value in redis", "backoff_until", "=", "(", "datetime", ".", "datetime", ".", "utcnow", "(", ")", "+", "datetime", ".", "timedelta", "(", "milliseconds", "=", "retry_after", ")", ")", "global_backoff", "=", "bool", "(", "e", ".", "response", ".", "headers", ".", "get", "(", "'X-RateLimit-Global'", ",", "False", ")", ")", "if", "global_backoff", ":", "logger", ".", "info", "(", "\"Global backoff!!\"", ")", "cache", ".", "set", "(", "cache_global_key", ",", "backoff_until", ".", "strftime", "(", "cache_time_format", ")", ",", "retry_after", ")", "else", ":", "cache", ".", "set", "(", "cache_key", ",", "backoff_until", ".", "strftime", "(", "cache_time_format", ")", ",", "retry_after", ")", "raise", "PerformBackoff", "(", "retry_after", "=", "retry_after", ",", "retry_datetime", "=", "backoff_until", ",", "global_ratelimit", "=", "global_backoff", ")", "else", ":", "# Not 429, re-raise", "raise", "e", "except", "PerformBackoff", "as", "bo", ":", "# Sleep if we're blocking", "if", "blocking", ":", "logger", ".", "info", "(", "\"Blocking Back off from API calls for %s seconds\"", "%", "bo", ".", "retry_after", ")", "time", ".", "sleep", "(", "(", "10", "if", "bo", ".", "retry_after", ">", "10", "else", "bo", ".", "retry_after", ")", "/", "1000", ")", "else", ":", "# Otherwise raise exception and let caller handle the backoff", "raise", "DiscordApiBackoff", "(", "retry_after", "=", "bo", ".", "retry_after", ",", "global_ratelimit", "=", "bo", ".", "global_ratelimit", ")", "finally", ":", "retries", "-=", "1", "if", "retries", "==", "0", ":", "raise", "DiscordApiTooBusy", "(", ")", "return", "decorated" ]
Decorator, Handles HTTP 429 "Too Many Requests" messages from the Discord API If blocking=True is specified, this function will block and retry the function up to max_retries=n times, or 3 if retries is not specified. If the API call still recieves a backoff timer this function will raise a <DiscordApiTooBusy> exception. If the caller chooses blocking=False, the decorator will raise a DiscordApiBackoff exception and the caller can choose to retry after the given timespan available in the retry_after property in seconds.
[ "Decorator", "Handles", "HTTP", "429", "Too", "Many", "Requests", "messages", "from", "the", "Discord", "API", "If", "blocking", "=", "True", "is", "specified", "this", "function", "will", "block", "and", "retry", "the", "function", "up", "to", "max_retries", "=", "n", "times", "or", "3", "if", "retries", "is", "not", "specified", ".", "If", "the", "API", "call", "still", "recieves", "a", "backoff", "timer", "this", "function", "will", "raise", "a", "<DiscordApiTooBusy", ">", "exception", ".", "If", "the", "caller", "chooses", "blocking", "=", "False", "the", "decorator", "will", "raise", "a", "DiscordApiBackoff", "exception", "and", "the", "caller", "can", "choose", "to", "retry", "after", "the", "given", "timespan", "available", "in", "the", "retry_after", "property", "in", "seconds", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/services/modules/discord/manager.py#L67-L154
allianceauth/allianceauth
allianceauth/srp/views.py
random_string
def random_string(string_length=10): """Returns a random string of length string_length.""" random = str(uuid.uuid4()) # Convert UUID format to a Python string. random = random.upper() # Make all characters uppercase. random = random.replace("-", "") # Remove the UUID '-'. return random[0:string_length]
python
def random_string(string_length=10): """Returns a random string of length string_length.""" random = str(uuid.uuid4()) # Convert UUID format to a Python string. random = random.upper() # Make all characters uppercase. random = random.replace("-", "") # Remove the UUID '-'. return random[0:string_length]
[ "def", "random_string", "(", "string_length", "=", "10", ")", ":", "random", "=", "str", "(", "uuid", ".", "uuid4", "(", ")", ")", "# Convert UUID format to a Python string.", "random", "=", "random", ".", "upper", "(", ")", "# Make all characters uppercase.", "random", "=", "random", ".", "replace", "(", "\"-\"", ",", "\"\"", ")", "# Remove the UUID '-'.", "return", "random", "[", "0", ":", "string_length", "]" ]
Returns a random string of length string_length.
[ "Returns", "a", "random", "string", "of", "length", "string_length", "." ]
train
https://github.com/allianceauth/allianceauth/blob/6585b07e96571a99a4d6dc03cc03f9b8c8f690ca/allianceauth/srp/views.py#L25-L30
tariqdaouda/pyGeno
pyGeno/Genome.py
getGenomeList
def getGenomeList() : """Return the names of all imported genomes""" import rabaDB.filters as rfilt f = rfilt.RabaQuery(Genome_Raba) names = [] for g in f.iterRun() : names.append(g.name) return names
python
def getGenomeList() : """Return the names of all imported genomes""" import rabaDB.filters as rfilt f = rfilt.RabaQuery(Genome_Raba) names = [] for g in f.iterRun() : names.append(g.name) return names
[ "def", "getGenomeList", "(", ")", ":", "import", "rabaDB", ".", "filters", "as", "rfilt", "f", "=", "rfilt", ".", "RabaQuery", "(", "Genome_Raba", ")", "names", "=", "[", "]", "for", "g", "in", "f", ".", "iterRun", "(", ")", ":", "names", ".", "append", "(", "g", ".", "name", ")", "return", "names" ]
Return the names of all imported genomes
[ "Return", "the", "names", "of", "all", "imported", "genomes" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/Genome.py#L16-L23
tariqdaouda/pyGeno
pyGeno/Transcript.py
Transcript.iterCodons
def iterCodons(self) : """iterates through the codons""" for i in range(len(self.cDNA)/3) : yield self.getCodon(i)
python
def iterCodons(self) : """iterates through the codons""" for i in range(len(self.cDNA)/3) : yield self.getCodon(i)
[ "def", "iterCodons", "(", "self", ")", ":", "for", "i", "in", "range", "(", "len", "(", "self", ".", "cDNA", ")", "/", "3", ")", ":", "yield", "self", ".", "getCodon", "(", "i", ")" ]
iterates through the codons
[ "iterates", "through", "the", "codons" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/Transcript.py#L165-L168
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
removeDuplicates
def removeDuplicates(inFileName, outFileName) : """removes duplicated lines from a 'inFileName' CSV file, the results are witten in 'outFileName'""" f = open(inFileName) legend = f.readline() data = '' h = {} h[legend] = 0 lines = f.readlines() for l in lines : if not h.has_key(l) : h[l] = 0 data += l f.flush() f.close() f = open(outFileName, 'w') f.write(legend+data) f.flush() f.close()
python
def removeDuplicates(inFileName, outFileName) : """removes duplicated lines from a 'inFileName' CSV file, the results are witten in 'outFileName'""" f = open(inFileName) legend = f.readline() data = '' h = {} h[legend] = 0 lines = f.readlines() for l in lines : if not h.has_key(l) : h[l] = 0 data += l f.flush() f.close() f = open(outFileName, 'w') f.write(legend+data) f.flush() f.close()
[ "def", "removeDuplicates", "(", "inFileName", ",", "outFileName", ")", ":", "f", "=", "open", "(", "inFileName", ")", "legend", "=", "f", ".", "readline", "(", ")", "data", "=", "''", "h", "=", "{", "}", "h", "[", "legend", "]", "=", "0", "lines", "=", "f", ".", "readlines", "(", ")", "for", "l", "in", "lines", ":", "if", "not", "h", ".", "has_key", "(", "l", ")", ":", "h", "[", "l", "]", "=", "0", "data", "+=", "l", "f", ".", "flush", "(", ")", "f", ".", "close", "(", ")", "f", "=", "open", "(", "outFileName", ",", "'w'", ")", "f", ".", "write", "(", "legend", "+", "data", ")", "f", ".", "flush", "(", ")", "f", ".", "close", "(", ")" ]
removes duplicated lines from a 'inFileName' CSV file, the results are witten in 'outFileName
[ "removes", "duplicated", "lines", "from", "a", "inFileName", "CSV", "file", "the", "results", "are", "witten", "in", "outFileName" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L14-L34
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
catCSVs
def catCSVs(folder, ouputFileName, removeDups = False) : """Concatenates all csv in 'folder' and wites the results in 'ouputFileName'. My not work on non Unix systems""" strCmd = r"""cat %s/*.csv > %s""" %(folder, ouputFileName) os.system(strCmd) if removeDups : removeDuplicates(ouputFileName, ouputFileName)
python
def catCSVs(folder, ouputFileName, removeDups = False) : """Concatenates all csv in 'folder' and wites the results in 'ouputFileName'. My not work on non Unix systems""" strCmd = r"""cat %s/*.csv > %s""" %(folder, ouputFileName) os.system(strCmd) if removeDups : removeDuplicates(ouputFileName, ouputFileName)
[ "def", "catCSVs", "(", "folder", ",", "ouputFileName", ",", "removeDups", "=", "False", ")", ":", "strCmd", "=", "r\"\"\"cat %s/*.csv > %s\"\"\"", "%", "(", "folder", ",", "ouputFileName", ")", "os", ".", "system", "(", "strCmd", ")", "if", "removeDups", ":", "removeDuplicates", "(", "ouputFileName", ",", "ouputFileName", ")" ]
Concatenates all csv in 'folder' and wites the results in 'ouputFileName'. My not work on non Unix systems
[ "Concatenates", "all", "csv", "in", "folder", "and", "wites", "the", "results", "in", "ouputFileName", ".", "My", "not", "work", "on", "non", "Unix", "systems" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L36-L42
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
joinCSVs
def joinCSVs(csvFilePaths, column, ouputFileName, separator = ',') : """csvFilePaths should be an iterable. Joins all CSVs according to the values in the column 'column'. Write the results in a new file 'ouputFileName' """ res = '' legend = [] csvs = [] for f in csvFilePaths : c = CSVFile() c.parse(f) csvs.append(c) legend.append(separator.join(c.legend.keys())) legend = separator.join(legend) lines = [] for i in range(len(csvs[0])) : val = csvs[0].get(i, column) line = separator.join(csvs[0][i]) for c in csvs[1:] : for j in range(len(c)) : if val == c.get(j, column) : line += separator + separator.join(c[j]) lines.append( line ) res = legend + '\n' + '\n'.join(lines) f = open(ouputFileName, 'w') f.write(res) f.flush() f.close() return res
python
def joinCSVs(csvFilePaths, column, ouputFileName, separator = ',') : """csvFilePaths should be an iterable. Joins all CSVs according to the values in the column 'column'. Write the results in a new file 'ouputFileName' """ res = '' legend = [] csvs = [] for f in csvFilePaths : c = CSVFile() c.parse(f) csvs.append(c) legend.append(separator.join(c.legend.keys())) legend = separator.join(legend) lines = [] for i in range(len(csvs[0])) : val = csvs[0].get(i, column) line = separator.join(csvs[0][i]) for c in csvs[1:] : for j in range(len(c)) : if val == c.get(j, column) : line += separator + separator.join(c[j]) lines.append( line ) res = legend + '\n' + '\n'.join(lines) f = open(ouputFileName, 'w') f.write(res) f.flush() f.close() return res
[ "def", "joinCSVs", "(", "csvFilePaths", ",", "column", ",", "ouputFileName", ",", "separator", "=", "','", ")", ":", "res", "=", "''", "legend", "=", "[", "]", "csvs", "=", "[", "]", "for", "f", "in", "csvFilePaths", ":", "c", "=", "CSVFile", "(", ")", "c", ".", "parse", "(", "f", ")", "csvs", ".", "append", "(", "c", ")", "legend", ".", "append", "(", "separator", ".", "join", "(", "c", ".", "legend", ".", "keys", "(", ")", ")", ")", "legend", "=", "separator", ".", "join", "(", "legend", ")", "lines", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "csvs", "[", "0", "]", ")", ")", ":", "val", "=", "csvs", "[", "0", "]", ".", "get", "(", "i", ",", "column", ")", "line", "=", "separator", ".", "join", "(", "csvs", "[", "0", "]", "[", "i", "]", ")", "for", "c", "in", "csvs", "[", "1", ":", "]", ":", "for", "j", "in", "range", "(", "len", "(", "c", ")", ")", ":", "if", "val", "==", "c", ".", "get", "(", "j", ",", "column", ")", ":", "line", "+=", "separator", "+", "separator", ".", "join", "(", "c", "[", "j", "]", ")", "lines", ".", "append", "(", "line", ")", "res", "=", "legend", "+", "'\\n'", "+", "'\\n'", ".", "join", "(", "lines", ")", "f", "=", "open", "(", "ouputFileName", ",", "'w'", ")", "f", ".", "write", "(", "res", ")", "f", ".", "flush", "(", ")", "f", ".", "close", "(", ")", "return", "res" ]
csvFilePaths should be an iterable. Joins all CSVs according to the values in the column 'column'. Write the results in a new file 'ouputFileName'
[ "csvFilePaths", "should", "be", "an", "iterable", ".", "Joins", "all", "CSVs", "according", "to", "the", "values", "in", "the", "column", "column", ".", "Write", "the", "results", "in", "a", "new", "file", "ouputFileName" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L44-L76
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.addField
def addField(self, field) : """add a filed to the legend""" if field.lower() in self.legend : raise ValueError("%s is already in the legend" % field.lower()) self.legend[field.lower()] = len(self.legend) if len(self.strLegend) > 0 : self.strLegend += self.separator + field else : self.strLegend += field
python
def addField(self, field) : """add a filed to the legend""" if field.lower() in self.legend : raise ValueError("%s is already in the legend" % field.lower()) self.legend[field.lower()] = len(self.legend) if len(self.strLegend) > 0 : self.strLegend += self.separator + field else : self.strLegend += field
[ "def", "addField", "(", "self", ",", "field", ")", ":", "if", "field", ".", "lower", "(", ")", "in", "self", ".", "legend", ":", "raise", "ValueError", "(", "\"%s is already in the legend\"", "%", "field", ".", "lower", "(", ")", ")", "self", ".", "legend", "[", "field", ".", "lower", "(", ")", "]", "=", "len", "(", "self", ".", "legend", ")", "if", "len", "(", "self", ".", "strLegend", ")", ">", "0", ":", "self", ".", "strLegend", "+=", "self", ".", "separator", "+", "field", "else", ":", "self", ".", "strLegend", "+=", "field" ]
add a filed to the legend
[ "add", "a", "filed", "to", "the", "legend" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L221-L229
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.parse
def parse(self, filePath, skipLines=0, separator = ',', stringSeparator = '"', lineSeparator = '\n') : """Loads a CSV file""" self.filename = filePath f = open(filePath) if lineSeparator == '\n' : lines = f.readlines() else : lines = f.read().split(lineSeparator) f.flush() f.close() lines = lines[skipLines:] self.lines = [] self.comments = [] for l in lines : # print l if len(l) != 0 and l[0] != "#" : self.lines.append(l) elif l[0] == "#" : self.comments.append(l) self.separator = separator self.lineSeparator = lineSeparator self.stringSeparator = stringSeparator self.legend = collections.OrderedDict() i = 0 for c in self.lines[0].lower().replace(stringSeparator, '').split(separator) : legendElement = c.strip() if legendElement not in self.legend : self.legend[legendElement] = i i+=1 self.strLegend = self.lines[0].replace('\r', '\n').replace('\n', '') self.lines = self.lines[1:]
python
def parse(self, filePath, skipLines=0, separator = ',', stringSeparator = '"', lineSeparator = '\n') : """Loads a CSV file""" self.filename = filePath f = open(filePath) if lineSeparator == '\n' : lines = f.readlines() else : lines = f.read().split(lineSeparator) f.flush() f.close() lines = lines[skipLines:] self.lines = [] self.comments = [] for l in lines : # print l if len(l) != 0 and l[0] != "#" : self.lines.append(l) elif l[0] == "#" : self.comments.append(l) self.separator = separator self.lineSeparator = lineSeparator self.stringSeparator = stringSeparator self.legend = collections.OrderedDict() i = 0 for c in self.lines[0].lower().replace(stringSeparator, '').split(separator) : legendElement = c.strip() if legendElement not in self.legend : self.legend[legendElement] = i i+=1 self.strLegend = self.lines[0].replace('\r', '\n').replace('\n', '') self.lines = self.lines[1:]
[ "def", "parse", "(", "self", ",", "filePath", ",", "skipLines", "=", "0", ",", "separator", "=", "','", ",", "stringSeparator", "=", "'\"'", ",", "lineSeparator", "=", "'\\n'", ")", ":", "self", ".", "filename", "=", "filePath", "f", "=", "open", "(", "filePath", ")", "if", "lineSeparator", "==", "'\\n'", ":", "lines", "=", "f", ".", "readlines", "(", ")", "else", ":", "lines", "=", "f", ".", "read", "(", ")", ".", "split", "(", "lineSeparator", ")", "f", ".", "flush", "(", ")", "f", ".", "close", "(", ")", "lines", "=", "lines", "[", "skipLines", ":", "]", "self", ".", "lines", "=", "[", "]", "self", ".", "comments", "=", "[", "]", "for", "l", "in", "lines", ":", "# print l", "if", "len", "(", "l", ")", "!=", "0", "and", "l", "[", "0", "]", "!=", "\"#\"", ":", "self", ".", "lines", ".", "append", "(", "l", ")", "elif", "l", "[", "0", "]", "==", "\"#\"", ":", "self", ".", "comments", ".", "append", "(", "l", ")", "self", ".", "separator", "=", "separator", "self", ".", "lineSeparator", "=", "lineSeparator", "self", ".", "stringSeparator", "=", "stringSeparator", "self", ".", "legend", "=", "collections", ".", "OrderedDict", "(", ")", "i", "=", "0", "for", "c", "in", "self", ".", "lines", "[", "0", "]", ".", "lower", "(", ")", ".", "replace", "(", "stringSeparator", ",", "''", ")", ".", "split", "(", "separator", ")", ":", "legendElement", "=", "c", ".", "strip", "(", ")", "if", "legendElement", "not", "in", "self", ".", "legend", ":", "self", ".", "legend", "[", "legendElement", "]", "=", "i", "i", "+=", "1", "self", ".", "strLegend", "=", "self", ".", "lines", "[", "0", "]", ".", "replace", "(", "'\\r'", ",", "'\\n'", ")", ".", "replace", "(", "'\\n'", ",", "''", ")", "self", ".", "lines", "=", "self", ".", "lines", "[", "1", ":", "]" ]
Loads a CSV file
[ "Loads", "a", "CSV", "file" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L231-L266
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.streamToFile
def streamToFile(self, filename, keepInMemory = False, writeRate = 1) : """Starts a stream to a file. Every line must be committed (l.commit()) to be appended in to the file. If keepInMemory is set to True, the parser will keep a version of the whole CSV in memory, writeRate is the number of lines that must be committed before an automatic save is triggered. """ if len(self.legend) < 1 : raise ValueError("There's no legend defined") try : os.remove(filename) except : pass self.streamFile = open(filename, "a") self.writeRate = writeRate self.streamBuffer = [] self.keepInMemory = keepInMemory self.streamFile.write(self.strLegend + "\n")
python
def streamToFile(self, filename, keepInMemory = False, writeRate = 1) : """Starts a stream to a file. Every line must be committed (l.commit()) to be appended in to the file. If keepInMemory is set to True, the parser will keep a version of the whole CSV in memory, writeRate is the number of lines that must be committed before an automatic save is triggered. """ if len(self.legend) < 1 : raise ValueError("There's no legend defined") try : os.remove(filename) except : pass self.streamFile = open(filename, "a") self.writeRate = writeRate self.streamBuffer = [] self.keepInMemory = keepInMemory self.streamFile.write(self.strLegend + "\n")
[ "def", "streamToFile", "(", "self", ",", "filename", ",", "keepInMemory", "=", "False", ",", "writeRate", "=", "1", ")", ":", "if", "len", "(", "self", ".", "legend", ")", "<", "1", ":", "raise", "ValueError", "(", "\"There's no legend defined\"", ")", "try", ":", "os", ".", "remove", "(", "filename", ")", "except", ":", "pass", "self", ".", "streamFile", "=", "open", "(", "filename", ",", "\"a\"", ")", "self", ".", "writeRate", "=", "writeRate", "self", ".", "streamBuffer", "=", "[", "]", "self", ".", "keepInMemory", "=", "keepInMemory", "self", ".", "streamFile", ".", "write", "(", "self", ".", "strLegend", "+", "\"\\n\"", ")" ]
Starts a stream to a file. Every line must be committed (l.commit()) to be appended in to the file. If keepInMemory is set to True, the parser will keep a version of the whole CSV in memory, writeRate is the number of lines that must be committed before an automatic save is triggered.
[ "Starts", "a", "stream", "to", "a", "file", ".", "Every", "line", "must", "be", "committed", "(", "l", ".", "commit", "()", ")", "to", "be", "appended", "in", "to", "the", "file", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L278-L297
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.commitLine
def commitLine(self, line) : """Commits a line making it ready to be streamed to a file and saves the current buffer if needed. If no stream is active, raises a ValueError""" if self.streamBuffer is None : raise ValueError("Commit lines is only for when you are streaming to a file") self.streamBuffer.append(line) if len(self.streamBuffer) % self.writeRate == 0 : for i in xrange(len(self.streamBuffer)) : self.streamBuffer[i] = str(self.streamBuffer[i]) self.streamFile.write("%s\n" % ('\n'.join(self.streamBuffer))) self.streamFile.flush() self.streamBuffer = []
python
def commitLine(self, line) : """Commits a line making it ready to be streamed to a file and saves the current buffer if needed. If no stream is active, raises a ValueError""" if self.streamBuffer is None : raise ValueError("Commit lines is only for when you are streaming to a file") self.streamBuffer.append(line) if len(self.streamBuffer) % self.writeRate == 0 : for i in xrange(len(self.streamBuffer)) : self.streamBuffer[i] = str(self.streamBuffer[i]) self.streamFile.write("%s\n" % ('\n'.join(self.streamBuffer))) self.streamFile.flush() self.streamBuffer = []
[ "def", "commitLine", "(", "self", ",", "line", ")", ":", "if", "self", ".", "streamBuffer", "is", "None", ":", "raise", "ValueError", "(", "\"Commit lines is only for when you are streaming to a file\"", ")", "self", ".", "streamBuffer", ".", "append", "(", "line", ")", "if", "len", "(", "self", ".", "streamBuffer", ")", "%", "self", ".", "writeRate", "==", "0", ":", "for", "i", "in", "xrange", "(", "len", "(", "self", ".", "streamBuffer", ")", ")", ":", "self", ".", "streamBuffer", "[", "i", "]", "=", "str", "(", "self", ".", "streamBuffer", "[", "i", "]", ")", "self", ".", "streamFile", ".", "write", "(", "\"%s\\n\"", "%", "(", "'\\n'", ".", "join", "(", "self", ".", "streamBuffer", ")", ")", ")", "self", ".", "streamFile", ".", "flush", "(", ")", "self", ".", "streamBuffer", "=", "[", "]" ]
Commits a line making it ready to be streamed to a file and saves the current buffer if needed. If no stream is active, raises a ValueError
[ "Commits", "a", "line", "making", "it", "ready", "to", "be", "streamed", "to", "a", "file", "and", "saves", "the", "current", "buffer", "if", "needed", ".", "If", "no", "stream", "is", "active", "raises", "a", "ValueError" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L299-L310
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.closeStreamToFile
def closeStreamToFile(self) : """Appends the remaining commited lines and closes the stream. If no stream is active, raises a ValueError""" if self.streamBuffer is None : raise ValueError("Commit lines is only for when you are streaming to a file") for i in xrange(len(self.streamBuffer)) : self.streamBuffer[i] = str(self.streamBuffer[i]) self.streamFile.write('\n'.join(self.streamBuffer)) self.streamFile.close() self.streamFile = None self.writeRate = None self.streamBuffer = None self.keepInMemory = True
python
def closeStreamToFile(self) : """Appends the remaining commited lines and closes the stream. If no stream is active, raises a ValueError""" if self.streamBuffer is None : raise ValueError("Commit lines is only for when you are streaming to a file") for i in xrange(len(self.streamBuffer)) : self.streamBuffer[i] = str(self.streamBuffer[i]) self.streamFile.write('\n'.join(self.streamBuffer)) self.streamFile.close() self.streamFile = None self.writeRate = None self.streamBuffer = None self.keepInMemory = True
[ "def", "closeStreamToFile", "(", "self", ")", ":", "if", "self", ".", "streamBuffer", "is", "None", ":", "raise", "ValueError", "(", "\"Commit lines is only for when you are streaming to a file\"", ")", "for", "i", "in", "xrange", "(", "len", "(", "self", ".", "streamBuffer", ")", ")", ":", "self", ".", "streamBuffer", "[", "i", "]", "=", "str", "(", "self", ".", "streamBuffer", "[", "i", "]", ")", "self", ".", "streamFile", ".", "write", "(", "'\\n'", ".", "join", "(", "self", ".", "streamBuffer", ")", ")", "self", ".", "streamFile", ".", "close", "(", ")", "self", ".", "streamFile", "=", "None", "self", ".", "writeRate", "=", "None", "self", ".", "streamBuffer", "=", "None", "self", ".", "keepInMemory", "=", "True" ]
Appends the remaining commited lines and closes the stream. If no stream is active, raises a ValueError
[ "Appends", "the", "remaining", "commited", "lines", "and", "closes", "the", "stream", ".", "If", "no", "stream", "is", "active", "raises", "a", "ValueError" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L312-L325
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.newLine
def newLine(self) : """Appends an empty line at the end of the CSV and returns it""" l = CSVEntry(self) if self.keepInMemory : self.lines.append(l) return l
python
def newLine(self) : """Appends an empty line at the end of the CSV and returns it""" l = CSVEntry(self) if self.keepInMemory : self.lines.append(l) return l
[ "def", "newLine", "(", "self", ")", ":", "l", "=", "CSVEntry", "(", "self", ")", "if", "self", ".", "keepInMemory", ":", "self", ".", "lines", ".", "append", "(", "l", ")", "return", "l" ]
Appends an empty line at the end of the CSV and returns it
[ "Appends", "an", "empty", "line", "at", "the", "end", "of", "the", "CSV", "and", "returns", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L350-L355
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.insertLine
def insertLine(self, i) : """Inserts an empty line at position i and returns it""" self.data.insert(i, CSVEntry(self)) return self.lines[i]
python
def insertLine(self, i) : """Inserts an empty line at position i and returns it""" self.data.insert(i, CSVEntry(self)) return self.lines[i]
[ "def", "insertLine", "(", "self", ",", "i", ")", ":", "self", ".", "data", ".", "insert", "(", "i", ",", "CSVEntry", "(", "self", ")", ")", "return", "self", ".", "lines", "[", "i", "]" ]
Inserts an empty line at position i and returns it
[ "Inserts", "an", "empty", "line", "at", "position", "i", "and", "returns", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L357-L360
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.save
def save(self, filePath) : """save the CSV to a file""" self.filename = filePath f = open(filePath, 'w') f.write(self.toStr()) f.flush() f.close()
python
def save(self, filePath) : """save the CSV to a file""" self.filename = filePath f = open(filePath, 'w') f.write(self.toStr()) f.flush() f.close()
[ "def", "save", "(", "self", ",", "filePath", ")", ":", "self", ".", "filename", "=", "filePath", "f", "=", "open", "(", "filePath", ",", "'w'", ")", "f", ".", "write", "(", "self", ".", "toStr", "(", ")", ")", "f", ".", "flush", "(", ")", "f", ".", "close", "(", ")" ]
save the CSV to a file
[ "save", "the", "CSV", "to", "a", "file" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L362-L368
tariqdaouda/pyGeno
pyGeno/tools/parsers/CSVTools.py
CSVFile.toStr
def toStr(self) : """returns a string version of the CSV""" s = [self.strLegend] for l in self.lines : s.append(l.toStr()) return self.lineSeparator.join(s)
python
def toStr(self) : """returns a string version of the CSV""" s = [self.strLegend] for l in self.lines : s.append(l.toStr()) return self.lineSeparator.join(s)
[ "def", "toStr", "(", "self", ")", ":", "s", "=", "[", "self", ".", "strLegend", "]", "for", "l", "in", "self", ".", "lines", ":", "s", ".", "append", "(", "l", ".", "toStr", "(", ")", ")", "return", "self", ".", "lineSeparator", ".", "join", "(", "s", ")" ]
returns a string version of the CSV
[ "returns", "a", "string", "version", "of", "the", "CSV" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/CSVTools.py#L370-L375
tariqdaouda/pyGeno
pyGeno/pyGenoObjectBases.py
pyGenoRabaObjectWrapper.count
def count(self, objectType, *args, **coolArgs) : """Returns the number of elements satisfying the query""" return self._makeLoadQuery(objectType, *args, **coolArgs).count()
python
def count(self, objectType, *args, **coolArgs) : """Returns the number of elements satisfying the query""" return self._makeLoadQuery(objectType, *args, **coolArgs).count()
[ "def", "count", "(", "self", ",", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ":", "return", "self", ".", "_makeLoadQuery", "(", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ".", "count", "(", ")" ]
Returns the number of elements satisfying the query
[ "Returns", "the", "number", "of", "elements", "satisfying", "the", "query" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/pyGenoObjectBases.py#L112-L114
tariqdaouda/pyGeno
pyGeno/pyGenoObjectBases.py
pyGenoRabaObjectWrapper.get
def get(self, objectType, *args, **coolArgs) : """Raba Magic inside. This is th function that you use for querying pyGeno's DB. Usage examples: * myGenome.get("Gene", name = 'TPST2') * myGene.get(Protein, id = 'ENSID...') * myGenome.get(Transcript, {'start >' : x, 'end <' : y})""" ret = [] for e in self._makeLoadQuery(objectType, *args, **coolArgs).iterRun() : if issubclass(objectType, pyGenoRabaObjectWrapper) : ret.append(objectType(wrapped_object_and_bag = (e, self.bagKey))) else : ret.append(e) return ret
python
def get(self, objectType, *args, **coolArgs) : """Raba Magic inside. This is th function that you use for querying pyGeno's DB. Usage examples: * myGenome.get("Gene", name = 'TPST2') * myGene.get(Protein, id = 'ENSID...') * myGenome.get(Transcript, {'start >' : x, 'end <' : y})""" ret = [] for e in self._makeLoadQuery(objectType, *args, **coolArgs).iterRun() : if issubclass(objectType, pyGenoRabaObjectWrapper) : ret.append(objectType(wrapped_object_and_bag = (e, self.bagKey))) else : ret.append(e) return ret
[ "def", "get", "(", "self", ",", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ":", "ret", "=", "[", "]", "for", "e", "in", "self", ".", "_makeLoadQuery", "(", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ".", "iterRun", "(", ")", ":", "if", "issubclass", "(", "objectType", ",", "pyGenoRabaObjectWrapper", ")", ":", "ret", ".", "append", "(", "objectType", "(", "wrapped_object_and_bag", "=", "(", "e", ",", "self", ".", "bagKey", ")", ")", ")", "else", ":", "ret", ".", "append", "(", "e", ")", "return", "ret" ]
Raba Magic inside. This is th function that you use for querying pyGeno's DB. Usage examples: * myGenome.get("Gene", name = 'TPST2') * myGene.get(Protein, id = 'ENSID...') * myGenome.get(Transcript, {'start >' : x, 'end <' : y})
[ "Raba", "Magic", "inside", ".", "This", "is", "th", "function", "that", "you", "use", "for", "querying", "pyGeno", "s", "DB", ".", "Usage", "examples", ":", "*", "myGenome", ".", "get", "(", "Gene", "name", "=", "TPST2", ")", "*", "myGene", ".", "get", "(", "Protein", "id", "=", "ENSID", "...", ")", "*", "myGenome", ".", "get", "(", "Transcript", "{", "start", ">", ":", "x", "end", "<", ":", "y", "}", ")" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/pyGenoObjectBases.py#L116-L135
tariqdaouda/pyGeno
pyGeno/pyGenoObjectBases.py
pyGenoRabaObjectWrapper.iterGet
def iterGet(self, objectType, *args, **coolArgs) : """Same as get. But retuns the elements one by one, much more efficient for large outputs""" for e in self._makeLoadQuery(objectType, *args, **coolArgs).iterRun() : if issubclass(objectType, pyGenoRabaObjectWrapper) : yield objectType(wrapped_object_and_bag = (e, self.bagKey)) else : yield e
python
def iterGet(self, objectType, *args, **coolArgs) : """Same as get. But retuns the elements one by one, much more efficient for large outputs""" for e in self._makeLoadQuery(objectType, *args, **coolArgs).iterRun() : if issubclass(objectType, pyGenoRabaObjectWrapper) : yield objectType(wrapped_object_and_bag = (e, self.bagKey)) else : yield e
[ "def", "iterGet", "(", "self", ",", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ":", "for", "e", "in", "self", ".", "_makeLoadQuery", "(", "objectType", ",", "*", "args", ",", "*", "*", "coolArgs", ")", ".", "iterRun", "(", ")", ":", "if", "issubclass", "(", "objectType", ",", "pyGenoRabaObjectWrapper", ")", ":", "yield", "objectType", "(", "wrapped_object_and_bag", "=", "(", "e", ",", "self", ".", "bagKey", ")", ")", "else", ":", "yield", "e" ]
Same as get. But retuns the elements one by one, much more efficient for large outputs
[ "Same", "as", "get", ".", "But", "retuns", "the", "elements", "one", "by", "one", "much", "more", "efficient", "for", "large", "outputs" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/pyGenoObjectBases.py#L137-L144
tariqdaouda/pyGeno
pyGeno/importation/SNPs.py
importSNPs
def importSNPs(packageFile) : """The big wrapper, this function should detect the SNP type by the package manifest and then launch the corresponding function. Here's an example of a SNP manifest file for Casava SNPs:: [package_infos] description = Casava SNPs for testing purposes maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = 1 [set_infos] species = human name = dummySRY type = Agnostic source = my place at the IRIC [snps] filename = snps.txt # as with genomes you can either include de file at the root of the package or specify an URL from where it must be downloaded """ printf("Importing polymorphism set: %s... (This may take a while)" % packageFile) isDir = False if not os.path.isdir(packageFile) : packageDir = _decompressPackage(packageFile) else : isDir = True packageDir = packageFile fpMan = os.path.normpath(packageDir+'/manifest.ini') if not os.path.isfile(fpMan) : raise ValueError("Not file named manifest.ini! Mais quel SCANDALE!!!!") parser = SafeConfigParser() parser.read(os.path.normpath(packageDir+'/manifest.ini')) packageInfos = parser.items('package_infos') setName = parser.get('set_infos', 'name') typ = parser.get('set_infos', 'type') if typ.lower()[-3:] != 'snp' : typ += 'SNP' species = parser.get('set_infos', 'species').lower() genomeSource = parser.get('set_infos', 'source') snpsFileTmp = parser.get('snps', 'filename').strip() snpsFile = _getFile(parser.get('snps', 'filename'), packageDir) return_value = None try : SMaster = SNPMaster(setName = setName) except KeyError : if typ.lower() == 'casavasnp' : return_value = _importSNPs_CasavaSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'dbsnpsnp' : return_value = _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'dbsnp' : return_value = _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'tophatsnp' : return_value = _importSNPs_TopHatSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'agnosticsnp' : return_value = _importSNPs_AgnosticSNP(setName, species, genomeSource, snpsFile) else : raise FutureWarning('Unknown SNP type in manifest %s' % typ) else : raise KeyError("There's already a SNP set by the name %s. Use deleteSNPs() to remove it first" %setName) if not isDir : shutil.rmtree(packageDir) return return_value
python
def importSNPs(packageFile) : """The big wrapper, this function should detect the SNP type by the package manifest and then launch the corresponding function. Here's an example of a SNP manifest file for Casava SNPs:: [package_infos] description = Casava SNPs for testing purposes maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = 1 [set_infos] species = human name = dummySRY type = Agnostic source = my place at the IRIC [snps] filename = snps.txt # as with genomes you can either include de file at the root of the package or specify an URL from where it must be downloaded """ printf("Importing polymorphism set: %s... (This may take a while)" % packageFile) isDir = False if not os.path.isdir(packageFile) : packageDir = _decompressPackage(packageFile) else : isDir = True packageDir = packageFile fpMan = os.path.normpath(packageDir+'/manifest.ini') if not os.path.isfile(fpMan) : raise ValueError("Not file named manifest.ini! Mais quel SCANDALE!!!!") parser = SafeConfigParser() parser.read(os.path.normpath(packageDir+'/manifest.ini')) packageInfos = parser.items('package_infos') setName = parser.get('set_infos', 'name') typ = parser.get('set_infos', 'type') if typ.lower()[-3:] != 'snp' : typ += 'SNP' species = parser.get('set_infos', 'species').lower() genomeSource = parser.get('set_infos', 'source') snpsFileTmp = parser.get('snps', 'filename').strip() snpsFile = _getFile(parser.get('snps', 'filename'), packageDir) return_value = None try : SMaster = SNPMaster(setName = setName) except KeyError : if typ.lower() == 'casavasnp' : return_value = _importSNPs_CasavaSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'dbsnpsnp' : return_value = _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'dbsnp' : return_value = _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'tophatsnp' : return_value = _importSNPs_TopHatSNP(setName, species, genomeSource, snpsFile) elif typ.lower() == 'agnosticsnp' : return_value = _importSNPs_AgnosticSNP(setName, species, genomeSource, snpsFile) else : raise FutureWarning('Unknown SNP type in manifest %s' % typ) else : raise KeyError("There's already a SNP set by the name %s. Use deleteSNPs() to remove it first" %setName) if not isDir : shutil.rmtree(packageDir) return return_value
[ "def", "importSNPs", "(", "packageFile", ")", ":", "printf", "(", "\"Importing polymorphism set: %s... (This may take a while)\"", "%", "packageFile", ")", "isDir", "=", "False", "if", "not", "os", ".", "path", ".", "isdir", "(", "packageFile", ")", ":", "packageDir", "=", "_decompressPackage", "(", "packageFile", ")", "else", ":", "isDir", "=", "True", "packageDir", "=", "packageFile", "fpMan", "=", "os", ".", "path", ".", "normpath", "(", "packageDir", "+", "'/manifest.ini'", ")", "if", "not", "os", ".", "path", ".", "isfile", "(", "fpMan", ")", ":", "raise", "ValueError", "(", "\"Not file named manifest.ini! Mais quel SCANDALE!!!!\"", ")", "parser", "=", "SafeConfigParser", "(", ")", "parser", ".", "read", "(", "os", ".", "path", ".", "normpath", "(", "packageDir", "+", "'/manifest.ini'", ")", ")", "packageInfos", "=", "parser", ".", "items", "(", "'package_infos'", ")", "setName", "=", "parser", ".", "get", "(", "'set_infos'", ",", "'name'", ")", "typ", "=", "parser", ".", "get", "(", "'set_infos'", ",", "'type'", ")", "if", "typ", ".", "lower", "(", ")", "[", "-", "3", ":", "]", "!=", "'snp'", ":", "typ", "+=", "'SNP'", "species", "=", "parser", ".", "get", "(", "'set_infos'", ",", "'species'", ")", ".", "lower", "(", ")", "genomeSource", "=", "parser", ".", "get", "(", "'set_infos'", ",", "'source'", ")", "snpsFileTmp", "=", "parser", ".", "get", "(", "'snps'", ",", "'filename'", ")", ".", "strip", "(", ")", "snpsFile", "=", "_getFile", "(", "parser", ".", "get", "(", "'snps'", ",", "'filename'", ")", ",", "packageDir", ")", "return_value", "=", "None", "try", ":", "SMaster", "=", "SNPMaster", "(", "setName", "=", "setName", ")", "except", "KeyError", ":", "if", "typ", ".", "lower", "(", ")", "==", "'casavasnp'", ":", "return_value", "=", "_importSNPs_CasavaSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", "elif", "typ", ".", "lower", "(", ")", "==", "'dbsnpsnp'", ":", "return_value", "=", "_importSNPs_dbSNPSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", "elif", "typ", ".", "lower", "(", ")", "==", "'dbsnp'", ":", "return_value", "=", "_importSNPs_dbSNPSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", "elif", "typ", ".", "lower", "(", ")", "==", "'tophatsnp'", ":", "return_value", "=", "_importSNPs_TopHatSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", "elif", "typ", ".", "lower", "(", ")", "==", "'agnosticsnp'", ":", "return_value", "=", "_importSNPs_AgnosticSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", "else", ":", "raise", "FutureWarning", "(", "'Unknown SNP type in manifest %s'", "%", "typ", ")", "else", ":", "raise", "KeyError", "(", "\"There's already a SNP set by the name %s. Use deleteSNPs() to remove it first\"", "%", "setName", ")", "if", "not", "isDir", ":", "shutil", ".", "rmtree", "(", "packageDir", ")", "return", "return_value" ]
The big wrapper, this function should detect the SNP type by the package manifest and then launch the corresponding function. Here's an example of a SNP manifest file for Casava SNPs:: [package_infos] description = Casava SNPs for testing purposes maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = 1 [set_infos] species = human name = dummySRY type = Agnostic source = my place at the IRIC [snps] filename = snps.txt # as with genomes you can either include de file at the root of the package or specify an URL from where it must be downloaded
[ "The", "big", "wrapper", "this", "function", "should", "detect", "the", "SNP", "type", "by", "the", "package", "manifest", "and", "then", "launch", "the", "corresponding", "function", ".", "Here", "s", "an", "example", "of", "a", "SNP", "manifest", "file", "for", "Casava", "SNPs", "::" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/SNPs.py#L14-L84
tariqdaouda/pyGeno
pyGeno/importation/SNPs.py
deleteSNPs
def deleteSNPs(setName) : """deletes a set of polymorphisms""" con = conf.db try : SMaster = SNPMaster(setName = setName) con.beginTransaction() SNPType = SMaster.SNPType con.delete(SNPType, 'setName = ?', (setName,)) SMaster.delete() con.endTransaction() except KeyError : raise KeyError("Can't delete the setName %s because i can't find it in SNPMaster, maybe there's not set by that name" % setName) #~ printf("can't delete the setName %s because i can't find it in SNPMaster, maybe there's no set by that name" % setName) return False return True
python
def deleteSNPs(setName) : """deletes a set of polymorphisms""" con = conf.db try : SMaster = SNPMaster(setName = setName) con.beginTransaction() SNPType = SMaster.SNPType con.delete(SNPType, 'setName = ?', (setName,)) SMaster.delete() con.endTransaction() except KeyError : raise KeyError("Can't delete the setName %s because i can't find it in SNPMaster, maybe there's not set by that name" % setName) #~ printf("can't delete the setName %s because i can't find it in SNPMaster, maybe there's no set by that name" % setName) return False return True
[ "def", "deleteSNPs", "(", "setName", ")", ":", "con", "=", "conf", ".", "db", "try", ":", "SMaster", "=", "SNPMaster", "(", "setName", "=", "setName", ")", "con", ".", "beginTransaction", "(", ")", "SNPType", "=", "SMaster", ".", "SNPType", "con", ".", "delete", "(", "SNPType", ",", "'setName = ?'", ",", "(", "setName", ",", ")", ")", "SMaster", ".", "delete", "(", ")", "con", ".", "endTransaction", "(", ")", "except", "KeyError", ":", "raise", "KeyError", "(", "\"Can't delete the setName %s because i can't find it in SNPMaster, maybe there's not set by that name\"", "%", "setName", ")", "#~ printf(\"can't delete the setName %s because i can't find it in SNPMaster, maybe there's no set by that name\" % setName)", "return", "False", "return", "True" ]
deletes a set of polymorphisms
[ "deletes", "a", "set", "of", "polymorphisms" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/SNPs.py#L86-L100
tariqdaouda/pyGeno
pyGeno/importation/SNPs.py
_importSNPs_AgnosticSNP
def _importSNPs_AgnosticSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno wil interpret all positions as 0 based" printf('importing SNP set %s for species %s...' % (setName, species)) snpData = CSVFile() snpData.parse(snpsFile, separator = "\t") AgnosticSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar(len(snpData)) pLabel = '' currChrNumber = None for snpEntry in snpData : tmpChr = snpEntry['chromosomeNumber'] if tmpChr != currChrNumber : currChrNumber = tmpChr pLabel = 'Chr %s...' % currChrNumber snp = AgnosticSNP() snp.species = species snp.setName = setName for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : if f != 'species' and f != 'setName' : printf("Warning filetype as no key %s", f) snp.quality = float(snp.quality) snp.start = int(snp.start) snp.end = int(snp.end) snp.save() pBar.update(label = pLabel) pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'AgnosticSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') AgnosticSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
python
def _importSNPs_AgnosticSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno wil interpret all positions as 0 based" printf('importing SNP set %s for species %s...' % (setName, species)) snpData = CSVFile() snpData.parse(snpsFile, separator = "\t") AgnosticSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar(len(snpData)) pLabel = '' currChrNumber = None for snpEntry in snpData : tmpChr = snpEntry['chromosomeNumber'] if tmpChr != currChrNumber : currChrNumber = tmpChr pLabel = 'Chr %s...' % currChrNumber snp = AgnosticSNP() snp.species = species snp.setName = setName for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : if f != 'species' and f != 'setName' : printf("Warning filetype as no key %s", f) snp.quality = float(snp.quality) snp.start = int(snp.start) snp.end = int(snp.end) snp.save() pBar.update(label = pLabel) pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'AgnosticSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') AgnosticSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
[ "def", "_importSNPs_AgnosticSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", ":", "printf", "(", "'importing SNP set %s for species %s...'", "%", "(", "setName", ",", "species", ")", ")", "snpData", "=", "CSVFile", "(", ")", "snpData", ".", "parse", "(", "snpsFile", ",", "separator", "=", "\"\\t\"", ")", "AgnosticSNP", ".", "dropIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "pBar", "=", "ProgressBar", "(", "len", "(", "snpData", ")", ")", "pLabel", "=", "''", "currChrNumber", "=", "None", "for", "snpEntry", "in", "snpData", ":", "tmpChr", "=", "snpEntry", "[", "'chromosomeNumber'", "]", "if", "tmpChr", "!=", "currChrNumber", ":", "currChrNumber", "=", "tmpChr", "pLabel", "=", "'Chr %s...'", "%", "currChrNumber", "snp", "=", "AgnosticSNP", "(", ")", "snp", ".", "species", "=", "species", "snp", ".", "setName", "=", "setName", "for", "f", "in", "snp", ".", "getFields", "(", ")", ":", "try", ":", "setattr", "(", "snp", ",", "f", ",", "snpEntry", "[", "f", "]", ")", "except", "KeyError", ":", "if", "f", "!=", "'species'", "and", "f", "!=", "'setName'", ":", "printf", "(", "\"Warning filetype as no key %s\"", ",", "f", ")", "snp", ".", "quality", "=", "float", "(", "snp", ".", "quality", ")", "snp", ".", "start", "=", "int", "(", "snp", ".", "start", ")", "snp", ".", "end", "=", "int", "(", "snp", ".", "end", ")", "snp", ".", "save", "(", ")", "pBar", ".", "update", "(", "label", "=", "pLabel", ")", "pBar", ".", "close", "(", ")", "snpMaster", "=", "SNPMaster", "(", ")", "snpMaster", ".", "set", "(", "setName", "=", "setName", ",", "SNPType", "=", "'AgnosticSNP'", ",", "species", "=", "species", ")", "snpMaster", ".", "save", "(", ")", "printf", "(", "'saving...'", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "printf", "(", "'creating indexes...'", ")", "AgnosticSNP", ".", "ensureGlobalIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "printf", "(", "'importation of SNP set %s for species %s done.'", "%", "(", "setName", ",", "species", ")", ")", "return", "True" ]
This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno wil interpret all positions as 0 based
[ "This", "function", "will", "also", "create", "an", "index", "on", "start", "-", ">", "chromosomeNumber", "-", ">", "setName", ".", "Warning", ":", "pyGeno", "wil", "interpret", "all", "positions", "as", "0", "based" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/SNPs.py#L102-L148
tariqdaouda/pyGeno
pyGeno/importation/SNPs.py
_importSNPs_CasavaSNP
def _importSNPs_CasavaSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based" printf('importing SNP set %s for species %s...' % (setName, species)) snpData = SNPsTxtFile(snpsFile) CasavaSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar(len(snpData)) pLabel = '' currChrNumber = None for snpEntry in snpData : tmpChr = snpEntry['chromosomeNumber'] if tmpChr != currChrNumber : currChrNumber = tmpChr pLabel = 'Chr %s...' % currChrNumber snp = CasavaSNP() snp.species = species snp.setName = setName for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : if f != 'species' and f != 'setName' : printf("Warning filetype as no key %s", f) snp.start -= 1 snp.end -= 1 snp.save() pBar.update(label = pLabel) pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'CasavaSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') CasavaSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
python
def _importSNPs_CasavaSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based" printf('importing SNP set %s for species %s...' % (setName, species)) snpData = SNPsTxtFile(snpsFile) CasavaSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar(len(snpData)) pLabel = '' currChrNumber = None for snpEntry in snpData : tmpChr = snpEntry['chromosomeNumber'] if tmpChr != currChrNumber : currChrNumber = tmpChr pLabel = 'Chr %s...' % currChrNumber snp = CasavaSNP() snp.species = species snp.setName = setName for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : if f != 'species' and f != 'setName' : printf("Warning filetype as no key %s", f) snp.start -= 1 snp.end -= 1 snp.save() pBar.update(label = pLabel) pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'CasavaSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') CasavaSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
[ "def", "_importSNPs_CasavaSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", ":", "printf", "(", "'importing SNP set %s for species %s...'", "%", "(", "setName", ",", "species", ")", ")", "snpData", "=", "SNPsTxtFile", "(", "snpsFile", ")", "CasavaSNP", ".", "dropIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "pBar", "=", "ProgressBar", "(", "len", "(", "snpData", ")", ")", "pLabel", "=", "''", "currChrNumber", "=", "None", "for", "snpEntry", "in", "snpData", ":", "tmpChr", "=", "snpEntry", "[", "'chromosomeNumber'", "]", "if", "tmpChr", "!=", "currChrNumber", ":", "currChrNumber", "=", "tmpChr", "pLabel", "=", "'Chr %s...'", "%", "currChrNumber", "snp", "=", "CasavaSNP", "(", ")", "snp", ".", "species", "=", "species", "snp", ".", "setName", "=", "setName", "for", "f", "in", "snp", ".", "getFields", "(", ")", ":", "try", ":", "setattr", "(", "snp", ",", "f", ",", "snpEntry", "[", "f", "]", ")", "except", "KeyError", ":", "if", "f", "!=", "'species'", "and", "f", "!=", "'setName'", ":", "printf", "(", "\"Warning filetype as no key %s\"", ",", "f", ")", "snp", ".", "start", "-=", "1", "snp", ".", "end", "-=", "1", "snp", ".", "save", "(", ")", "pBar", ".", "update", "(", "label", "=", "pLabel", ")", "pBar", ".", "close", "(", ")", "snpMaster", "=", "SNPMaster", "(", ")", "snpMaster", ".", "set", "(", "setName", "=", "setName", ",", "SNPType", "=", "'CasavaSNP'", ",", "species", "=", "species", ")", "snpMaster", ".", "save", "(", ")", "printf", "(", "'saving...'", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "printf", "(", "'creating indexes...'", ")", "CasavaSNP", ".", "ensureGlobalIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "printf", "(", "'importation of SNP set %s for species %s done.'", "%", "(", "setName", ",", "species", ")", ")", "return", "True" ]
This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based
[ "This", "function", "will", "also", "create", "an", "index", "on", "start", "-", ">", "chromosomeNumber", "-", ">", "setName", ".", "Warning", ":", "pyGeno", "positions", "are", "0", "based" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/SNPs.py#L150-L195
tariqdaouda/pyGeno
pyGeno/importation/SNPs.py
_importSNPs_dbSNPSNP
def _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based" snpData = VCFFile(snpsFile, gziped = True, stream = True) dbSNPSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar() pLabel = '' for snpEntry in snpData : pBar.update(label = 'Chr %s, %s...' % (snpEntry['#CHROM'], snpEntry['ID'])) snp = dbSNPSNP() for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : pass snp.chromosomeNumber = snpEntry['#CHROM'] snp.species = species snp.setName = setName snp.start = snpEntry['POS']-1 snp.alt = snpEntry['ALT'] snp.ref = snpEntry['REF'] snp.end = snp.start+len(snp.alt) snp.save() pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'dbSNPSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') dbSNPSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
python
def _importSNPs_dbSNPSNP(setName, species, genomeSource, snpsFile) : "This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based" snpData = VCFFile(snpsFile, gziped = True, stream = True) dbSNPSNP.dropIndex(('start', 'chromosomeNumber', 'setName')) conf.db.beginTransaction() pBar = ProgressBar() pLabel = '' for snpEntry in snpData : pBar.update(label = 'Chr %s, %s...' % (snpEntry['#CHROM'], snpEntry['ID'])) snp = dbSNPSNP() for f in snp.getFields() : try : setattr(snp, f, snpEntry[f]) except KeyError : pass snp.chromosomeNumber = snpEntry['#CHROM'] snp.species = species snp.setName = setName snp.start = snpEntry['POS']-1 snp.alt = snpEntry['ALT'] snp.ref = snpEntry['REF'] snp.end = snp.start+len(snp.alt) snp.save() pBar.close() snpMaster = SNPMaster() snpMaster.set(setName = setName, SNPType = 'dbSNPSNP', species = species) snpMaster.save() printf('saving...') conf.db.endTransaction() printf('creating indexes...') dbSNPSNP.ensureGlobalIndex(('start', 'chromosomeNumber', 'setName')) printf('importation of SNP set %s for species %s done.' %(setName, species)) return True
[ "def", "_importSNPs_dbSNPSNP", "(", "setName", ",", "species", ",", "genomeSource", ",", "snpsFile", ")", ":", "snpData", "=", "VCFFile", "(", "snpsFile", ",", "gziped", "=", "True", ",", "stream", "=", "True", ")", "dbSNPSNP", ".", "dropIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "pBar", "=", "ProgressBar", "(", ")", "pLabel", "=", "''", "for", "snpEntry", "in", "snpData", ":", "pBar", ".", "update", "(", "label", "=", "'Chr %s, %s...'", "%", "(", "snpEntry", "[", "'#CHROM'", "]", ",", "snpEntry", "[", "'ID'", "]", ")", ")", "snp", "=", "dbSNPSNP", "(", ")", "for", "f", "in", "snp", ".", "getFields", "(", ")", ":", "try", ":", "setattr", "(", "snp", ",", "f", ",", "snpEntry", "[", "f", "]", ")", "except", "KeyError", ":", "pass", "snp", ".", "chromosomeNumber", "=", "snpEntry", "[", "'#CHROM'", "]", "snp", ".", "species", "=", "species", "snp", ".", "setName", "=", "setName", "snp", ".", "start", "=", "snpEntry", "[", "'POS'", "]", "-", "1", "snp", ".", "alt", "=", "snpEntry", "[", "'ALT'", "]", "snp", ".", "ref", "=", "snpEntry", "[", "'REF'", "]", "snp", ".", "end", "=", "snp", ".", "start", "+", "len", "(", "snp", ".", "alt", ")", "snp", ".", "save", "(", ")", "pBar", ".", "close", "(", ")", "snpMaster", "=", "SNPMaster", "(", ")", "snpMaster", ".", "set", "(", "setName", "=", "setName", ",", "SNPType", "=", "'dbSNPSNP'", ",", "species", "=", "species", ")", "snpMaster", ".", "save", "(", ")", "printf", "(", "'saving...'", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "printf", "(", "'creating indexes...'", ")", "dbSNPSNP", ".", "ensureGlobalIndex", "(", "(", "'start'", ",", "'chromosomeNumber'", ",", "'setName'", ")", ")", "printf", "(", "'importation of SNP set %s for species %s done.'", "%", "(", "setName", ",", "species", ")", ")", "return", "True" ]
This function will also create an index on start->chromosomeNumber->setName. Warning : pyGeno positions are 0 based
[ "This", "function", "will", "also", "create", "an", "index", "on", "start", "-", ">", "chromosomeNumber", "-", ">", "setName", ".", "Warning", ":", "pyGeno", "positions", "are", "0", "based" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/SNPs.py#L197-L234
tariqdaouda/pyGeno
pyGeno/SNP.py
getSNPSetsList
def getSNPSetsList() : """Return the names of all imported snp sets""" import rabaDB.filters as rfilt f = rfilt.RabaQuery(SNPMaster) names = [] for g in f.iterRun() : names.append(g.setName) return names
python
def getSNPSetsList() : """Return the names of all imported snp sets""" import rabaDB.filters as rfilt f = rfilt.RabaQuery(SNPMaster) names = [] for g in f.iterRun() : names.append(g.setName) return names
[ "def", "getSNPSetsList", "(", ")", ":", "import", "rabaDB", ".", "filters", "as", "rfilt", "f", "=", "rfilt", ".", "RabaQuery", "(", "SNPMaster", ")", "names", "=", "[", "]", "for", "g", "in", "f", ".", "iterRun", "(", ")", ":", "names", ".", "append", "(", "g", ".", "setName", ")", "return", "names" ]
Return the names of all imported snp sets
[ "Return", "the", "names", "of", "all", "imported", "snp", "sets" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/SNP.py#L18-L25
tariqdaouda/pyGeno
pyGeno/tools/io.py
printf
def printf(*s) : 'print + sys.stdout.flush()' for e in s[:-1] : print e, print s[-1] sys.stdout.flush()
python
def printf(*s) : 'print + sys.stdout.flush()' for e in s[:-1] : print e, print s[-1] sys.stdout.flush()
[ "def", "printf", "(", "*", "s", ")", ":", "for", "e", "in", "s", "[", ":", "-", "1", "]", ":", "print", "e", ",", "print", "s", "[", "-", "1", "]", "sys", ".", "stdout", ".", "flush", "(", ")" ]
print + sys.stdout.flush()
[ "print", "+", "sys", ".", "stdout", ".", "flush", "()" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/io.py#L3-L9
tariqdaouda/pyGeno
pyGeno/tools/Stats.py
kullback_leibler
def kullback_leibler(p, q) : """Discrete Kullback-Leibler divergence D(P||Q)""" p = np.asarray(p, dtype=np.float) q = np.asarray(q, dtype=np.float) if p.shape != q.shape : raise ValueError("p and q must be of the same dimensions") return np.sum(np.where(p > 0, np.log(p / q) * p, 0))
python
def kullback_leibler(p, q) : """Discrete Kullback-Leibler divergence D(P||Q)""" p = np.asarray(p, dtype=np.float) q = np.asarray(q, dtype=np.float) if p.shape != q.shape : raise ValueError("p and q must be of the same dimensions") return np.sum(np.where(p > 0, np.log(p / q) * p, 0))
[ "def", "kullback_leibler", "(", "p", ",", "q", ")", ":", "p", "=", "np", ".", "asarray", "(", "p", ",", "dtype", "=", "np", ".", "float", ")", "q", "=", "np", ".", "asarray", "(", "q", ",", "dtype", "=", "np", ".", "float", ")", "if", "p", ".", "shape", "!=", "q", ".", "shape", ":", "raise", "ValueError", "(", "\"p and q must be of the same dimensions\"", ")", "return", "np", ".", "sum", "(", "np", ".", "where", "(", "p", ">", "0", ",", "np", ".", "log", "(", "p", "/", "q", ")", "*", "p", ",", "0", ")", ")" ]
Discrete Kullback-Leibler divergence D(P||Q)
[ "Discrete", "Kullback", "-", "Leibler", "divergence", "D", "(", "P||Q", ")" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/Stats.py#L3-L11
tariqdaouda/pyGeno
pyGeno/tools/parsers/FastaTools.py
FastaFile.parseFile
def parseFile(self, fil) : """Opens a file and parses it""" f = open(fil) self.parseStr(f.read()) f.close()
python
def parseFile(self, fil) : """Opens a file and parses it""" f = open(fil) self.parseStr(f.read()) f.close()
[ "def", "parseFile", "(", "self", ",", "fil", ")", ":", "f", "=", "open", "(", "fil", ")", "self", ".", "parseStr", "(", "f", ".", "read", "(", ")", ")", "f", ".", "close", "(", ")" ]
Opens a file and parses it
[ "Opens", "a", "file", "and", "parses", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/FastaTools.py#L32-L36
tariqdaouda/pyGeno
pyGeno/tools/parsers/FastaTools.py
FastaFile.add
def add(self, header, data) : """appends a new entry to the file""" if header[0] != '>' : self.data.append(('>'+header, data)) else : self.data.append((header, data))
python
def add(self, header, data) : """appends a new entry to the file""" if header[0] != '>' : self.data.append(('>'+header, data)) else : self.data.append((header, data))
[ "def", "add", "(", "self", ",", "header", ",", "data", ")", ":", "if", "header", "[", "0", "]", "!=", "'>'", ":", "self", ".", "data", ".", "append", "(", "(", "'>'", "+", "header", ",", "data", ")", ")", "else", ":", "self", ".", "data", ".", "append", "(", "(", "header", ",", "data", ")", ")" ]
appends a new entry to the file
[ "appends", "a", "new", "entry", "to", "the", "file" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/FastaTools.py#L52-L57
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
findAll
def findAll(haystack, needle) : """returns a list of all occurances of needle in haystack""" h = haystack res = [] f = haystack.find(needle) offset = 0 while (f >= 0) : #print h, needle, f, offset res.append(f+offset) offset += f+len(needle) h = h[f+len(needle):] f = h.find(needle) return res
python
def findAll(haystack, needle) : """returns a list of all occurances of needle in haystack""" h = haystack res = [] f = haystack.find(needle) offset = 0 while (f >= 0) : #print h, needle, f, offset res.append(f+offset) offset += f+len(needle) h = h[f+len(needle):] f = h.find(needle) return res
[ "def", "findAll", "(", "haystack", ",", "needle", ")", ":", "h", "=", "haystack", "res", "=", "[", "]", "f", "=", "haystack", ".", "find", "(", "needle", ")", "offset", "=", "0", "while", "(", "f", ">=", "0", ")", ":", "#print h, needle, f, offset", "res", ".", "append", "(", "f", "+", "offset", ")", "offset", "+=", "f", "+", "len", "(", "needle", ")", "h", "=", "h", "[", "f", "+", "len", "(", "needle", ")", ":", "]", "f", "=", "h", ".", "find", "(", "needle", ")", "return", "res" ]
returns a list of all occurances of needle in haystack
[ "returns", "a", "list", "of", "all", "occurances", "of", "needle", "in", "haystack" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L136-L150
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
complementTab
def complementTab(seq=[]): """returns a list of complementary sequence without inversing it""" complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'R': 'Y', 'Y': 'R', 'M': 'K', 'K': 'M', 'W': 'W', 'S': 'S', 'B': 'V', 'D': 'H', 'H': 'D', 'V': 'B', 'N': 'N', 'a': 't', 'c': 'g', 'g': 'c', 't': 'a', 'r': 'y', 'y': 'r', 'm': 'k', 'k': 'm', 'w': 'w', 's': 's', 'b': 'v', 'd': 'h', 'h': 'd', 'v': 'b', 'n': 'n'} seq_tmp = [] for bps in seq: if len(bps) == 0: #Need manage '' for deletion seq_tmp.append('') elif len(bps) == 1: seq_tmp.append(complement[bps]) else: #Need manage 'ACT' for insertion #The insertion need to be reverse complement (like seq) seq_tmp.append(reverseComplement(bps)) #Doesn't work in the second for when bps=='' #seq = [complement[bp] if bp != '' else '' for bps in seq for bp in bps] return seq_tmp
python
def complementTab(seq=[]): """returns a list of complementary sequence without inversing it""" complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'R': 'Y', 'Y': 'R', 'M': 'K', 'K': 'M', 'W': 'W', 'S': 'S', 'B': 'V', 'D': 'H', 'H': 'D', 'V': 'B', 'N': 'N', 'a': 't', 'c': 'g', 'g': 'c', 't': 'a', 'r': 'y', 'y': 'r', 'm': 'k', 'k': 'm', 'w': 'w', 's': 's', 'b': 'v', 'd': 'h', 'h': 'd', 'v': 'b', 'n': 'n'} seq_tmp = [] for bps in seq: if len(bps) == 0: #Need manage '' for deletion seq_tmp.append('') elif len(bps) == 1: seq_tmp.append(complement[bps]) else: #Need manage 'ACT' for insertion #The insertion need to be reverse complement (like seq) seq_tmp.append(reverseComplement(bps)) #Doesn't work in the second for when bps=='' #seq = [complement[bp] if bp != '' else '' for bps in seq for bp in bps] return seq_tmp
[ "def", "complementTab", "(", "seq", "=", "[", "]", ")", ":", "complement", "=", "{", "'A'", ":", "'T'", ",", "'C'", ":", "'G'", ",", "'G'", ":", "'C'", ",", "'T'", ":", "'A'", ",", "'R'", ":", "'Y'", ",", "'Y'", ":", "'R'", ",", "'M'", ":", "'K'", ",", "'K'", ":", "'M'", ",", "'W'", ":", "'W'", ",", "'S'", ":", "'S'", ",", "'B'", ":", "'V'", ",", "'D'", ":", "'H'", ",", "'H'", ":", "'D'", ",", "'V'", ":", "'B'", ",", "'N'", ":", "'N'", ",", "'a'", ":", "'t'", ",", "'c'", ":", "'g'", ",", "'g'", ":", "'c'", ",", "'t'", ":", "'a'", ",", "'r'", ":", "'y'", ",", "'y'", ":", "'r'", ",", "'m'", ":", "'k'", ",", "'k'", ":", "'m'", ",", "'w'", ":", "'w'", ",", "'s'", ":", "'s'", ",", "'b'", ":", "'v'", ",", "'d'", ":", "'h'", ",", "'h'", ":", "'d'", ",", "'v'", ":", "'b'", ",", "'n'", ":", "'n'", "}", "seq_tmp", "=", "[", "]", "for", "bps", "in", "seq", ":", "if", "len", "(", "bps", ")", "==", "0", ":", "#Need manage '' for deletion", "seq_tmp", ".", "append", "(", "''", ")", "elif", "len", "(", "bps", ")", "==", "1", ":", "seq_tmp", ".", "append", "(", "complement", "[", "bps", "]", ")", "else", ":", "#Need manage 'ACT' for insertion", "#The insertion need to be reverse complement (like seq)", "seq_tmp", ".", "append", "(", "reverseComplement", "(", "bps", ")", ")", "#Doesn't work in the second for when bps==''", "#seq = [complement[bp] if bp != '' else '' for bps in seq for bp in bps]", "return", "seq_tmp" ]
returns a list of complementary sequence without inversing it
[ "returns", "a", "list", "of", "complementary", "sequence", "without", "inversing", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L153-L174
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
translateDNA_6Frames
def translateDNA_6Frames(sequence) : """returns 6 translation of sequence. One for each reading frame""" trans = ( translateDNA(sequence, 'f1'), translateDNA(sequence, 'f2'), translateDNA(sequence, 'f3'), translateDNA(sequence, 'r1'), translateDNA(sequence, 'r2'), translateDNA(sequence, 'r3'), ) return trans
python
def translateDNA_6Frames(sequence) : """returns 6 translation of sequence. One for each reading frame""" trans = ( translateDNA(sequence, 'f1'), translateDNA(sequence, 'f2'), translateDNA(sequence, 'f3'), translateDNA(sequence, 'r1'), translateDNA(sequence, 'r2'), translateDNA(sequence, 'r3'), ) return trans
[ "def", "translateDNA_6Frames", "(", "sequence", ")", ":", "trans", "=", "(", "translateDNA", "(", "sequence", ",", "'f1'", ")", ",", "translateDNA", "(", "sequence", ",", "'f2'", ")", ",", "translateDNA", "(", "sequence", ",", "'f3'", ")", ",", "translateDNA", "(", "sequence", ",", "'r1'", ")", ",", "translateDNA", "(", "sequence", ",", "'r2'", ")", ",", "translateDNA", "(", "sequence", ",", "'r3'", ")", ",", ")", "return", "trans" ]
returns 6 translation of sequence. One for each reading frame
[ "returns", "6", "translation", "of", "sequence", ".", "One", "for", "each", "reading", "frame" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L196-L208
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
translateDNA
def translateDNA(sequence, frame = 'f1', translTable_id='default') : """Translates DNA code, frame : fwd1, fwd2, fwd3, rev1, rev2, rev3""" protein = "" if frame == 'f1' : dna = sequence elif frame == 'f2': dna = sequence[1:] elif frame == 'f3' : dna = sequence[2:] elif frame == 'r1' : dna = reverseComplement(sequence) elif frame == 'r2' : dna = reverseComplement(sequence) dna = dna[1:] elif frame == 'r3' : dna = reverseComplement(sequence) dna = dna[2:] else : raise ValueError('unknown reading frame: %s, should be one of the following: fwd1, fwd2, fwd3, rev1, rev2, rev3' % frame) for i in range(0, len(dna), 3) : codon = dna[i:i+3] # Check if variant messed with selenocysteine codon if '!' in codon and codon != '!GA': codon = codon.replace('!', 'T') if (len(codon) == 3) : try : # MC protein += translTable[translTable_id][codon] except KeyError : combinaisons = polymorphicCodonCombinaisons(list(codon)) translations = set() for ci in range(len(combinaisons)): translations.add(translTable[translTable_id][combinaisons[ci]]) protein += '/'.join(translations) return protein
python
def translateDNA(sequence, frame = 'f1', translTable_id='default') : """Translates DNA code, frame : fwd1, fwd2, fwd3, rev1, rev2, rev3""" protein = "" if frame == 'f1' : dna = sequence elif frame == 'f2': dna = sequence[1:] elif frame == 'f3' : dna = sequence[2:] elif frame == 'r1' : dna = reverseComplement(sequence) elif frame == 'r2' : dna = reverseComplement(sequence) dna = dna[1:] elif frame == 'r3' : dna = reverseComplement(sequence) dna = dna[2:] else : raise ValueError('unknown reading frame: %s, should be one of the following: fwd1, fwd2, fwd3, rev1, rev2, rev3' % frame) for i in range(0, len(dna), 3) : codon = dna[i:i+3] # Check if variant messed with selenocysteine codon if '!' in codon and codon != '!GA': codon = codon.replace('!', 'T') if (len(codon) == 3) : try : # MC protein += translTable[translTable_id][codon] except KeyError : combinaisons = polymorphicCodonCombinaisons(list(codon)) translations = set() for ci in range(len(combinaisons)): translations.add(translTable[translTable_id][combinaisons[ci]]) protein += '/'.join(translations) return protein
[ "def", "translateDNA", "(", "sequence", ",", "frame", "=", "'f1'", ",", "translTable_id", "=", "'default'", ")", ":", "protein", "=", "\"\"", "if", "frame", "==", "'f1'", ":", "dna", "=", "sequence", "elif", "frame", "==", "'f2'", ":", "dna", "=", "sequence", "[", "1", ":", "]", "elif", "frame", "==", "'f3'", ":", "dna", "=", "sequence", "[", "2", ":", "]", "elif", "frame", "==", "'r1'", ":", "dna", "=", "reverseComplement", "(", "sequence", ")", "elif", "frame", "==", "'r2'", ":", "dna", "=", "reverseComplement", "(", "sequence", ")", "dna", "=", "dna", "[", "1", ":", "]", "elif", "frame", "==", "'r3'", ":", "dna", "=", "reverseComplement", "(", "sequence", ")", "dna", "=", "dna", "[", "2", ":", "]", "else", ":", "raise", "ValueError", "(", "'unknown reading frame: %s, should be one of the following: fwd1, fwd2, fwd3, rev1, rev2, rev3'", "%", "frame", ")", "for", "i", "in", "range", "(", "0", ",", "len", "(", "dna", ")", ",", "3", ")", ":", "codon", "=", "dna", "[", "i", ":", "i", "+", "3", "]", "# Check if variant messed with selenocysteine codon", "if", "'!'", "in", "codon", "and", "codon", "!=", "'!GA'", ":", "codon", "=", "codon", ".", "replace", "(", "'!'", ",", "'T'", ")", "if", "(", "len", "(", "codon", ")", "==", "3", ")", ":", "try", ":", "# MC", "protein", "+=", "translTable", "[", "translTable_id", "]", "[", "codon", "]", "except", "KeyError", ":", "combinaisons", "=", "polymorphicCodonCombinaisons", "(", "list", "(", "codon", ")", ")", "translations", "=", "set", "(", ")", "for", "ci", "in", "range", "(", "len", "(", "combinaisons", ")", ")", ":", "translations", ".", "add", "(", "translTable", "[", "translTable_id", "]", "[", "combinaisons", "[", "ci", "]", "]", ")", "protein", "+=", "'/'", ".", "join", "(", "translations", ")", "return", "protein" ]
Translates DNA code, frame : fwd1, fwd2, fwd3, rev1, rev2, rev3
[ "Translates", "DNA", "code", "frame", ":", "fwd1", "fwd2", "fwd3", "rev1", "rev2", "rev3" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L210-L250
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
getSequenceCombinaisons
def getSequenceCombinaisons(polymorphipolymorphicDnaSeqSeq, pos = 0) : """Takes a dna sequence with polymorphismes and returns all the possible sequences that it can yield""" if type(polymorphipolymorphicDnaSeqSeq) is not types.ListType : seq = list(polymorphipolymorphicDnaSeqSeq) else : seq = polymorphipolymorphicDnaSeqSeq if pos >= len(seq) : return [''.join(seq)] variants = [] if seq[pos] in polymorphicNucleotides : chars = decodePolymorphicNucleotide(seq[pos]) else : chars = seq[pos]#.split('/') for c in chars : rseq = copy.copy(seq) rseq[pos] = c variants.extend(getSequenceCombinaisons(rseq, pos + 1)) return variants
python
def getSequenceCombinaisons(polymorphipolymorphicDnaSeqSeq, pos = 0) : """Takes a dna sequence with polymorphismes and returns all the possible sequences that it can yield""" if type(polymorphipolymorphicDnaSeqSeq) is not types.ListType : seq = list(polymorphipolymorphicDnaSeqSeq) else : seq = polymorphipolymorphicDnaSeqSeq if pos >= len(seq) : return [''.join(seq)] variants = [] if seq[pos] in polymorphicNucleotides : chars = decodePolymorphicNucleotide(seq[pos]) else : chars = seq[pos]#.split('/') for c in chars : rseq = copy.copy(seq) rseq[pos] = c variants.extend(getSequenceCombinaisons(rseq, pos + 1)) return variants
[ "def", "getSequenceCombinaisons", "(", "polymorphipolymorphicDnaSeqSeq", ",", "pos", "=", "0", ")", ":", "if", "type", "(", "polymorphipolymorphicDnaSeqSeq", ")", "is", "not", "types", ".", "ListType", ":", "seq", "=", "list", "(", "polymorphipolymorphicDnaSeqSeq", ")", "else", ":", "seq", "=", "polymorphipolymorphicDnaSeqSeq", "if", "pos", ">=", "len", "(", "seq", ")", ":", "return", "[", "''", ".", "join", "(", "seq", ")", "]", "variants", "=", "[", "]", "if", "seq", "[", "pos", "]", "in", "polymorphicNucleotides", ":", "chars", "=", "decodePolymorphicNucleotide", "(", "seq", "[", "pos", "]", ")", "else", ":", "chars", "=", "seq", "[", "pos", "]", "#.split('/')", "for", "c", "in", "chars", ":", "rseq", "=", "copy", ".", "copy", "(", "seq", ")", "rseq", "[", "pos", "]", "=", "c", "variants", ".", "extend", "(", "getSequenceCombinaisons", "(", "rseq", ",", "pos", "+", "1", ")", ")", "return", "variants" ]
Takes a dna sequence with polymorphismes and returns all the possible sequences that it can yield
[ "Takes", "a", "dna", "sequence", "with", "polymorphismes", "and", "returns", "all", "the", "possible", "sequences", "that", "it", "can", "yield" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L252-L274
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
encodePolymorphicNucleotide
def encodePolymorphicNucleotide(polySeq) : """returns a single character encoding all nucletides of polySeq in a single character. PolySeq must have one of the following forms: ['A', 'T', 'G'], 'ATG', 'A/T/G'""" if type(polySeq) is types.StringType : if polySeq.find("/") < 0 : sseq = list(polySeq) else : sseq = polySeq.split('/') else : sseq = polySeq seq = [] for n in sseq : try : for n2 in polymorphicNucleotides[n] : seq.append(n2) except KeyError : seq.append(n) seq = set(seq) if len(seq) == 4: return 'N' elif len(seq) == 3 : if 'T' not in seq : return 'V' elif 'G' not in seq : return 'H' elif 'C' not in seq : return 'D' elif 'A' not in seq : return 'B' elif len(seq) == 2 : if 'A' in seq and 'G' in seq : return 'R' elif 'C' in seq and 'T' in seq : return 'Y' elif 'A' in seq and 'C' in seq : return 'M' elif 'T' in seq and 'G' in seq : return 'K' elif 'A' in seq and 'T' in seq : return 'W' elif 'C' in seq and 'G' in seq : return 'S' elif polySeq[0] in nucleotides : return polySeq[0] else : raise UnknownNucleotide(polySeq)
python
def encodePolymorphicNucleotide(polySeq) : """returns a single character encoding all nucletides of polySeq in a single character. PolySeq must have one of the following forms: ['A', 'T', 'G'], 'ATG', 'A/T/G'""" if type(polySeq) is types.StringType : if polySeq.find("/") < 0 : sseq = list(polySeq) else : sseq = polySeq.split('/') else : sseq = polySeq seq = [] for n in sseq : try : for n2 in polymorphicNucleotides[n] : seq.append(n2) except KeyError : seq.append(n) seq = set(seq) if len(seq) == 4: return 'N' elif len(seq) == 3 : if 'T' not in seq : return 'V' elif 'G' not in seq : return 'H' elif 'C' not in seq : return 'D' elif 'A' not in seq : return 'B' elif len(seq) == 2 : if 'A' in seq and 'G' in seq : return 'R' elif 'C' in seq and 'T' in seq : return 'Y' elif 'A' in seq and 'C' in seq : return 'M' elif 'T' in seq and 'G' in seq : return 'K' elif 'A' in seq and 'T' in seq : return 'W' elif 'C' in seq and 'G' in seq : return 'S' elif polySeq[0] in nucleotides : return polySeq[0] else : raise UnknownNucleotide(polySeq)
[ "def", "encodePolymorphicNucleotide", "(", "polySeq", ")", ":", "if", "type", "(", "polySeq", ")", "is", "types", ".", "StringType", ":", "if", "polySeq", ".", "find", "(", "\"/\"", ")", "<", "0", ":", "sseq", "=", "list", "(", "polySeq", ")", "else", ":", "sseq", "=", "polySeq", ".", "split", "(", "'/'", ")", "else", ":", "sseq", "=", "polySeq", "seq", "=", "[", "]", "for", "n", "in", "sseq", ":", "try", ":", "for", "n2", "in", "polymorphicNucleotides", "[", "n", "]", ":", "seq", ".", "append", "(", "n2", ")", "except", "KeyError", ":", "seq", ".", "append", "(", "n", ")", "seq", "=", "set", "(", "seq", ")", "if", "len", "(", "seq", ")", "==", "4", ":", "return", "'N'", "elif", "len", "(", "seq", ")", "==", "3", ":", "if", "'T'", "not", "in", "seq", ":", "return", "'V'", "elif", "'G'", "not", "in", "seq", ":", "return", "'H'", "elif", "'C'", "not", "in", "seq", ":", "return", "'D'", "elif", "'A'", "not", "in", "seq", ":", "return", "'B'", "elif", "len", "(", "seq", ")", "==", "2", ":", "if", "'A'", "in", "seq", "and", "'G'", "in", "seq", ":", "return", "'R'", "elif", "'C'", "in", "seq", "and", "'T'", "in", "seq", ":", "return", "'Y'", "elif", "'A'", "in", "seq", "and", "'C'", "in", "seq", ":", "return", "'M'", "elif", "'T'", "in", "seq", "and", "'G'", "in", "seq", ":", "return", "'K'", "elif", "'A'", "in", "seq", "and", "'T'", "in", "seq", ":", "return", "'W'", "elif", "'C'", "in", "seq", "and", "'G'", "in", "seq", ":", "return", "'S'", "elif", "polySeq", "[", "0", "]", "in", "nucleotides", ":", "return", "polySeq", "[", "0", "]", "else", ":", "raise", "UnknownNucleotide", "(", "polySeq", ")" ]
returns a single character encoding all nucletides of polySeq in a single character. PolySeq must have one of the following forms: ['A', 'T', 'G'], 'ATG', 'A/T/G
[ "returns", "a", "single", "character", "encoding", "all", "nucletides", "of", "polySeq", "in", "a", "single", "character", ".", "PolySeq", "must", "have", "one", "of", "the", "following", "forms", ":", "[", "A", "T", "G", "]", "ATG", "A", "/", "T", "/", "G" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L280-L331
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
decodePolymorphicNucleotide
def decodePolymorphicNucleotide(nuc) : """the opposite of encodePolymorphicNucleotide, from 'R' to ['A', 'G']""" if nuc in polymorphicNucleotides : return polymorphicNucleotides[nuc] if nuc in nucleotides : return nuc raise ValueError('nuc: %s, is not a valid nucleotide' % nuc)
python
def decodePolymorphicNucleotide(nuc) : """the opposite of encodePolymorphicNucleotide, from 'R' to ['A', 'G']""" if nuc in polymorphicNucleotides : return polymorphicNucleotides[nuc] if nuc in nucleotides : return nuc raise ValueError('nuc: %s, is not a valid nucleotide' % nuc)
[ "def", "decodePolymorphicNucleotide", "(", "nuc", ")", ":", "if", "nuc", "in", "polymorphicNucleotides", ":", "return", "polymorphicNucleotides", "[", "nuc", "]", "if", "nuc", "in", "nucleotides", ":", "return", "nuc", "raise", "ValueError", "(", "'nuc: %s, is not a valid nucleotide'", "%", "nuc", ")" ]
the opposite of encodePolymorphicNucleotide, from 'R' to ['A', 'G']
[ "the", "opposite", "of", "encodePolymorphicNucleotide", "from", "R", "to", "[", "A", "G", "]" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L333-L341
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
getNucleotideCodon
def getNucleotideCodon(sequence, x1) : """Returns the entire codon of the nucleotide at pos x1 in sequence, and the position of that nocleotide in the codon in a tuple""" if x1 < 0 or x1 >= len(sequence) : return None p = x1%3 if p == 0 : return (sequence[x1: x1+3], 0) elif p ==1 : return (sequence[x1-1: x1+2], 1) elif p == 2 : return (sequence[x1-2: x1+1], 2)
python
def getNucleotideCodon(sequence, x1) : """Returns the entire codon of the nucleotide at pos x1 in sequence, and the position of that nocleotide in the codon in a tuple""" if x1 < 0 or x1 >= len(sequence) : return None p = x1%3 if p == 0 : return (sequence[x1: x1+3], 0) elif p ==1 : return (sequence[x1-1: x1+2], 1) elif p == 2 : return (sequence[x1-2: x1+1], 2)
[ "def", "getNucleotideCodon", "(", "sequence", ",", "x1", ")", ":", "if", "x1", "<", "0", "or", "x1", ">=", "len", "(", "sequence", ")", ":", "return", "None", "p", "=", "x1", "%", "3", "if", "p", "==", "0", ":", "return", "(", "sequence", "[", "x1", ":", "x1", "+", "3", "]", ",", "0", ")", "elif", "p", "==", "1", ":", "return", "(", "sequence", "[", "x1", "-", "1", ":", "x1", "+", "2", "]", ",", "1", ")", "elif", "p", "==", "2", ":", "return", "(", "sequence", "[", "x1", "-", "2", ":", "x1", "+", "1", "]", ",", "2", ")" ]
Returns the entire codon of the nucleotide at pos x1 in sequence, and the position of that nocleotide in the codon in a tuple
[ "Returns", "the", "entire", "codon", "of", "the", "nucleotide", "at", "pos", "x1", "in", "sequence", "and", "the", "position", "of", "that", "nocleotide", "in", "the", "codon", "in", "a", "tuple" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L348-L361
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
showDifferences
def showDifferences(seq1, seq2) : """Returns a string highligthing differences between seq1 and seq2: * Matches by '-' * Differences : 'A|T' * Exceeded length : '#' """ ret = [] for i in range(max(len(seq1), len(seq2))) : if i >= len(seq1) : c1 = '#' else : c1 = seq1[i] if i >= len(seq2) : c2 = '#' else : c2 = seq2[i] if c1 != c2 : ret.append('%s|%s' % (c1, c2)) else : ret.append('-') return ''.join(ret)
python
def showDifferences(seq1, seq2) : """Returns a string highligthing differences between seq1 and seq2: * Matches by '-' * Differences : 'A|T' * Exceeded length : '#' """ ret = [] for i in range(max(len(seq1), len(seq2))) : if i >= len(seq1) : c1 = '#' else : c1 = seq1[i] if i >= len(seq2) : c2 = '#' else : c2 = seq2[i] if c1 != c2 : ret.append('%s|%s' % (c1, c2)) else : ret.append('-') return ''.join(ret)
[ "def", "showDifferences", "(", "seq1", ",", "seq2", ")", ":", "ret", "=", "[", "]", "for", "i", "in", "range", "(", "max", "(", "len", "(", "seq1", ")", ",", "len", "(", "seq2", ")", ")", ")", ":", "if", "i", ">=", "len", "(", "seq1", ")", ":", "c1", "=", "'#'", "else", ":", "c1", "=", "seq1", "[", "i", "]", "if", "i", ">=", "len", "(", "seq2", ")", ":", "c2", "=", "'#'", "else", ":", "c2", "=", "seq2", "[", "i", "]", "if", "c1", "!=", "c2", ":", "ret", ".", "append", "(", "'%s|%s'", "%", "(", "c1", ",", "c2", ")", ")", "else", ":", "ret", ".", "append", "(", "'-'", ")", "return", "''", ".", "join", "(", "ret", ")" ]
Returns a string highligthing differences between seq1 and seq2: * Matches by '-' * Differences : 'A|T' * Exceeded length : '#'
[ "Returns", "a", "string", "highligthing", "differences", "between", "seq1", "and", "seq2", ":", "*", "Matches", "by", "-", "*", "Differences", ":", "A|T", "*", "Exceeded", "length", ":", "#" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L363-L390
tariqdaouda/pyGeno
pyGeno/tools/UsefulFunctions.py
highlightSubsequence
def highlightSubsequence(sequence, x1, x2, start=' [', stop = '] ') : """returns a sequence where the subsequence in [x1, x2[ is placed in bewteen 'start' and 'stop'""" seq = list(sequence) print x1, x2-1, len(seq) seq[x1] = start + seq[x1] seq[x2-1] = seq[x2-1] + stop return ''.join(seq)
python
def highlightSubsequence(sequence, x1, x2, start=' [', stop = '] ') : """returns a sequence where the subsequence in [x1, x2[ is placed in bewteen 'start' and 'stop'""" seq = list(sequence) print x1, x2-1, len(seq) seq[x1] = start + seq[x1] seq[x2-1] = seq[x2-1] + stop return ''.join(seq)
[ "def", "highlightSubsequence", "(", "sequence", ",", "x1", ",", "x2", ",", "start", "=", "' ['", ",", "stop", "=", "'] '", ")", ":", "seq", "=", "list", "(", "sequence", ")", "print", "x1", ",", "x2", "-", "1", ",", "len", "(", "seq", ")", "seq", "[", "x1", "]", "=", "start", "+", "seq", "[", "x1", "]", "seq", "[", "x2", "-", "1", "]", "=", "seq", "[", "x2", "-", "1", "]", "+", "stop", "return", "''", ".", "join", "(", "seq", ")" ]
returns a sequence where the subsequence in [x1, x2[ is placed in bewteen 'start' and 'stop
[ "returns", "a", "sequence", "where", "the", "subsequence", "in", "[", "x1", "x2", "[", "is", "placed", "in", "bewteen", "start", "and", "stop" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/UsefulFunctions.py#L392-L400
tariqdaouda/pyGeno
pyGeno/importation/Genomes.py
backUpDB
def backUpDB() : """backup the current database version. automatically called by importGenome(). Returns the filename of the backup""" st = time.ctime().replace(' ', '_') fn = conf.pyGeno_RABA_DBFILE.replace('.db', '_%s-bck.db' % st) shutil.copy2(conf.pyGeno_RABA_DBFILE, fn) return fn
python
def backUpDB() : """backup the current database version. automatically called by importGenome(). Returns the filename of the backup""" st = time.ctime().replace(' ', '_') fn = conf.pyGeno_RABA_DBFILE.replace('.db', '_%s-bck.db' % st) shutil.copy2(conf.pyGeno_RABA_DBFILE, fn) return fn
[ "def", "backUpDB", "(", ")", ":", "st", "=", "time", ".", "ctime", "(", ")", ".", "replace", "(", "' '", ",", "'_'", ")", "fn", "=", "conf", ".", "pyGeno_RABA_DBFILE", ".", "replace", "(", "'.db'", ",", "'_%s-bck.db'", "%", "st", ")", "shutil", ".", "copy2", "(", "conf", ".", "pyGeno_RABA_DBFILE", ",", "fn", ")", "return", "fn" ]
backup the current database version. automatically called by importGenome(). Returns the filename of the backup
[ "backup", "the", "current", "database", "version", ".", "automatically", "called", "by", "importGenome", "()", ".", "Returns", "the", "filename", "of", "the", "backup" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/Genomes.py#L22-L28
tariqdaouda/pyGeno
pyGeno/importation/Genomes.py
deleteGenome
def deleteGenome(species, name) : """Removes a genome from the database""" printf('deleting genome (%s, %s)...' % (species, name)) conf.db.beginTransaction() objs = [] allGood = True try : genome = Genome_Raba(name = name, species = species.lower()) objs.append(genome) pBar = ProgressBar(label = 'preparing') for typ in (Chromosome_Raba, Gene_Raba, Transcript_Raba, Exon_Raba, Protein_Raba) : pBar.update() f = RabaQuery(typ, namespace = genome._raba_namespace) f.addFilter({'genome' : genome}) for e in f.iterRun() : objs.append(e) pBar.close() pBar = ProgressBar(nbEpochs = len(objs), label = 'deleting objects') for e in objs : pBar.update() e.delete() pBar.close() except KeyError as e : #~ printf("\tWARNING, couldn't remove genome form db, maybe it's not there: ", e) raise KeyError("\tWARNING, couldn't remove genome form db, maybe it's not there: ", e) allGood = False printf('\tdeleting folder') try : shutil.rmtree(conf.getGenomeSequencePath(species, name)) except OSError as e: #~ printf('\tWARNING, Unable to delete folder: ', e) OSError('\tWARNING, Unable to delete folder: ', e) allGood = False conf.db.endTransaction() return allGood
python
def deleteGenome(species, name) : """Removes a genome from the database""" printf('deleting genome (%s, %s)...' % (species, name)) conf.db.beginTransaction() objs = [] allGood = True try : genome = Genome_Raba(name = name, species = species.lower()) objs.append(genome) pBar = ProgressBar(label = 'preparing') for typ in (Chromosome_Raba, Gene_Raba, Transcript_Raba, Exon_Raba, Protein_Raba) : pBar.update() f = RabaQuery(typ, namespace = genome._raba_namespace) f.addFilter({'genome' : genome}) for e in f.iterRun() : objs.append(e) pBar.close() pBar = ProgressBar(nbEpochs = len(objs), label = 'deleting objects') for e in objs : pBar.update() e.delete() pBar.close() except KeyError as e : #~ printf("\tWARNING, couldn't remove genome form db, maybe it's not there: ", e) raise KeyError("\tWARNING, couldn't remove genome form db, maybe it's not there: ", e) allGood = False printf('\tdeleting folder') try : shutil.rmtree(conf.getGenomeSequencePath(species, name)) except OSError as e: #~ printf('\tWARNING, Unable to delete folder: ', e) OSError('\tWARNING, Unable to delete folder: ', e) allGood = False conf.db.endTransaction() return allGood
[ "def", "deleteGenome", "(", "species", ",", "name", ")", ":", "printf", "(", "'deleting genome (%s, %s)...'", "%", "(", "species", ",", "name", ")", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "objs", "=", "[", "]", "allGood", "=", "True", "try", ":", "genome", "=", "Genome_Raba", "(", "name", "=", "name", ",", "species", "=", "species", ".", "lower", "(", ")", ")", "objs", ".", "append", "(", "genome", ")", "pBar", "=", "ProgressBar", "(", "label", "=", "'preparing'", ")", "for", "typ", "in", "(", "Chromosome_Raba", ",", "Gene_Raba", ",", "Transcript_Raba", ",", "Exon_Raba", ",", "Protein_Raba", ")", ":", "pBar", ".", "update", "(", ")", "f", "=", "RabaQuery", "(", "typ", ",", "namespace", "=", "genome", ".", "_raba_namespace", ")", "f", ".", "addFilter", "(", "{", "'genome'", ":", "genome", "}", ")", "for", "e", "in", "f", ".", "iterRun", "(", ")", ":", "objs", ".", "append", "(", "e", ")", "pBar", ".", "close", "(", ")", "pBar", "=", "ProgressBar", "(", "nbEpochs", "=", "len", "(", "objs", ")", ",", "label", "=", "'deleting objects'", ")", "for", "e", "in", "objs", ":", "pBar", ".", "update", "(", ")", "e", ".", "delete", "(", ")", "pBar", ".", "close", "(", ")", "except", "KeyError", "as", "e", ":", "#~ printf(\"\\tWARNING, couldn't remove genome form db, maybe it's not there: \", e)", "raise", "KeyError", "(", "\"\\tWARNING, couldn't remove genome form db, maybe it's not there: \"", ",", "e", ")", "allGood", "=", "False", "printf", "(", "'\\tdeleting folder'", ")", "try", ":", "shutil", ".", "rmtree", "(", "conf", ".", "getGenomeSequencePath", "(", "species", ",", "name", ")", ")", "except", "OSError", "as", "e", ":", "#~ printf('\\tWARNING, Unable to delete folder: ', e)", "OSError", "(", "'\\tWARNING, Unable to delete folder: '", ",", "e", ")", "allGood", "=", "False", "conf", ".", "db", ".", "endTransaction", "(", ")", "return", "allGood" ]
Removes a genome from the database
[ "Removes", "a", "genome", "from", "the", "database" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/Genomes.py#L58-L97
tariqdaouda/pyGeno
pyGeno/importation/Genomes.py
importGenome
def importGenome(packageFile, batchSize = 50, verbose = 0) : """Import a pyGeno genome package. A genome packages is folder or a tar.gz ball that contains at it's root: * gziped fasta files for all chromosomes, or URLs from where them must be downloaded * gziped GTF gene_set file from Ensembl, or an URL from where it must be downloaded * a manifest.ini file such as:: [package_infos] description = Test package. This package installs only chromosome Y of mus musculus maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = GRCm38.73 [genome] species = Mus_musculus name = GRCm38_test source = http://useast.ensembl.org/info/data/ftp/index.html [chromosome_files] Y = Mus_musculus.GRCm38.73.dna.chromosome.Y.fa.gz / or an url such as ftp://... or http:// [gene_set] gtf = Mus_musculus.GRCm38.73_Y-only.gtf.gz / or an url such as ftp://... or http:// All files except the manifest can be downloaded from: http://useast.ensembl.org/info/data/ftp/index.html A rollback is performed if an exception is caught during importation batchSize sets the number of genes to parse before performing a database save. PCs with little ram like small values, while those endowed with more memory may perform faster with higher ones. Verbose must be an int [0, 4] for various levels of verbosity """ def reformatItems(items) : s = str(items) s = s.replace('[', '').replace(']', '').replace("',", ': ').replace('), ', '\n').replace("'", '').replace('(', '').replace(')', '') return s printf('Importing genome package: %s... (This may take a while)' % packageFile) isDir = False if not os.path.isdir(packageFile) : packageDir = _decompressPackage(packageFile) else : isDir = True packageDir = packageFile parser = SafeConfigParser() parser.read(os.path.normpath(packageDir+'/manifest.ini')) packageInfos = parser.items('package_infos') genomeName = parser.get('genome', 'name') species = parser.get('genome', 'species') genomeSource = parser.get('genome', 'source') seqTargetDir = conf.getGenomeSequencePath(species.lower(), genomeName) if os.path.isdir(seqTargetDir) : raise KeyError("The directory %s already exists, Please call deleteGenome() first if you want to reinstall" % seqTargetDir) gtfFile = _getFile(parser.get('gene_set', 'gtf'), packageDir) chromosomesFiles = {} chromosomeSet = set() for key, fil in parser.items('chromosome_files') : chromosomesFiles[key] = _getFile(fil, packageDir) chromosomeSet.add(key) try : genome = Genome(name = genomeName, species = species) except KeyError: pass else : raise KeyError("There seems to be already a genome (%s, %s), please call deleteGenome() first if you want to reinstall it" % (genomeName, species)) genome = Genome_Raba() genome.set(name = genomeName, species = species, source = genomeSource, packageInfos = packageInfos) printf("Importing:\n\t%s\nGenome:\n\t%s\n..." % (reformatItems(packageInfos).replace('\n', '\n\t'), reformatItems(parser.items('genome')).replace('\n', '\n\t'))) chros = _importGenomeObjects(gtfFile, chromosomeSet, genome, batchSize, verbose) os.makedirs(seqTargetDir) startChro = 0 pBar = ProgressBar(nbEpochs = len(chros)) for chro in chros : pBar.update(label = "Importing DNA, chro %s" % chro.number) length = _importSequence(chro, chromosomesFiles[chro.number.lower()], seqTargetDir) chro.start = startChro chro.end = startChro+length startChro = chro.end chro.save() pBar.close() if not isDir : shutil.rmtree(packageDir) #~ objgraph.show_most_common_types(limit=20) return True
python
def importGenome(packageFile, batchSize = 50, verbose = 0) : """Import a pyGeno genome package. A genome packages is folder or a tar.gz ball that contains at it's root: * gziped fasta files for all chromosomes, or URLs from where them must be downloaded * gziped GTF gene_set file from Ensembl, or an URL from where it must be downloaded * a manifest.ini file such as:: [package_infos] description = Test package. This package installs only chromosome Y of mus musculus maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = GRCm38.73 [genome] species = Mus_musculus name = GRCm38_test source = http://useast.ensembl.org/info/data/ftp/index.html [chromosome_files] Y = Mus_musculus.GRCm38.73.dna.chromosome.Y.fa.gz / or an url such as ftp://... or http:// [gene_set] gtf = Mus_musculus.GRCm38.73_Y-only.gtf.gz / or an url such as ftp://... or http:// All files except the manifest can be downloaded from: http://useast.ensembl.org/info/data/ftp/index.html A rollback is performed if an exception is caught during importation batchSize sets the number of genes to parse before performing a database save. PCs with little ram like small values, while those endowed with more memory may perform faster with higher ones. Verbose must be an int [0, 4] for various levels of verbosity """ def reformatItems(items) : s = str(items) s = s.replace('[', '').replace(']', '').replace("',", ': ').replace('), ', '\n').replace("'", '').replace('(', '').replace(')', '') return s printf('Importing genome package: %s... (This may take a while)' % packageFile) isDir = False if not os.path.isdir(packageFile) : packageDir = _decompressPackage(packageFile) else : isDir = True packageDir = packageFile parser = SafeConfigParser() parser.read(os.path.normpath(packageDir+'/manifest.ini')) packageInfos = parser.items('package_infos') genomeName = parser.get('genome', 'name') species = parser.get('genome', 'species') genomeSource = parser.get('genome', 'source') seqTargetDir = conf.getGenomeSequencePath(species.lower(), genomeName) if os.path.isdir(seqTargetDir) : raise KeyError("The directory %s already exists, Please call deleteGenome() first if you want to reinstall" % seqTargetDir) gtfFile = _getFile(parser.get('gene_set', 'gtf'), packageDir) chromosomesFiles = {} chromosomeSet = set() for key, fil in parser.items('chromosome_files') : chromosomesFiles[key] = _getFile(fil, packageDir) chromosomeSet.add(key) try : genome = Genome(name = genomeName, species = species) except KeyError: pass else : raise KeyError("There seems to be already a genome (%s, %s), please call deleteGenome() first if you want to reinstall it" % (genomeName, species)) genome = Genome_Raba() genome.set(name = genomeName, species = species, source = genomeSource, packageInfos = packageInfos) printf("Importing:\n\t%s\nGenome:\n\t%s\n..." % (reformatItems(packageInfos).replace('\n', '\n\t'), reformatItems(parser.items('genome')).replace('\n', '\n\t'))) chros = _importGenomeObjects(gtfFile, chromosomeSet, genome, batchSize, verbose) os.makedirs(seqTargetDir) startChro = 0 pBar = ProgressBar(nbEpochs = len(chros)) for chro in chros : pBar.update(label = "Importing DNA, chro %s" % chro.number) length = _importSequence(chro, chromosomesFiles[chro.number.lower()], seqTargetDir) chro.start = startChro chro.end = startChro+length startChro = chro.end chro.save() pBar.close() if not isDir : shutil.rmtree(packageDir) #~ objgraph.show_most_common_types(limit=20) return True
[ "def", "importGenome", "(", "packageFile", ",", "batchSize", "=", "50", ",", "verbose", "=", "0", ")", ":", "def", "reformatItems", "(", "items", ")", ":", "s", "=", "str", "(", "items", ")", "s", "=", "s", ".", "replace", "(", "'['", ",", "''", ")", ".", "replace", "(", "']'", ",", "''", ")", ".", "replace", "(", "\"',\"", ",", "': '", ")", ".", "replace", "(", "'), '", ",", "'\\n'", ")", ".", "replace", "(", "\"'\"", ",", "''", ")", ".", "replace", "(", "'('", ",", "''", ")", ".", "replace", "(", "')'", ",", "''", ")", "return", "s", "printf", "(", "'Importing genome package: %s... (This may take a while)'", "%", "packageFile", ")", "isDir", "=", "False", "if", "not", "os", ".", "path", ".", "isdir", "(", "packageFile", ")", ":", "packageDir", "=", "_decompressPackage", "(", "packageFile", ")", "else", ":", "isDir", "=", "True", "packageDir", "=", "packageFile", "parser", "=", "SafeConfigParser", "(", ")", "parser", ".", "read", "(", "os", ".", "path", ".", "normpath", "(", "packageDir", "+", "'/manifest.ini'", ")", ")", "packageInfos", "=", "parser", ".", "items", "(", "'package_infos'", ")", "genomeName", "=", "parser", ".", "get", "(", "'genome'", ",", "'name'", ")", "species", "=", "parser", ".", "get", "(", "'genome'", ",", "'species'", ")", "genomeSource", "=", "parser", ".", "get", "(", "'genome'", ",", "'source'", ")", "seqTargetDir", "=", "conf", ".", "getGenomeSequencePath", "(", "species", ".", "lower", "(", ")", ",", "genomeName", ")", "if", "os", ".", "path", ".", "isdir", "(", "seqTargetDir", ")", ":", "raise", "KeyError", "(", "\"The directory %s already exists, Please call deleteGenome() first if you want to reinstall\"", "%", "seqTargetDir", ")", "gtfFile", "=", "_getFile", "(", "parser", ".", "get", "(", "'gene_set'", ",", "'gtf'", ")", ",", "packageDir", ")", "chromosomesFiles", "=", "{", "}", "chromosomeSet", "=", "set", "(", ")", "for", "key", ",", "fil", "in", "parser", ".", "items", "(", "'chromosome_files'", ")", ":", "chromosomesFiles", "[", "key", "]", "=", "_getFile", "(", "fil", ",", "packageDir", ")", "chromosomeSet", ".", "add", "(", "key", ")", "try", ":", "genome", "=", "Genome", "(", "name", "=", "genomeName", ",", "species", "=", "species", ")", "except", "KeyError", ":", "pass", "else", ":", "raise", "KeyError", "(", "\"There seems to be already a genome (%s, %s), please call deleteGenome() first if you want to reinstall it\"", "%", "(", "genomeName", ",", "species", ")", ")", "genome", "=", "Genome_Raba", "(", ")", "genome", ".", "set", "(", "name", "=", "genomeName", ",", "species", "=", "species", ",", "source", "=", "genomeSource", ",", "packageInfos", "=", "packageInfos", ")", "printf", "(", "\"Importing:\\n\\t%s\\nGenome:\\n\\t%s\\n...\"", "%", "(", "reformatItems", "(", "packageInfos", ")", ".", "replace", "(", "'\\n'", ",", "'\\n\\t'", ")", ",", "reformatItems", "(", "parser", ".", "items", "(", "'genome'", ")", ")", ".", "replace", "(", "'\\n'", ",", "'\\n\\t'", ")", ")", ")", "chros", "=", "_importGenomeObjects", "(", "gtfFile", ",", "chromosomeSet", ",", "genome", ",", "batchSize", ",", "verbose", ")", "os", ".", "makedirs", "(", "seqTargetDir", ")", "startChro", "=", "0", "pBar", "=", "ProgressBar", "(", "nbEpochs", "=", "len", "(", "chros", ")", ")", "for", "chro", "in", "chros", ":", "pBar", ".", "update", "(", "label", "=", "\"Importing DNA, chro %s\"", "%", "chro", ".", "number", ")", "length", "=", "_importSequence", "(", "chro", ",", "chromosomesFiles", "[", "chro", ".", "number", ".", "lower", "(", ")", "]", ",", "seqTargetDir", ")", "chro", ".", "start", "=", "startChro", "chro", ".", "end", "=", "startChro", "+", "length", "startChro", "=", "chro", ".", "end", "chro", ".", "save", "(", ")", "pBar", ".", "close", "(", ")", "if", "not", "isDir", ":", "shutil", ".", "rmtree", "(", "packageDir", ")", "#~ objgraph.show_most_common_types(limit=20)", "return", "True" ]
Import a pyGeno genome package. A genome packages is folder or a tar.gz ball that contains at it's root: * gziped fasta files for all chromosomes, or URLs from where them must be downloaded * gziped GTF gene_set file from Ensembl, or an URL from where it must be downloaded * a manifest.ini file such as:: [package_infos] description = Test package. This package installs only chromosome Y of mus musculus maintainer = Tariq Daouda maintainer_contact = tariq.daouda [at] umontreal version = GRCm38.73 [genome] species = Mus_musculus name = GRCm38_test source = http://useast.ensembl.org/info/data/ftp/index.html [chromosome_files] Y = Mus_musculus.GRCm38.73.dna.chromosome.Y.fa.gz / or an url such as ftp://... or http:// [gene_set] gtf = Mus_musculus.GRCm38.73_Y-only.gtf.gz / or an url such as ftp://... or http:// All files except the manifest can be downloaded from: http://useast.ensembl.org/info/data/ftp/index.html A rollback is performed if an exception is caught during importation batchSize sets the number of genes to parse before performing a database save. PCs with little ram like small values, while those endowed with more memory may perform faster with higher ones. Verbose must be an int [0, 4] for various levels of verbosity
[ "Import", "a", "pyGeno", "genome", "package", ".", "A", "genome", "packages", "is", "folder", "or", "a", "tar", ".", "gz", "ball", "that", "contains", "at", "it", "s", "root", ":" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/Genomes.py#L99-L198
tariqdaouda/pyGeno
pyGeno/importation/Genomes.py
_importGenomeObjects
def _importGenomeObjects(gtfFilePath, chroSet, genome, batchSize, verbose = 0) : """verbose must be an int [0, 4] for various levels of verbosity""" class Store(object) : def __init__(self, conf) : self.conf = conf self.chromosomes = {} self.genes = {} self.transcripts = {} self.proteins = {} self.exons = {} def batch_save(self) : self.conf.db.beginTransaction() for c in self.genes.itervalues() : c.save() conf.removeFromDBRegistery(c) for c in self.transcripts.itervalues() : c.save() conf.removeFromDBRegistery(c.exons) conf.removeFromDBRegistery(c) for c in self.proteins.itervalues() : c.save() conf.removeFromDBRegistery(c) self.conf.db.endTransaction() del(self.genes) del(self.transcripts) del(self.proteins) del(self.exons) self.genes = {} self.transcripts = {} self.proteins = {} self.exons = {} gc.collect() def save_chros(self) : pBar = ProgressBar(nbEpochs = len(self.chromosomes)) for c in self.chromosomes.itervalues() : pBar.update(label = 'Chr %s' % c.number) c.save() pBar.close() printf('Importing gene set infos from %s...' % gtfFilePath) printf('Backuping indexes...') indexes = conf.db.getIndexes() printf("Droping all your indexes, (don't worry i'll restore them later)...") Genome_Raba.flushIndexes() Chromosome_Raba.flushIndexes() Gene_Raba.flushIndexes() Transcript_Raba.flushIndexes() Protein_Raba.flushIndexes() Exon_Raba.flushIndexes() printf("Parsing gene set...") gtf = GTFFile(gtfFilePath, gziped = True) printf('Done. Importation begins!') store = Store(conf) chroNumber = None pBar = ProgressBar(nbEpochs = len(gtf)) for line in gtf : chroN = line['seqname'] pBar.update(label = "Chr %s" % chroN) if (chroN.upper() in chroSet or chroN.lower() in chroSet): strand = line['strand'] gene_biotype = line['gene_biotype'] regionType = line['feature'] frame = line['frame'] start = int(line['start']) - 1 end = int(line['end']) if start > end : start, end = end, start chroNumber = chroN.upper() if chroNumber not in store.chromosomes : store.chromosomes[chroNumber] = Chromosome_Raba() store.chromosomes[chroNumber].set(genome = genome, number = chroNumber) try : geneId = line['gene_id'] geneName = line['gene_name'] except KeyError : geneId = None geneName = None if verbose : printf('Warning: no gene_id/name found in line %s' % gtf[i]) if geneId is not None : if geneId not in store.genes : if len(store.genes) > batchSize : store.batch_save() if verbose > 0 : printf('\tGene %s, %s...' % (geneId, geneName)) store.genes[geneId] = Gene_Raba() store.genes[geneId].set(genome = genome, id = geneId, chromosome = store.chromosomes[chroNumber], name = geneName, strand = strand, biotype = gene_biotype) if start < store.genes[geneId].start or store.genes[geneId].start is None : store.genes[geneId].start = start if end > store.genes[geneId].end or store.genes[geneId].end is None : store.genes[geneId].end = end try : transId = line['transcript_id'] transName = line['transcript_name'] try : transcript_biotype = line['transcript_biotype'] except KeyError : transcript_biotype = None except KeyError : transId = None transName = None if verbose > 2 : printf('\t\tWarning: no transcript_id, name found in line %s' % gtf[i]) if transId is not None : if transId not in store.transcripts : if verbose > 1 : printf('\t\tTranscript %s, %s...' % (transId, transName)) store.transcripts[transId] = Transcript_Raba() store.transcripts[transId].set(genome = genome, id = transId, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), name = transName, biotype=transcript_biotype) if start < store.transcripts[transId].start or store.transcripts[transId].start is None: store.transcripts[transId].start = start if end > store.transcripts[transId].end or store.transcripts[transId].end is None: store.transcripts[transId].end = end try : protId = line['protein_id'] except KeyError : protId = None if verbose > 2 : printf('Warning: no protein_id found in line %s' % gtf[i]) # Store selenocysteine positions in transcript if regionType == 'Selenocysteine': store.transcripts[transId].selenocysteine.append(start) if protId is not None and protId not in store.proteins : if verbose > 1 : printf('\t\tProtein %s...' % (protId)) store.proteins[protId] = Protein_Raba() store.proteins[protId].set(genome = genome, id = protId, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), transcript = store.transcripts.get(transId, None), name = transName) store.transcripts[transId].protein = store.proteins[protId] try : exonNumber = int(line['exon_number']) - 1 exonKey = (transId, exonNumber) except KeyError : exonNumber = None exonKey = None if verbose > 2 : printf('Warning: no exon number or id found in line %s' % gtf[i]) if exonKey is not None : if verbose > 3 : printf('\t\t\texon %s...' % (exonId)) if exonKey not in store.exons and regionType == 'exon' : store.exons[exonKey] = Exon_Raba() store.exons[exonKey].set(genome = genome, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), transcript = store.transcripts.get(transId, None), protein = store.proteins.get(protId, None), strand = strand, number = exonNumber, start = start, end = end) store.transcripts[transId].exons.append(store.exons[exonKey]) try : store.exons[exonKey].id = line['exon_id'] except KeyError : pass if regionType == 'exon' : if start < store.exons[exonKey].start or store.exons[exonKey].start is None: store.exons[exonKey].start = start if end > store.transcripts[transId].end or store.exons[exonKey].end is None: store.exons[exonKey].end = end elif regionType == 'CDS' : store.exons[exonKey].CDS_start = start store.exons[exonKey].CDS_end = end store.exons[exonKey].frame = frame elif regionType == 'stop_codon' : if strand == '+' : if store.exons[exonKey].CDS_end != None : store.exons[exonKey].CDS_end += 3 if store.exons[exonKey].end < store.exons[exonKey].CDS_end : store.exons[exonKey].end = store.exons[exonKey].CDS_end if store.transcripts[transId].end < store.exons[exonKey].CDS_end : store.transcripts[transId].end = store.exons[exonKey].CDS_end if store.genes[geneId].end < store.exons[exonKey].CDS_end : store.genes[geneId].end = store.exons[exonKey].CDS_end if strand == '-' : if store.exons[exonKey].CDS_start != None : store.exons[exonKey].CDS_start -= 3 if store.exons[exonKey].start > store.exons[exonKey].CDS_start : store.exons[exonKey].start = store.exons[exonKey].CDS_start if store.transcripts[transId].start > store.exons[exonKey].CDS_start : store.transcripts[transId].start = store.exons[exonKey].CDS_start if store.genes[geneId].start > store.exons[exonKey].CDS_start : store.genes[geneId].start = store.exons[exonKey].CDS_start pBar.close() store.batch_save() conf.db.beginTransaction() printf('almost done saving chromosomes...') store.save_chros() printf('saving genome object...') genome.save() conf.db.endTransaction() conf.db.beginTransaction() printf('restoring core indexes...') # Genome.ensureGlobalIndex(('name', 'species')) # Chromosome.ensureGlobalIndex('genome') # Gene.ensureGlobalIndex('genome') # Transcript.ensureGlobalIndex('genome') # Protein.ensureGlobalIndex('genome') # Exon.ensureGlobalIndex('genome') Transcript.ensureGlobalIndex('exons') printf('commiting changes...') conf.db.endTransaction() conf.db.beginTransaction() printf('restoring user indexes') pBar = ProgressBar(label = "restoring", nbEpochs = len(indexes)) for idx in indexes : pBar.update() conf.db.execute(idx[-1].replace('CREATE INDEX', 'CREATE INDEX IF NOT EXISTS')) pBar.close() printf('commiting changes...') conf.db.endTransaction() return store.chromosomes.values()
python
def _importGenomeObjects(gtfFilePath, chroSet, genome, batchSize, verbose = 0) : """verbose must be an int [0, 4] for various levels of verbosity""" class Store(object) : def __init__(self, conf) : self.conf = conf self.chromosomes = {} self.genes = {} self.transcripts = {} self.proteins = {} self.exons = {} def batch_save(self) : self.conf.db.beginTransaction() for c in self.genes.itervalues() : c.save() conf.removeFromDBRegistery(c) for c in self.transcripts.itervalues() : c.save() conf.removeFromDBRegistery(c.exons) conf.removeFromDBRegistery(c) for c in self.proteins.itervalues() : c.save() conf.removeFromDBRegistery(c) self.conf.db.endTransaction() del(self.genes) del(self.transcripts) del(self.proteins) del(self.exons) self.genes = {} self.transcripts = {} self.proteins = {} self.exons = {} gc.collect() def save_chros(self) : pBar = ProgressBar(nbEpochs = len(self.chromosomes)) for c in self.chromosomes.itervalues() : pBar.update(label = 'Chr %s' % c.number) c.save() pBar.close() printf('Importing gene set infos from %s...' % gtfFilePath) printf('Backuping indexes...') indexes = conf.db.getIndexes() printf("Droping all your indexes, (don't worry i'll restore them later)...") Genome_Raba.flushIndexes() Chromosome_Raba.flushIndexes() Gene_Raba.flushIndexes() Transcript_Raba.flushIndexes() Protein_Raba.flushIndexes() Exon_Raba.flushIndexes() printf("Parsing gene set...") gtf = GTFFile(gtfFilePath, gziped = True) printf('Done. Importation begins!') store = Store(conf) chroNumber = None pBar = ProgressBar(nbEpochs = len(gtf)) for line in gtf : chroN = line['seqname'] pBar.update(label = "Chr %s" % chroN) if (chroN.upper() in chroSet or chroN.lower() in chroSet): strand = line['strand'] gene_biotype = line['gene_biotype'] regionType = line['feature'] frame = line['frame'] start = int(line['start']) - 1 end = int(line['end']) if start > end : start, end = end, start chroNumber = chroN.upper() if chroNumber not in store.chromosomes : store.chromosomes[chroNumber] = Chromosome_Raba() store.chromosomes[chroNumber].set(genome = genome, number = chroNumber) try : geneId = line['gene_id'] geneName = line['gene_name'] except KeyError : geneId = None geneName = None if verbose : printf('Warning: no gene_id/name found in line %s' % gtf[i]) if geneId is not None : if geneId not in store.genes : if len(store.genes) > batchSize : store.batch_save() if verbose > 0 : printf('\tGene %s, %s...' % (geneId, geneName)) store.genes[geneId] = Gene_Raba() store.genes[geneId].set(genome = genome, id = geneId, chromosome = store.chromosomes[chroNumber], name = geneName, strand = strand, biotype = gene_biotype) if start < store.genes[geneId].start or store.genes[geneId].start is None : store.genes[geneId].start = start if end > store.genes[geneId].end or store.genes[geneId].end is None : store.genes[geneId].end = end try : transId = line['transcript_id'] transName = line['transcript_name'] try : transcript_biotype = line['transcript_biotype'] except KeyError : transcript_biotype = None except KeyError : transId = None transName = None if verbose > 2 : printf('\t\tWarning: no transcript_id, name found in line %s' % gtf[i]) if transId is not None : if transId not in store.transcripts : if verbose > 1 : printf('\t\tTranscript %s, %s...' % (transId, transName)) store.transcripts[transId] = Transcript_Raba() store.transcripts[transId].set(genome = genome, id = transId, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), name = transName, biotype=transcript_biotype) if start < store.transcripts[transId].start or store.transcripts[transId].start is None: store.transcripts[transId].start = start if end > store.transcripts[transId].end or store.transcripts[transId].end is None: store.transcripts[transId].end = end try : protId = line['protein_id'] except KeyError : protId = None if verbose > 2 : printf('Warning: no protein_id found in line %s' % gtf[i]) # Store selenocysteine positions in transcript if regionType == 'Selenocysteine': store.transcripts[transId].selenocysteine.append(start) if protId is not None and protId not in store.proteins : if verbose > 1 : printf('\t\tProtein %s...' % (protId)) store.proteins[protId] = Protein_Raba() store.proteins[protId].set(genome = genome, id = protId, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), transcript = store.transcripts.get(transId, None), name = transName) store.transcripts[transId].protein = store.proteins[protId] try : exonNumber = int(line['exon_number']) - 1 exonKey = (transId, exonNumber) except KeyError : exonNumber = None exonKey = None if verbose > 2 : printf('Warning: no exon number or id found in line %s' % gtf[i]) if exonKey is not None : if verbose > 3 : printf('\t\t\texon %s...' % (exonId)) if exonKey not in store.exons and regionType == 'exon' : store.exons[exonKey] = Exon_Raba() store.exons[exonKey].set(genome = genome, chromosome = store.chromosomes[chroNumber], gene = store.genes.get(geneId, None), transcript = store.transcripts.get(transId, None), protein = store.proteins.get(protId, None), strand = strand, number = exonNumber, start = start, end = end) store.transcripts[transId].exons.append(store.exons[exonKey]) try : store.exons[exonKey].id = line['exon_id'] except KeyError : pass if regionType == 'exon' : if start < store.exons[exonKey].start or store.exons[exonKey].start is None: store.exons[exonKey].start = start if end > store.transcripts[transId].end or store.exons[exonKey].end is None: store.exons[exonKey].end = end elif regionType == 'CDS' : store.exons[exonKey].CDS_start = start store.exons[exonKey].CDS_end = end store.exons[exonKey].frame = frame elif regionType == 'stop_codon' : if strand == '+' : if store.exons[exonKey].CDS_end != None : store.exons[exonKey].CDS_end += 3 if store.exons[exonKey].end < store.exons[exonKey].CDS_end : store.exons[exonKey].end = store.exons[exonKey].CDS_end if store.transcripts[transId].end < store.exons[exonKey].CDS_end : store.transcripts[transId].end = store.exons[exonKey].CDS_end if store.genes[geneId].end < store.exons[exonKey].CDS_end : store.genes[geneId].end = store.exons[exonKey].CDS_end if strand == '-' : if store.exons[exonKey].CDS_start != None : store.exons[exonKey].CDS_start -= 3 if store.exons[exonKey].start > store.exons[exonKey].CDS_start : store.exons[exonKey].start = store.exons[exonKey].CDS_start if store.transcripts[transId].start > store.exons[exonKey].CDS_start : store.transcripts[transId].start = store.exons[exonKey].CDS_start if store.genes[geneId].start > store.exons[exonKey].CDS_start : store.genes[geneId].start = store.exons[exonKey].CDS_start pBar.close() store.batch_save() conf.db.beginTransaction() printf('almost done saving chromosomes...') store.save_chros() printf('saving genome object...') genome.save() conf.db.endTransaction() conf.db.beginTransaction() printf('restoring core indexes...') # Genome.ensureGlobalIndex(('name', 'species')) # Chromosome.ensureGlobalIndex('genome') # Gene.ensureGlobalIndex('genome') # Transcript.ensureGlobalIndex('genome') # Protein.ensureGlobalIndex('genome') # Exon.ensureGlobalIndex('genome') Transcript.ensureGlobalIndex('exons') printf('commiting changes...') conf.db.endTransaction() conf.db.beginTransaction() printf('restoring user indexes') pBar = ProgressBar(label = "restoring", nbEpochs = len(indexes)) for idx in indexes : pBar.update() conf.db.execute(idx[-1].replace('CREATE INDEX', 'CREATE INDEX IF NOT EXISTS')) pBar.close() printf('commiting changes...') conf.db.endTransaction() return store.chromosomes.values()
[ "def", "_importGenomeObjects", "(", "gtfFilePath", ",", "chroSet", ",", "genome", ",", "batchSize", ",", "verbose", "=", "0", ")", ":", "class", "Store", "(", "object", ")", ":", "def", "__init__", "(", "self", ",", "conf", ")", ":", "self", ".", "conf", "=", "conf", "self", ".", "chromosomes", "=", "{", "}", "self", ".", "genes", "=", "{", "}", "self", ".", "transcripts", "=", "{", "}", "self", ".", "proteins", "=", "{", "}", "self", ".", "exons", "=", "{", "}", "def", "batch_save", "(", "self", ")", ":", "self", ".", "conf", ".", "db", ".", "beginTransaction", "(", ")", "for", "c", "in", "self", ".", "genes", ".", "itervalues", "(", ")", ":", "c", ".", "save", "(", ")", "conf", ".", "removeFromDBRegistery", "(", "c", ")", "for", "c", "in", "self", ".", "transcripts", ".", "itervalues", "(", ")", ":", "c", ".", "save", "(", ")", "conf", ".", "removeFromDBRegistery", "(", "c", ".", "exons", ")", "conf", ".", "removeFromDBRegistery", "(", "c", ")", "for", "c", "in", "self", ".", "proteins", ".", "itervalues", "(", ")", ":", "c", ".", "save", "(", ")", "conf", ".", "removeFromDBRegistery", "(", "c", ")", "self", ".", "conf", ".", "db", ".", "endTransaction", "(", ")", "del", "(", "self", ".", "genes", ")", "del", "(", "self", ".", "transcripts", ")", "del", "(", "self", ".", "proteins", ")", "del", "(", "self", ".", "exons", ")", "self", ".", "genes", "=", "{", "}", "self", ".", "transcripts", "=", "{", "}", "self", ".", "proteins", "=", "{", "}", "self", ".", "exons", "=", "{", "}", "gc", ".", "collect", "(", ")", "def", "save_chros", "(", "self", ")", ":", "pBar", "=", "ProgressBar", "(", "nbEpochs", "=", "len", "(", "self", ".", "chromosomes", ")", ")", "for", "c", "in", "self", ".", "chromosomes", ".", "itervalues", "(", ")", ":", "pBar", ".", "update", "(", "label", "=", "'Chr %s'", "%", "c", ".", "number", ")", "c", ".", "save", "(", ")", "pBar", ".", "close", "(", ")", "printf", "(", "'Importing gene set infos from %s...'", "%", "gtfFilePath", ")", "printf", "(", "'Backuping indexes...'", ")", "indexes", "=", "conf", ".", "db", ".", "getIndexes", "(", ")", "printf", "(", "\"Droping all your indexes, (don't worry i'll restore them later)...\"", ")", "Genome_Raba", ".", "flushIndexes", "(", ")", "Chromosome_Raba", ".", "flushIndexes", "(", ")", "Gene_Raba", ".", "flushIndexes", "(", ")", "Transcript_Raba", ".", "flushIndexes", "(", ")", "Protein_Raba", ".", "flushIndexes", "(", ")", "Exon_Raba", ".", "flushIndexes", "(", ")", "printf", "(", "\"Parsing gene set...\"", ")", "gtf", "=", "GTFFile", "(", "gtfFilePath", ",", "gziped", "=", "True", ")", "printf", "(", "'Done. Importation begins!'", ")", "store", "=", "Store", "(", "conf", ")", "chroNumber", "=", "None", "pBar", "=", "ProgressBar", "(", "nbEpochs", "=", "len", "(", "gtf", ")", ")", "for", "line", "in", "gtf", ":", "chroN", "=", "line", "[", "'seqname'", "]", "pBar", ".", "update", "(", "label", "=", "\"Chr %s\"", "%", "chroN", ")", "if", "(", "chroN", ".", "upper", "(", ")", "in", "chroSet", "or", "chroN", ".", "lower", "(", ")", "in", "chroSet", ")", ":", "strand", "=", "line", "[", "'strand'", "]", "gene_biotype", "=", "line", "[", "'gene_biotype'", "]", "regionType", "=", "line", "[", "'feature'", "]", "frame", "=", "line", "[", "'frame'", "]", "start", "=", "int", "(", "line", "[", "'start'", "]", ")", "-", "1", "end", "=", "int", "(", "line", "[", "'end'", "]", ")", "if", "start", ">", "end", ":", "start", ",", "end", "=", "end", ",", "start", "chroNumber", "=", "chroN", ".", "upper", "(", ")", "if", "chroNumber", "not", "in", "store", ".", "chromosomes", ":", "store", ".", "chromosomes", "[", "chroNumber", "]", "=", "Chromosome_Raba", "(", ")", "store", ".", "chromosomes", "[", "chroNumber", "]", ".", "set", "(", "genome", "=", "genome", ",", "number", "=", "chroNumber", ")", "try", ":", "geneId", "=", "line", "[", "'gene_id'", "]", "geneName", "=", "line", "[", "'gene_name'", "]", "except", "KeyError", ":", "geneId", "=", "None", "geneName", "=", "None", "if", "verbose", ":", "printf", "(", "'Warning: no gene_id/name found in line %s'", "%", "gtf", "[", "i", "]", ")", "if", "geneId", "is", "not", "None", ":", "if", "geneId", "not", "in", "store", ".", "genes", ":", "if", "len", "(", "store", ".", "genes", ")", ">", "batchSize", ":", "store", ".", "batch_save", "(", ")", "if", "verbose", ">", "0", ":", "printf", "(", "'\\tGene %s, %s...'", "%", "(", "geneId", ",", "geneName", ")", ")", "store", ".", "genes", "[", "geneId", "]", "=", "Gene_Raba", "(", ")", "store", ".", "genes", "[", "geneId", "]", ".", "set", "(", "genome", "=", "genome", ",", "id", "=", "geneId", ",", "chromosome", "=", "store", ".", "chromosomes", "[", "chroNumber", "]", ",", "name", "=", "geneName", ",", "strand", "=", "strand", ",", "biotype", "=", "gene_biotype", ")", "if", "start", "<", "store", ".", "genes", "[", "geneId", "]", ".", "start", "or", "store", ".", "genes", "[", "geneId", "]", ".", "start", "is", "None", ":", "store", ".", "genes", "[", "geneId", "]", ".", "start", "=", "start", "if", "end", ">", "store", ".", "genes", "[", "geneId", "]", ".", "end", "or", "store", ".", "genes", "[", "geneId", "]", ".", "end", "is", "None", ":", "store", ".", "genes", "[", "geneId", "]", ".", "end", "=", "end", "try", ":", "transId", "=", "line", "[", "'transcript_id'", "]", "transName", "=", "line", "[", "'transcript_name'", "]", "try", ":", "transcript_biotype", "=", "line", "[", "'transcript_biotype'", "]", "except", "KeyError", ":", "transcript_biotype", "=", "None", "except", "KeyError", ":", "transId", "=", "None", "transName", "=", "None", "if", "verbose", ">", "2", ":", "printf", "(", "'\\t\\tWarning: no transcript_id, name found in line %s'", "%", "gtf", "[", "i", "]", ")", "if", "transId", "is", "not", "None", ":", "if", "transId", "not", "in", "store", ".", "transcripts", ":", "if", "verbose", ">", "1", ":", "printf", "(", "'\\t\\tTranscript %s, %s...'", "%", "(", "transId", ",", "transName", ")", ")", "store", ".", "transcripts", "[", "transId", "]", "=", "Transcript_Raba", "(", ")", "store", ".", "transcripts", "[", "transId", "]", ".", "set", "(", "genome", "=", "genome", ",", "id", "=", "transId", ",", "chromosome", "=", "store", ".", "chromosomes", "[", "chroNumber", "]", ",", "gene", "=", "store", ".", "genes", ".", "get", "(", "geneId", ",", "None", ")", ",", "name", "=", "transName", ",", "biotype", "=", "transcript_biotype", ")", "if", "start", "<", "store", ".", "transcripts", "[", "transId", "]", ".", "start", "or", "store", ".", "transcripts", "[", "transId", "]", ".", "start", "is", "None", ":", "store", ".", "transcripts", "[", "transId", "]", ".", "start", "=", "start", "if", "end", ">", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "or", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "is", "None", ":", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "=", "end", "try", ":", "protId", "=", "line", "[", "'protein_id'", "]", "except", "KeyError", ":", "protId", "=", "None", "if", "verbose", ">", "2", ":", "printf", "(", "'Warning: no protein_id found in line %s'", "%", "gtf", "[", "i", "]", ")", "# Store selenocysteine positions in transcript", "if", "regionType", "==", "'Selenocysteine'", ":", "store", ".", "transcripts", "[", "transId", "]", ".", "selenocysteine", ".", "append", "(", "start", ")", "if", "protId", "is", "not", "None", "and", "protId", "not", "in", "store", ".", "proteins", ":", "if", "verbose", ">", "1", ":", "printf", "(", "'\\t\\tProtein %s...'", "%", "(", "protId", ")", ")", "store", ".", "proteins", "[", "protId", "]", "=", "Protein_Raba", "(", ")", "store", ".", "proteins", "[", "protId", "]", ".", "set", "(", "genome", "=", "genome", ",", "id", "=", "protId", ",", "chromosome", "=", "store", ".", "chromosomes", "[", "chroNumber", "]", ",", "gene", "=", "store", ".", "genes", ".", "get", "(", "geneId", ",", "None", ")", ",", "transcript", "=", "store", ".", "transcripts", ".", "get", "(", "transId", ",", "None", ")", ",", "name", "=", "transName", ")", "store", ".", "transcripts", "[", "transId", "]", ".", "protein", "=", "store", ".", "proteins", "[", "protId", "]", "try", ":", "exonNumber", "=", "int", "(", "line", "[", "'exon_number'", "]", ")", "-", "1", "exonKey", "=", "(", "transId", ",", "exonNumber", ")", "except", "KeyError", ":", "exonNumber", "=", "None", "exonKey", "=", "None", "if", "verbose", ">", "2", ":", "printf", "(", "'Warning: no exon number or id found in line %s'", "%", "gtf", "[", "i", "]", ")", "if", "exonKey", "is", "not", "None", ":", "if", "verbose", ">", "3", ":", "printf", "(", "'\\t\\t\\texon %s...'", "%", "(", "exonId", ")", ")", "if", "exonKey", "not", "in", "store", ".", "exons", "and", "regionType", "==", "'exon'", ":", "store", ".", "exons", "[", "exonKey", "]", "=", "Exon_Raba", "(", ")", "store", ".", "exons", "[", "exonKey", "]", ".", "set", "(", "genome", "=", "genome", ",", "chromosome", "=", "store", ".", "chromosomes", "[", "chroNumber", "]", ",", "gene", "=", "store", ".", "genes", ".", "get", "(", "geneId", ",", "None", ")", ",", "transcript", "=", "store", ".", "transcripts", ".", "get", "(", "transId", ",", "None", ")", ",", "protein", "=", "store", ".", "proteins", ".", "get", "(", "protId", ",", "None", ")", ",", "strand", "=", "strand", ",", "number", "=", "exonNumber", ",", "start", "=", "start", ",", "end", "=", "end", ")", "store", ".", "transcripts", "[", "transId", "]", ".", "exons", ".", "append", "(", "store", ".", "exons", "[", "exonKey", "]", ")", "try", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "id", "=", "line", "[", "'exon_id'", "]", "except", "KeyError", ":", "pass", "if", "regionType", "==", "'exon'", ":", "if", "start", "<", "store", ".", "exons", "[", "exonKey", "]", ".", "start", "or", "store", ".", "exons", "[", "exonKey", "]", ".", "start", "is", "None", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "start", "=", "start", "if", "end", ">", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "or", "store", ".", "exons", "[", "exonKey", "]", ".", "end", "is", "None", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "end", "=", "end", "elif", "regionType", "==", "'CDS'", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "=", "start", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "=", "end", "store", ".", "exons", "[", "exonKey", "]", ".", "frame", "=", "frame", "elif", "regionType", "==", "'stop_codon'", ":", "if", "strand", "==", "'+'", ":", "if", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "!=", "None", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "+=", "3", "if", "store", ".", "exons", "[", "exonKey", "]", ".", "end", "<", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "end", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "if", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "<", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", ":", "store", ".", "transcripts", "[", "transId", "]", ".", "end", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "if", "store", ".", "genes", "[", "geneId", "]", ".", "end", "<", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", ":", "store", ".", "genes", "[", "geneId", "]", ".", "end", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_end", "if", "strand", "==", "'-'", ":", "if", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "!=", "None", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "-=", "3", "if", "store", ".", "exons", "[", "exonKey", "]", ".", "start", ">", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", ":", "store", ".", "exons", "[", "exonKey", "]", ".", "start", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "if", "store", ".", "transcripts", "[", "transId", "]", ".", "start", ">", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", ":", "store", ".", "transcripts", "[", "transId", "]", ".", "start", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "if", "store", ".", "genes", "[", "geneId", "]", ".", "start", ">", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", ":", "store", ".", "genes", "[", "geneId", "]", ".", "start", "=", "store", ".", "exons", "[", "exonKey", "]", ".", "CDS_start", "pBar", ".", "close", "(", ")", "store", ".", "batch_save", "(", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "printf", "(", "'almost done saving chromosomes...'", ")", "store", ".", "save_chros", "(", ")", "printf", "(", "'saving genome object...'", ")", "genome", ".", "save", "(", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "printf", "(", "'restoring core indexes...'", ")", "# Genome.ensureGlobalIndex(('name', 'species'))", "# Chromosome.ensureGlobalIndex('genome')", "# Gene.ensureGlobalIndex('genome')", "# Transcript.ensureGlobalIndex('genome')", "# Protein.ensureGlobalIndex('genome')", "# Exon.ensureGlobalIndex('genome')", "Transcript", ".", "ensureGlobalIndex", "(", "'exons'", ")", "printf", "(", "'commiting changes...'", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "conf", ".", "db", ".", "beginTransaction", "(", ")", "printf", "(", "'restoring user indexes'", ")", "pBar", "=", "ProgressBar", "(", "label", "=", "\"restoring\"", ",", "nbEpochs", "=", "len", "(", "indexes", ")", ")", "for", "idx", "in", "indexes", ":", "pBar", ".", "update", "(", ")", "conf", ".", "db", ".", "execute", "(", "idx", "[", "-", "1", "]", ".", "replace", "(", "'CREATE INDEX'", ",", "'CREATE INDEX IF NOT EXISTS'", ")", ")", "pBar", ".", "close", "(", ")", "printf", "(", "'commiting changes...'", ")", "conf", ".", "db", ".", "endTransaction", "(", ")", "return", "store", ".", "chromosomes", ".", "values", "(", ")" ]
verbose must be an int [0, 4] for various levels of verbosity
[ "verbose", "must", "be", "an", "int", "[", "0", "4", "]", "for", "various", "levels", "of", "verbosity" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/Genomes.py#L201-L442
tariqdaouda/pyGeno
pyGeno/importation/Genomes.py
_importSequence
def _importSequence(chromosome, fastaFile, targetDir) : "Serializes fastas into .dat files" f = gzip.open(fastaFile) header = f.readline() strRes = f.read().upper().replace('\n', '').replace('\r', '') f.close() fn = '%s/chromosome%s.dat' % (targetDir, chromosome.number) f = open(fn, 'w') f.write(strRes) f.close() chromosome.dataFile = fn chromosome.header = header return len(strRes)
python
def _importSequence(chromosome, fastaFile, targetDir) : "Serializes fastas into .dat files" f = gzip.open(fastaFile) header = f.readline() strRes = f.read().upper().replace('\n', '').replace('\r', '') f.close() fn = '%s/chromosome%s.dat' % (targetDir, chromosome.number) f = open(fn, 'w') f.write(strRes) f.close() chromosome.dataFile = fn chromosome.header = header return len(strRes)
[ "def", "_importSequence", "(", "chromosome", ",", "fastaFile", ",", "targetDir", ")", ":", "f", "=", "gzip", ".", "open", "(", "fastaFile", ")", "header", "=", "f", ".", "readline", "(", ")", "strRes", "=", "f", ".", "read", "(", ")", ".", "upper", "(", ")", ".", "replace", "(", "'\\n'", ",", "''", ")", ".", "replace", "(", "'\\r'", ",", "''", ")", "f", ".", "close", "(", ")", "fn", "=", "'%s/chromosome%s.dat'", "%", "(", "targetDir", ",", "chromosome", ".", "number", ")", "f", "=", "open", "(", "fn", ",", "'w'", ")", "f", ".", "write", "(", "strRes", ")", "f", ".", "close", "(", ")", "chromosome", ".", "dataFile", "=", "fn", "chromosome", ".", "header", "=", "header", "return", "len", "(", "strRes", ")" ]
Serializes fastas into .dat files
[ "Serializes", "fastas", "into", ".", "dat", "files" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/importation/Genomes.py#L445-L459
tariqdaouda/pyGeno
pyGeno/configuration.py
createDefaultConfigFile
def createDefaultConfigFile() : """Creates a default configuration file""" s = "[pyGeno_config]\nsettings_dir=%s\nremote_location=%s" % (pyGeno_SETTINGS_DIR, pyGeno_REMOTE_LOCATION) f = open('%s/config.ini' % pyGeno_SETTINGS_DIR, 'w') f.write(s) f.close()
python
def createDefaultConfigFile() : """Creates a default configuration file""" s = "[pyGeno_config]\nsettings_dir=%s\nremote_location=%s" % (pyGeno_SETTINGS_DIR, pyGeno_REMOTE_LOCATION) f = open('%s/config.ini' % pyGeno_SETTINGS_DIR, 'w') f.write(s) f.close()
[ "def", "createDefaultConfigFile", "(", ")", ":", "s", "=", "\"[pyGeno_config]\\nsettings_dir=%s\\nremote_location=%s\"", "%", "(", "pyGeno_SETTINGS_DIR", ",", "pyGeno_REMOTE_LOCATION", ")", "f", "=", "open", "(", "'%s/config.ini'", "%", "pyGeno_SETTINGS_DIR", ",", "'w'", ")", "f", ".", "write", "(", "s", ")", "f", ".", "close", "(", ")" ]
Creates a default configuration file
[ "Creates", "a", "default", "configuration", "file" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/configuration.py#L46-L51
tariqdaouda/pyGeno
pyGeno/configuration.py
getSettingsPath
def getSettingsPath() : """Returns the path where the settings are stored""" parser = SafeConfigParser() try : parser.read(os.path.normpath(pyGeno_SETTINGS_DIR+'/config.ini')) return parser.get('pyGeno_config', 'settings_dir') except : createDefaultConfigFile() return getSettingsPath()
python
def getSettingsPath() : """Returns the path where the settings are stored""" parser = SafeConfigParser() try : parser.read(os.path.normpath(pyGeno_SETTINGS_DIR+'/config.ini')) return parser.get('pyGeno_config', 'settings_dir') except : createDefaultConfigFile() return getSettingsPath()
[ "def", "getSettingsPath", "(", ")", ":", "parser", "=", "SafeConfigParser", "(", ")", "try", ":", "parser", ".", "read", "(", "os", ".", "path", ".", "normpath", "(", "pyGeno_SETTINGS_DIR", "+", "'/config.ini'", ")", ")", "return", "parser", ".", "get", "(", "'pyGeno_config'", ",", "'settings_dir'", ")", "except", ":", "createDefaultConfigFile", "(", ")", "return", "getSettingsPath", "(", ")" ]
Returns the path where the settings are stored
[ "Returns", "the", "path", "where", "the", "settings", "are", "stored" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/configuration.py#L53-L61
tariqdaouda/pyGeno
pyGeno/configuration.py
pyGeno_init
def pyGeno_init() : """This function is automatically called at launch""" global db, dbConf global pyGeno_SETTINGS_PATH global pyGeno_RABA_DBFILE global pyGeno_DATA_PATH if not checkPythonVersion() : raise PythonVersionError("==> FATAL: pyGeno only works with python 2.7 and above, please upgrade your python version") if not os.path.exists(pyGeno_SETTINGS_DIR) : os.makedirs(pyGeno_SETTINGS_DIR) pyGeno_SETTINGS_PATH = getSettingsPath() pyGeno_RABA_DBFILE = os.path.normpath( os.path.join(pyGeno_SETTINGS_PATH, "pyGenoRaba.db") ) pyGeno_DATA_PATH = os.path.normpath( os.path.join(pyGeno_SETTINGS_PATH, "data") ) if not os.path.exists(pyGeno_SETTINGS_PATH) : os.makedirs(pyGeno_SETTINGS_PATH) if not os.path.exists(pyGeno_DATA_PATH) : os.makedirs(pyGeno_DATA_PATH) #launching the db rabaDB.rabaSetup.RabaConfiguration(pyGeno_RABA_NAMESPACE, pyGeno_RABA_DBFILE) db = rabaDB.rabaSetup.RabaConnection(pyGeno_RABA_NAMESPACE) dbConf = rabaDB.rabaSetup.RabaConfiguration(pyGeno_RABA_NAMESPACE)
python
def pyGeno_init() : """This function is automatically called at launch""" global db, dbConf global pyGeno_SETTINGS_PATH global pyGeno_RABA_DBFILE global pyGeno_DATA_PATH if not checkPythonVersion() : raise PythonVersionError("==> FATAL: pyGeno only works with python 2.7 and above, please upgrade your python version") if not os.path.exists(pyGeno_SETTINGS_DIR) : os.makedirs(pyGeno_SETTINGS_DIR) pyGeno_SETTINGS_PATH = getSettingsPath() pyGeno_RABA_DBFILE = os.path.normpath( os.path.join(pyGeno_SETTINGS_PATH, "pyGenoRaba.db") ) pyGeno_DATA_PATH = os.path.normpath( os.path.join(pyGeno_SETTINGS_PATH, "data") ) if not os.path.exists(pyGeno_SETTINGS_PATH) : os.makedirs(pyGeno_SETTINGS_PATH) if not os.path.exists(pyGeno_DATA_PATH) : os.makedirs(pyGeno_DATA_PATH) #launching the db rabaDB.rabaSetup.RabaConfiguration(pyGeno_RABA_NAMESPACE, pyGeno_RABA_DBFILE) db = rabaDB.rabaSetup.RabaConnection(pyGeno_RABA_NAMESPACE) dbConf = rabaDB.rabaSetup.RabaConfiguration(pyGeno_RABA_NAMESPACE)
[ "def", "pyGeno_init", "(", ")", ":", "global", "db", ",", "dbConf", "global", "pyGeno_SETTINGS_PATH", "global", "pyGeno_RABA_DBFILE", "global", "pyGeno_DATA_PATH", "if", "not", "checkPythonVersion", "(", ")", ":", "raise", "PythonVersionError", "(", "\"==> FATAL: pyGeno only works with python 2.7 and above, please upgrade your python version\"", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "pyGeno_SETTINGS_DIR", ")", ":", "os", ".", "makedirs", "(", "pyGeno_SETTINGS_DIR", ")", "pyGeno_SETTINGS_PATH", "=", "getSettingsPath", "(", ")", "pyGeno_RABA_DBFILE", "=", "os", ".", "path", ".", "normpath", "(", "os", ".", "path", ".", "join", "(", "pyGeno_SETTINGS_PATH", ",", "\"pyGenoRaba.db\"", ")", ")", "pyGeno_DATA_PATH", "=", "os", ".", "path", ".", "normpath", "(", "os", ".", "path", ".", "join", "(", "pyGeno_SETTINGS_PATH", ",", "\"data\"", ")", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "pyGeno_SETTINGS_PATH", ")", ":", "os", ".", "makedirs", "(", "pyGeno_SETTINGS_PATH", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "pyGeno_DATA_PATH", ")", ":", "os", ".", "makedirs", "(", "pyGeno_DATA_PATH", ")", "#launching the db", "rabaDB", ".", "rabaSetup", ".", "RabaConfiguration", "(", "pyGeno_RABA_NAMESPACE", ",", "pyGeno_RABA_DBFILE", ")", "db", "=", "rabaDB", ".", "rabaSetup", ".", "RabaConnection", "(", "pyGeno_RABA_NAMESPACE", ")", "dbConf", "=", "rabaDB", ".", "rabaSetup", ".", "RabaConfiguration", "(", "pyGeno_RABA_NAMESPACE", ")" ]
This function is automatically called at launch
[ "This", "function", "is", "automatically", "called", "at", "launch" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/configuration.py#L76-L104
tariqdaouda/pyGeno
pyGeno/Exon.py
Exon.pluck
def pluck(self) : """Returns a plucked object. Plucks the exon off the tree, set the value of self.transcript into str(self.transcript). This effectively disconnects the object and makes it much more lighter in case you'd like to pickle it""" e = copy.copy(self) e.transcript = str(self.transcript) return e
python
def pluck(self) : """Returns a plucked object. Plucks the exon off the tree, set the value of self.transcript into str(self.transcript). This effectively disconnects the object and makes it much more lighter in case you'd like to pickle it""" e = copy.copy(self) e.transcript = str(self.transcript) return e
[ "def", "pluck", "(", "self", ")", ":", "e", "=", "copy", ".", "copy", "(", "self", ")", "e", ".", "transcript", "=", "str", "(", "self", ".", "transcript", ")", "return", "e" ]
Returns a plucked object. Plucks the exon off the tree, set the value of self.transcript into str(self.transcript). This effectively disconnects the object and makes it much more lighter in case you'd like to pickle it
[ "Returns", "a", "plucked", "object", ".", "Plucks", "the", "exon", "off", "the", "tree", "set", "the", "value", "of", "self", ".", "transcript", "into", "str", "(", "self", ".", "transcript", ")", ".", "This", "effectively", "disconnects", "the", "object", "and", "makes", "it", "much", "more", "lighter", "in", "case", "you", "d", "like", "to", "pickle", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/Exon.py#L138-L143
tariqdaouda/pyGeno
pyGeno/Exon.py
Exon.previousExon
def previousExon(self) : """Returns the previous exon of the transcript, or None if there is none""" if self.number == 0 : return None try : return self.transcript.exons[self.number-1] except IndexError : return None
python
def previousExon(self) : """Returns the previous exon of the transcript, or None if there is none""" if self.number == 0 : return None try : return self.transcript.exons[self.number-1] except IndexError : return None
[ "def", "previousExon", "(", "self", ")", ":", "if", "self", ".", "number", "==", "0", ":", "return", "None", "try", ":", "return", "self", ".", "transcript", ".", "exons", "[", "self", ".", "number", "-", "1", "]", "except", "IndexError", ":", "return", "None" ]
Returns the previous exon of the transcript, or None if there is none
[ "Returns", "the", "previous", "exon", "of", "the", "transcript", "or", "None", "if", "there", "is", "none" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/Exon.py#L152-L161
tariqdaouda/pyGeno
pyGeno/tools/parsers/FastqTools.py
FastqFile.parseStr
def parseStr(self, st) : """Parses a string""" self.data = st.replace('\r', '\n') self.data = self.data.replace('\n\n', '\n') self.data = self.data.split('\n')
python
def parseStr(self, st) : """Parses a string""" self.data = st.replace('\r', '\n') self.data = self.data.replace('\n\n', '\n') self.data = self.data.split('\n')
[ "def", "parseStr", "(", "self", ",", "st", ")", ":", "self", ".", "data", "=", "st", ".", "replace", "(", "'\\r'", ",", "'\\n'", ")", "self", ".", "data", "=", "self", ".", "data", ".", "replace", "(", "'\\n\\n'", ",", "'\\n'", ")", "self", ".", "data", "=", "self", ".", "data", ".", "split", "(", "'\\n'", ")" ]
Parses a string
[ "Parses", "a", "string" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/FastqTools.py#L51-L55
tariqdaouda/pyGeno
pyGeno/tools/parsers/FastqTools.py
FastqFile.get
def get(self, li) : """returns the ith entry""" i = li*4 self.__splitEntry(i) return self.data[i]
python
def get(self, li) : """returns the ith entry""" i = li*4 self.__splitEntry(i) return self.data[i]
[ "def", "get", "(", "self", ",", "li", ")", ":", "i", "=", "li", "*", "4", "self", ".", "__splitEntry", "(", "i", ")", "return", "self", ".", "data", "[", "i", "]" ]
returns the ith entry
[ "returns", "the", "ith", "entry" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/FastqTools.py#L70-L74
tariqdaouda/pyGeno
pyGeno/tools/parsers/FastqTools.py
FastqFile.newEntry
def newEntry(self, ident = "", seq = "", plus = "", qual = "") : """Appends an empty entry at the end of the CSV and returns it""" e = FastqEntry() self.data.append(e) return e
python
def newEntry(self, ident = "", seq = "", plus = "", qual = "") : """Appends an empty entry at the end of the CSV and returns it""" e = FastqEntry() self.data.append(e) return e
[ "def", "newEntry", "(", "self", ",", "ident", "=", "\"\"", ",", "seq", "=", "\"\"", ",", "plus", "=", "\"\"", ",", "qual", "=", "\"\"", ")", ":", "e", "=", "FastqEntry", "(", ")", "self", ".", "data", ".", "append", "(", "e", ")", "return", "e" ]
Appends an empty entry at the end of the CSV and returns it
[ "Appends", "an", "empty", "entry", "at", "the", "end", "of", "the", "CSV", "and", "returns", "it" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/parsers/FastqTools.py#L76-L80
tariqdaouda/pyGeno
pyGeno/bootstrap.py
listRemoteDatawraps
def listRemoteDatawraps(location = conf.pyGeno_REMOTE_LOCATION) : """Lists all the datawraps availabe from a remote a remote location.""" loc = location + "/datawraps.json" response = urllib2.urlopen(loc) js = json.loads(response.read()) return js
python
def listRemoteDatawraps(location = conf.pyGeno_REMOTE_LOCATION) : """Lists all the datawraps availabe from a remote a remote location.""" loc = location + "/datawraps.json" response = urllib2.urlopen(loc) js = json.loads(response.read()) return js
[ "def", "listRemoteDatawraps", "(", "location", "=", "conf", ".", "pyGeno_REMOTE_LOCATION", ")", ":", "loc", "=", "location", "+", "\"/datawraps.json\"", "response", "=", "urllib2", ".", "urlopen", "(", "loc", ")", "js", "=", "json", ".", "loads", "(", "response", ".", "read", "(", ")", ")", "return", "js" ]
Lists all the datawraps availabe from a remote a remote location.
[ "Lists", "all", "the", "datawraps", "availabe", "from", "a", "remote", "a", "remote", "location", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L11-L17
tariqdaouda/pyGeno
pyGeno/bootstrap.py
printRemoteDatawraps
def printRemoteDatawraps(location = conf.pyGeno_REMOTE_LOCATION) : """ print all available datawraps from a remote location the location must have a datawraps.json in the following format:: { "Ordered": { "Reference genomes": { "Human" : ["GRCh37.75", "GRCh38.78"], "Mouse" : ["GRCm38.78"], }, "SNPs":{ } }, "Flat":{ "Reference genomes": { "GRCh37.75": "Human.GRCh37.75.tar.gz", "GRCh38.78": "Human.GRCh37.75.tar.gz", "GRCm38.78": "Mouse.GRCm38.78.tar.gz" }, "SNPs":{ } } } """ l = listRemoteDatawraps(location) printf("Available datawraps for bootstraping\n") print json.dumps(l["Ordered"], sort_keys=True, indent=4, separators=(',', ': '))
python
def printRemoteDatawraps(location = conf.pyGeno_REMOTE_LOCATION) : """ print all available datawraps from a remote location the location must have a datawraps.json in the following format:: { "Ordered": { "Reference genomes": { "Human" : ["GRCh37.75", "GRCh38.78"], "Mouse" : ["GRCm38.78"], }, "SNPs":{ } }, "Flat":{ "Reference genomes": { "GRCh37.75": "Human.GRCh37.75.tar.gz", "GRCh38.78": "Human.GRCh37.75.tar.gz", "GRCm38.78": "Mouse.GRCm38.78.tar.gz" }, "SNPs":{ } } } """ l = listRemoteDatawraps(location) printf("Available datawraps for bootstraping\n") print json.dumps(l["Ordered"], sort_keys=True, indent=4, separators=(',', ': '))
[ "def", "printRemoteDatawraps", "(", "location", "=", "conf", ".", "pyGeno_REMOTE_LOCATION", ")", ":", "l", "=", "listRemoteDatawraps", "(", "location", ")", "printf", "(", "\"Available datawraps for bootstraping\\n\"", ")", "print", "json", ".", "dumps", "(", "l", "[", "\"Ordered\"", "]", ",", "sort_keys", "=", "True", ",", "indent", "=", "4", ",", "separators", "=", "(", "','", ",", "': '", ")", ")" ]
print all available datawraps from a remote location the location must have a datawraps.json in the following format:: { "Ordered": { "Reference genomes": { "Human" : ["GRCh37.75", "GRCh38.78"], "Mouse" : ["GRCm38.78"], }, "SNPs":{ } }, "Flat":{ "Reference genomes": { "GRCh37.75": "Human.GRCh37.75.tar.gz", "GRCh38.78": "Human.GRCh37.75.tar.gz", "GRCm38.78": "Mouse.GRCm38.78.tar.gz" }, "SNPs":{ } } }
[ "print", "all", "available", "datawraps", "from", "a", "remote", "location", "the", "location", "must", "have", "a", "datawraps", ".", "json", "in", "the", "following", "format", "::" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L19-L47
tariqdaouda/pyGeno
pyGeno/bootstrap.py
importRemoteGenome
def importRemoteGenome(name, batchSize = 100) : """Import a genome available from http://pygeno.iric.ca (might work).""" try : dw = listRemoteDatawraps()["Flat"]["Reference genomes"][name] except AttributeError : raise AttributeError("There's no remote genome datawrap by the name of: '%s'" % name) finalFile = _DW(name, dw["url"]) PG.importGenome(finalFile, batchSize)
python
def importRemoteGenome(name, batchSize = 100) : """Import a genome available from http://pygeno.iric.ca (might work).""" try : dw = listRemoteDatawraps()["Flat"]["Reference genomes"][name] except AttributeError : raise AttributeError("There's no remote genome datawrap by the name of: '%s'" % name) finalFile = _DW(name, dw["url"]) PG.importGenome(finalFile, batchSize)
[ "def", "importRemoteGenome", "(", "name", ",", "batchSize", "=", "100", ")", ":", "try", ":", "dw", "=", "listRemoteDatawraps", "(", ")", "[", "\"Flat\"", "]", "[", "\"Reference genomes\"", "]", "[", "name", "]", "except", "AttributeError", ":", "raise", "AttributeError", "(", "\"There's no remote genome datawrap by the name of: '%s'\"", "%", "name", ")", "finalFile", "=", "_DW", "(", "name", ",", "dw", "[", "\"url\"", "]", ")", "PG", ".", "importGenome", "(", "finalFile", ",", "batchSize", ")" ]
Import a genome available from http://pygeno.iric.ca (might work).
[ "Import", "a", "genome", "available", "from", "http", ":", "//", "pygeno", ".", "iric", ".", "ca", "(", "might", "work", ")", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L58-L66
tariqdaouda/pyGeno
pyGeno/bootstrap.py
importRemoteSNPs
def importRemoteSNPs(name) : """Import a SNP set available from http://pygeno.iric.ca (might work).""" try : dw = listRemoteDatawraps()["Flat"]["SNPs"] except AttributeError : raise AttributeError("There's no remote genome datawrap by the name of: '%s'" % name) finalFile = _DW(name, dw["url"]) PS.importSNPs(finalFile)
python
def importRemoteSNPs(name) : """Import a SNP set available from http://pygeno.iric.ca (might work).""" try : dw = listRemoteDatawraps()["Flat"]["SNPs"] except AttributeError : raise AttributeError("There's no remote genome datawrap by the name of: '%s'" % name) finalFile = _DW(name, dw["url"]) PS.importSNPs(finalFile)
[ "def", "importRemoteSNPs", "(", "name", ")", ":", "try", ":", "dw", "=", "listRemoteDatawraps", "(", ")", "[", "\"Flat\"", "]", "[", "\"SNPs\"", "]", "except", "AttributeError", ":", "raise", "AttributeError", "(", "\"There's no remote genome datawrap by the name of: '%s'\"", "%", "name", ")", "finalFile", "=", "_DW", "(", "name", ",", "dw", "[", "\"url\"", "]", ")", "PS", ".", "importSNPs", "(", "finalFile", ")" ]
Import a SNP set available from http://pygeno.iric.ca (might work).
[ "Import", "a", "SNP", "set", "available", "from", "http", ":", "//", "pygeno", ".", "iric", ".", "ca", "(", "might", "work", ")", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L68-L76
tariqdaouda/pyGeno
pyGeno/bootstrap.py
listDatawraps
def listDatawraps() : """Lists all the datawraps pyGeno comes with""" l = {"Genomes" : [], "SNPs" : []} for f in os.listdir(os.path.join(this_dir, "bootstrap_data/genomes")) : if f.find(".tar.gz") > -1 : l["Genomes"].append(f) for f in os.listdir(os.path.join(this_dir, "bootstrap_data/SNPs")) : if f.find(".tar.gz") > -1 : l["SNPs"].append(f) return l
python
def listDatawraps() : """Lists all the datawraps pyGeno comes with""" l = {"Genomes" : [], "SNPs" : []} for f in os.listdir(os.path.join(this_dir, "bootstrap_data/genomes")) : if f.find(".tar.gz") > -1 : l["Genomes"].append(f) for f in os.listdir(os.path.join(this_dir, "bootstrap_data/SNPs")) : if f.find(".tar.gz") > -1 : l["SNPs"].append(f) return l
[ "def", "listDatawraps", "(", ")", ":", "l", "=", "{", "\"Genomes\"", ":", "[", "]", ",", "\"SNPs\"", ":", "[", "]", "}", "for", "f", "in", "os", ".", "listdir", "(", "os", ".", "path", ".", "join", "(", "this_dir", ",", "\"bootstrap_data/genomes\"", ")", ")", ":", "if", "f", ".", "find", "(", "\".tar.gz\"", ")", ">", "-", "1", ":", "l", "[", "\"Genomes\"", "]", ".", "append", "(", "f", ")", "for", "f", "in", "os", ".", "listdir", "(", "os", ".", "path", ".", "join", "(", "this_dir", ",", "\"bootstrap_data/SNPs\"", ")", ")", ":", "if", "f", ".", "find", "(", "\".tar.gz\"", ")", ">", "-", "1", ":", "l", "[", "\"SNPs\"", "]", ".", "append", "(", "f", ")", "return", "l" ]
Lists all the datawraps pyGeno comes with
[ "Lists", "all", "the", "datawraps", "pyGeno", "comes", "with" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L78-L89
tariqdaouda/pyGeno
pyGeno/bootstrap.py
printDatawraps
def printDatawraps() : """print all available datawraps for bootstraping""" l = listDatawraps() printf("Available datawraps for boostraping\n") for k, v in l.iteritems() : printf(k) printf("~"*len(k) + "|") for vv in v : printf(" "*len(k) + "|" + "~~~:> " + vv) printf('\n')
python
def printDatawraps() : """print all available datawraps for bootstraping""" l = listDatawraps() printf("Available datawraps for boostraping\n") for k, v in l.iteritems() : printf(k) printf("~"*len(k) + "|") for vv in v : printf(" "*len(k) + "|" + "~~~:> " + vv) printf('\n')
[ "def", "printDatawraps", "(", ")", ":", "l", "=", "listDatawraps", "(", ")", "printf", "(", "\"Available datawraps for boostraping\\n\"", ")", "for", "k", ",", "v", "in", "l", ".", "iteritems", "(", ")", ":", "printf", "(", "k", ")", "printf", "(", "\"~\"", "*", "len", "(", "k", ")", "+", "\"|\"", ")", "for", "vv", "in", "v", ":", "printf", "(", "\" \"", "*", "len", "(", "k", ")", "+", "\"|\"", "+", "\"~~~:> \"", "+", "vv", ")", "printf", "(", "'\\n'", ")" ]
print all available datawraps for bootstraping
[ "print", "all", "available", "datawraps", "for", "bootstraping" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L91-L100
tariqdaouda/pyGeno
pyGeno/bootstrap.py
importGenome
def importGenome(name, batchSize = 100) : """Import a genome shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.""" path = os.path.join(this_dir, "bootstrap_data", "genomes/" + name) PG.importGenome(path, batchSize)
python
def importGenome(name, batchSize = 100) : """Import a genome shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.""" path = os.path.join(this_dir, "bootstrap_data", "genomes/" + name) PG.importGenome(path, batchSize)
[ "def", "importGenome", "(", "name", ",", "batchSize", "=", "100", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "this_dir", ",", "\"bootstrap_data\"", ",", "\"genomes/\"", "+", "name", ")", "PG", ".", "importGenome", "(", "path", ",", "batchSize", ")" ]
Import a genome shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.
[ "Import", "a", "genome", "shipped", "with", "pyGeno", ".", "Most", "of", "the", "datawraps", "only", "contain", "URLs", "towards", "data", "provided", "by", "third", "parties", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L102-L105
tariqdaouda/pyGeno
pyGeno/bootstrap.py
importSNPs
def importSNPs(name) : """Import a SNP set shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.""" path = os.path.join(this_dir, "bootstrap_data", "SNPs/" + name) PS.importSNPs(path)
python
def importSNPs(name) : """Import a SNP set shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.""" path = os.path.join(this_dir, "bootstrap_data", "SNPs/" + name) PS.importSNPs(path)
[ "def", "importSNPs", "(", "name", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "this_dir", ",", "\"bootstrap_data\"", ",", "\"SNPs/\"", "+", "name", ")", "PS", ".", "importSNPs", "(", "path", ")" ]
Import a SNP set shipped with pyGeno. Most of the datawraps only contain URLs towards data provided by third parties.
[ "Import", "a", "SNP", "set", "shipped", "with", "pyGeno", ".", "Most", "of", "the", "datawraps", "only", "contain", "URLs", "towards", "data", "provided", "by", "third", "parties", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/bootstrap.py#L107-L110
tariqdaouda/pyGeno
pyGeno/tools/ProgressBar.py
ProgressBar.log
def log(self) : """logs stats about the progression, without printing anything on screen""" self.logs['epochDuration'].append(self.lastEpochDuration) self.logs['avg'].append(self.avg) self.logs['runtime'].append(self.runtime) self.logs['remtime'].append(self.remtime)
python
def log(self) : """logs stats about the progression, without printing anything on screen""" self.logs['epochDuration'].append(self.lastEpochDuration) self.logs['avg'].append(self.avg) self.logs['runtime'].append(self.runtime) self.logs['remtime'].append(self.remtime)
[ "def", "log", "(", "self", ")", ":", "self", ".", "logs", "[", "'epochDuration'", "]", ".", "append", "(", "self", ".", "lastEpochDuration", ")", "self", ".", "logs", "[", "'avg'", "]", ".", "append", "(", "self", ".", "avg", ")", "self", ".", "logs", "[", "'runtime'", "]", ".", "append", "(", "self", ".", "runtime", ")", "self", ".", "logs", "[", "'remtime'", "]", ".", "append", "(", "self", ".", "remtime", ")" ]
logs stats about the progression, without printing anything on screen
[ "logs", "stats", "about", "the", "progression", "without", "printing", "anything", "on", "screen" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/ProgressBar.py#L60-L66
tariqdaouda/pyGeno
pyGeno/tools/ProgressBar.py
ProgressBar.saveLogs
def saveLogs(self, filename) : """dumps logs into a nice pickle""" f = open(filename, 'wb') cPickle.dump(self.logs, f) f.close()
python
def saveLogs(self, filename) : """dumps logs into a nice pickle""" f = open(filename, 'wb') cPickle.dump(self.logs, f) f.close()
[ "def", "saveLogs", "(", "self", ",", "filename", ")", ":", "f", "=", "open", "(", "filename", ",", "'wb'", ")", "cPickle", ".", "dump", "(", "self", ".", "logs", ",", "f", ")", "f", ".", "close", "(", ")" ]
dumps logs into a nice pickle
[ "dumps", "logs", "into", "a", "nice", "pickle" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/ProgressBar.py#L68-L72
tariqdaouda/pyGeno
pyGeno/tools/ProgressBar.py
ProgressBar.update
def update(self, label = '', forceRefresh = False, log = False) : """the function to be called at each iteration. Setting log = True is the same as calling log() just after update()""" self.currEpoch += 1 tim = time.time() if (tim - self.lastPrintTime > self.minRefeshTime) or forceRefresh : self._update() wheelState = self.wheel[self.currEpoch%len(self.wheel)] if label == '' : slabel = self.label else : slabel = label if self.nbEpochs > 1 : ratio = self.currEpoch/self.nbEpochs snakeLen = int(self.width*ratio) voidLen = int(self.width - (self.width*ratio)) if snakeLen + voidLen < self.width : snakeLen = self.width - voidLen self.bar = "%s %s[%s:>%s] %.2f%% (%d/%d) runtime: %s, remaining: %s, avg: %s" %(wheelState, slabel, "~-" * snakeLen, " " * voidLen, ratio*100, self.currEpoch, self.nbEpochs, self.runtime_hr, self.remtime_hr, self.formatTime(self.avg)) if self.currEpoch == self.nbEpochs : self.close() else : w = self.width - len(self.miniSnake) v = self.currEpoch%(w+1) snake = "%s%s%s" %(" " * (v), self.miniSnake, " " * (w-v)) self.bar = "%s %s[%s] %s%% (%d/%s) runtime: %s, remaining: %s, avg: %s" %(wheelState, slabel, snake, '?', self.currEpoch, '?', self.runtime_hr, '?', self.formatTime(self.avg)) sys.stdout.write("\b" * (len(self.bar)+1)) sys.stdout.write(" " * (len(self.bar)+1)) sys.stdout.write("\b" * (len(self.bar)+1)) sys.stdout.write(self.bar) sys.stdout.flush() self.lastPrintTime = time.time() if log : self.log()
python
def update(self, label = '', forceRefresh = False, log = False) : """the function to be called at each iteration. Setting log = True is the same as calling log() just after update()""" self.currEpoch += 1 tim = time.time() if (tim - self.lastPrintTime > self.minRefeshTime) or forceRefresh : self._update() wheelState = self.wheel[self.currEpoch%len(self.wheel)] if label == '' : slabel = self.label else : slabel = label if self.nbEpochs > 1 : ratio = self.currEpoch/self.nbEpochs snakeLen = int(self.width*ratio) voidLen = int(self.width - (self.width*ratio)) if snakeLen + voidLen < self.width : snakeLen = self.width - voidLen self.bar = "%s %s[%s:>%s] %.2f%% (%d/%d) runtime: %s, remaining: %s, avg: %s" %(wheelState, slabel, "~-" * snakeLen, " " * voidLen, ratio*100, self.currEpoch, self.nbEpochs, self.runtime_hr, self.remtime_hr, self.formatTime(self.avg)) if self.currEpoch == self.nbEpochs : self.close() else : w = self.width - len(self.miniSnake) v = self.currEpoch%(w+1) snake = "%s%s%s" %(" " * (v), self.miniSnake, " " * (w-v)) self.bar = "%s %s[%s] %s%% (%d/%s) runtime: %s, remaining: %s, avg: %s" %(wheelState, slabel, snake, '?', self.currEpoch, '?', self.runtime_hr, '?', self.formatTime(self.avg)) sys.stdout.write("\b" * (len(self.bar)+1)) sys.stdout.write(" " * (len(self.bar)+1)) sys.stdout.write("\b" * (len(self.bar)+1)) sys.stdout.write(self.bar) sys.stdout.flush() self.lastPrintTime = time.time() if log : self.log()
[ "def", "update", "(", "self", ",", "label", "=", "''", ",", "forceRefresh", "=", "False", ",", "log", "=", "False", ")", ":", "self", ".", "currEpoch", "+=", "1", "tim", "=", "time", ".", "time", "(", ")", "if", "(", "tim", "-", "self", ".", "lastPrintTime", ">", "self", ".", "minRefeshTime", ")", "or", "forceRefresh", ":", "self", ".", "_update", "(", ")", "wheelState", "=", "self", ".", "wheel", "[", "self", ".", "currEpoch", "%", "len", "(", "self", ".", "wheel", ")", "]", "if", "label", "==", "''", ":", "slabel", "=", "self", ".", "label", "else", ":", "slabel", "=", "label", "if", "self", ".", "nbEpochs", ">", "1", ":", "ratio", "=", "self", ".", "currEpoch", "/", "self", ".", "nbEpochs", "snakeLen", "=", "int", "(", "self", ".", "width", "*", "ratio", ")", "voidLen", "=", "int", "(", "self", ".", "width", "-", "(", "self", ".", "width", "*", "ratio", ")", ")", "if", "snakeLen", "+", "voidLen", "<", "self", ".", "width", ":", "snakeLen", "=", "self", ".", "width", "-", "voidLen", "self", ".", "bar", "=", "\"%s %s[%s:>%s] %.2f%% (%d/%d) runtime: %s, remaining: %s, avg: %s\"", "%", "(", "wheelState", ",", "slabel", ",", "\"~-\"", "*", "snakeLen", ",", "\" \"", "*", "voidLen", ",", "ratio", "*", "100", ",", "self", ".", "currEpoch", ",", "self", ".", "nbEpochs", ",", "self", ".", "runtime_hr", ",", "self", ".", "remtime_hr", ",", "self", ".", "formatTime", "(", "self", ".", "avg", ")", ")", "if", "self", ".", "currEpoch", "==", "self", ".", "nbEpochs", ":", "self", ".", "close", "(", ")", "else", ":", "w", "=", "self", ".", "width", "-", "len", "(", "self", ".", "miniSnake", ")", "v", "=", "self", ".", "currEpoch", "%", "(", "w", "+", "1", ")", "snake", "=", "\"%s%s%s\"", "%", "(", "\" \"", "*", "(", "v", ")", ",", "self", ".", "miniSnake", ",", "\" \"", "*", "(", "w", "-", "v", ")", ")", "self", ".", "bar", "=", "\"%s %s[%s] %s%% (%d/%s) runtime: %s, remaining: %s, avg: %s\"", "%", "(", "wheelState", ",", "slabel", ",", "snake", ",", "'?'", ",", "self", ".", "currEpoch", ",", "'?'", ",", "self", ".", "runtime_hr", ",", "'?'", ",", "self", ".", "formatTime", "(", "self", ".", "avg", ")", ")", "sys", ".", "stdout", ".", "write", "(", "\"\\b\"", "*", "(", "len", "(", "self", ".", "bar", ")", "+", "1", ")", ")", "sys", ".", "stdout", ".", "write", "(", "\" \"", "*", "(", "len", "(", "self", ".", "bar", ")", "+", "1", ")", ")", "sys", ".", "stdout", ".", "write", "(", "\"\\b\"", "*", "(", "len", "(", "self", ".", "bar", ")", "+", "1", ")", ")", "sys", ".", "stdout", ".", "write", "(", "self", ".", "bar", ")", "sys", ".", "stdout", ".", "flush", "(", ")", "self", ".", "lastPrintTime", "=", "time", ".", "time", "(", ")", "if", "log", ":", "self", ".", "log", "(", ")" ]
the function to be called at each iteration. Setting log = True is the same as calling log() just after update()
[ "the", "function", "to", "be", "called", "at", "each", "iteration", ".", "Setting", "log", "=", "True", "is", "the", "same", "as", "calling", "log", "()", "just", "after", "update", "()" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/ProgressBar.py#L74-L114
tariqdaouda/pyGeno
pyGeno/SNPFiltering.py
DefaultSNPFilter.filter
def filter(self, chromosome, **kwargs) : """The default filter mixes applied all SNPs and ignores Insertions and Deletions.""" def appendAllele(alleles, sources, snp) : pos = snp.start if snp.alt[0] == '-' : pass # print warn % ('DELETION', snpSet, snp.start, snp.chromosomeNumber) elif snp.ref[0] == '-' : pass # print warn % ('INSERTION', snpSet, snp.start, snp.chromosomeNumber) else : sources[snpSet] = snp alleles.append(snp.alt) #if not an indel append the polymorphism refAllele = chromosome.refSequence[pos] alleles.append(refAllele) sources['ref'] = refAllele return alleles, sources warn = 'Warning: the default snp filter ignores indels. IGNORED %s of SNP set: %s at pos: %s of chromosome: %s' sources = {} alleles = [] for snpSet, data in kwargs.iteritems() : if type(data) is list : for snp in data : alleles, sources = appendAllele(alleles, sources, snp) else : allels, sources = appendAllele(alleles, sources, data) #appends the refence allele to the lot #optional we keep a record of the polymorphisms that were used during the process return SequenceSNP(alleles, sources = sources)
python
def filter(self, chromosome, **kwargs) : """The default filter mixes applied all SNPs and ignores Insertions and Deletions.""" def appendAllele(alleles, sources, snp) : pos = snp.start if snp.alt[0] == '-' : pass # print warn % ('DELETION', snpSet, snp.start, snp.chromosomeNumber) elif snp.ref[0] == '-' : pass # print warn % ('INSERTION', snpSet, snp.start, snp.chromosomeNumber) else : sources[snpSet] = snp alleles.append(snp.alt) #if not an indel append the polymorphism refAllele = chromosome.refSequence[pos] alleles.append(refAllele) sources['ref'] = refAllele return alleles, sources warn = 'Warning: the default snp filter ignores indels. IGNORED %s of SNP set: %s at pos: %s of chromosome: %s' sources = {} alleles = [] for snpSet, data in kwargs.iteritems() : if type(data) is list : for snp in data : alleles, sources = appendAllele(alleles, sources, snp) else : allels, sources = appendAllele(alleles, sources, data) #appends the refence allele to the lot #optional we keep a record of the polymorphisms that were used during the process return SequenceSNP(alleles, sources = sources)
[ "def", "filter", "(", "self", ",", "chromosome", ",", "*", "*", "kwargs", ")", ":", "def", "appendAllele", "(", "alleles", ",", "sources", ",", "snp", ")", ":", "pos", "=", "snp", ".", "start", "if", "snp", ".", "alt", "[", "0", "]", "==", "'-'", ":", "pass", "# print warn % ('DELETION', snpSet, snp.start, snp.chromosomeNumber)", "elif", "snp", ".", "ref", "[", "0", "]", "==", "'-'", ":", "pass", "# print warn % ('INSERTION', snpSet, snp.start, snp.chromosomeNumber)", "else", ":", "sources", "[", "snpSet", "]", "=", "snp", "alleles", ".", "append", "(", "snp", ".", "alt", ")", "#if not an indel append the polymorphism", "refAllele", "=", "chromosome", ".", "refSequence", "[", "pos", "]", "alleles", ".", "append", "(", "refAllele", ")", "sources", "[", "'ref'", "]", "=", "refAllele", "return", "alleles", ",", "sources", "warn", "=", "'Warning: the default snp filter ignores indels. IGNORED %s of SNP set: %s at pos: %s of chromosome: %s'", "sources", "=", "{", "}", "alleles", "=", "[", "]", "for", "snpSet", ",", "data", "in", "kwargs", ".", "iteritems", "(", ")", ":", "if", "type", "(", "data", ")", "is", "list", ":", "for", "snp", "in", "data", ":", "alleles", ",", "sources", "=", "appendAllele", "(", "alleles", ",", "sources", ",", "snp", ")", "else", ":", "allels", ",", "sources", "=", "appendAllele", "(", "alleles", ",", "sources", ",", "data", ")", "#appends the refence allele to the lot", "#optional we keep a record of the polymorphisms that were used during the process", "return", "SequenceSNP", "(", "alleles", ",", "sources", "=", "sources", ")" ]
The default filter mixes applied all SNPs and ignores Insertions and Deletions.
[ "The", "default", "filter", "mixes", "applied", "all", "SNPs", "and", "ignores", "Insertions", "and", "Deletions", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/SNPFiltering.py#L105-L137
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
aux_insertTree
def aux_insertTree(childTree, parentTree): """This a private (You shouldn't have to call it) recursive function that inserts a child tree into a parent tree.""" if childTree.x1 != None and childTree.x2 != None : parentTree.insert(childTree.x1, childTree.x2, childTree.name, childTree.referedObject) for c in childTree.children: aux_insertTree(c, parentTree)
python
def aux_insertTree(childTree, parentTree): """This a private (You shouldn't have to call it) recursive function that inserts a child tree into a parent tree.""" if childTree.x1 != None and childTree.x2 != None : parentTree.insert(childTree.x1, childTree.x2, childTree.name, childTree.referedObject) for c in childTree.children: aux_insertTree(c, parentTree)
[ "def", "aux_insertTree", "(", "childTree", ",", "parentTree", ")", ":", "if", "childTree", ".", "x1", "!=", "None", "and", "childTree", ".", "x2", "!=", "None", ":", "parentTree", ".", "insert", "(", "childTree", ".", "x1", ",", "childTree", ".", "x2", ",", "childTree", ".", "name", ",", "childTree", ".", "referedObject", ")", "for", "c", "in", "childTree", ".", "children", ":", "aux_insertTree", "(", "c", ",", "parentTree", ")" ]
This a private (You shouldn't have to call it) recursive function that inserts a child tree into a parent tree.
[ "This", "a", "private", "(", "You", "shouldn", "t", "have", "to", "call", "it", ")", "recursive", "function", "that", "inserts", "a", "child", "tree", "into", "a", "parent", "tree", "." ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L3-L9
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
aux_moveTree
def aux_moveTree(offset, tree): """This a private recursive (You shouldn't have to call it) function that translates tree(and it's children) to a given x1""" if tree.x1 != None and tree.x2 != None : tree.x1, tree.x2 = tree.x1+offset, tree.x2+offset for c in tree.children: aux_moveTree(offset, c)
python
def aux_moveTree(offset, tree): """This a private recursive (You shouldn't have to call it) function that translates tree(and it's children) to a given x1""" if tree.x1 != None and tree.x2 != None : tree.x1, tree.x2 = tree.x1+offset, tree.x2+offset for c in tree.children: aux_moveTree(offset, c)
[ "def", "aux_moveTree", "(", "offset", ",", "tree", ")", ":", "if", "tree", ".", "x1", "!=", "None", "and", "tree", ".", "x2", "!=", "None", ":", "tree", ".", "x1", ",", "tree", ".", "x2", "=", "tree", ".", "x1", "+", "offset", ",", "tree", ".", "x2", "+", "offset", "for", "c", "in", "tree", ".", "children", ":", "aux_moveTree", "(", "offset", ",", "c", ")" ]
This a private recursive (You shouldn't have to call it) function that translates tree(and it's children) to a given x1
[ "This", "a", "private", "recursive", "(", "You", "shouldn", "t", "have", "to", "call", "it", ")", "function", "that", "translates", "tree", "(", "and", "it", "s", "children", ")", "to", "a", "given", "x1" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L11-L17
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.insert
def insert(self, x1, x2, name = '', referedObject = []) : """Insert the segment in it's right place and returns it. If there's already a segment S as S.x1 == x1 and S.x2 == x2. S.name will be changed to 'S.name U name' and the referedObject will be appended to the already existing list""" if x1 > x2 : xx1, xx2 = x2, x1 else : xx1, xx2 = x1, x2 rt = None insertId = None childrenToRemove = [] for i in range(len(self.children)) : if self.children[i].x1 == xx1 and xx2 == self.children[i].x2 : self.children[i].name = self.children[i].name + ' U ' + name self.children[i].referedObject.append(referedObject) return self.children[i] if self.children[i].x1 <= xx1 and xx2 <= self.children[i].x2 : return self.children[i].insert(x1, x2, name, referedObject) elif xx1 <= self.children[i].x1 and self.children[i].x2 <= xx2 : if rt == None : if type(referedObject) is types.ListType : rt = SegmentTree(xx1, xx2, name, referedObject, self, self.level+1) else : rt = SegmentTree(xx1, xx2, name, [referedObject], self, self.level+1) insertId = i rt.__addChild(self.children[i]) self.children[i].father = rt childrenToRemove.append(self.children[i]) elif xx1 <= self.children[i].x1 and xx2 <= self.children[i].x2 : insertId = i break if rt != None : self.__addChild(rt, insertId) for c in childrenToRemove : self.children.remove(c) else : if type(referedObject) is types.ListType : rt = SegmentTree(xx1, xx2, name, referedObject, self, self.level+1) else : rt = SegmentTree(xx1, xx2, name, [referedObject], self, self.level+1) if insertId != None : self.__addChild(rt, insertId) else : self.__addChild(rt) return rt
python
def insert(self, x1, x2, name = '', referedObject = []) : """Insert the segment in it's right place and returns it. If there's already a segment S as S.x1 == x1 and S.x2 == x2. S.name will be changed to 'S.name U name' and the referedObject will be appended to the already existing list""" if x1 > x2 : xx1, xx2 = x2, x1 else : xx1, xx2 = x1, x2 rt = None insertId = None childrenToRemove = [] for i in range(len(self.children)) : if self.children[i].x1 == xx1 and xx2 == self.children[i].x2 : self.children[i].name = self.children[i].name + ' U ' + name self.children[i].referedObject.append(referedObject) return self.children[i] if self.children[i].x1 <= xx1 and xx2 <= self.children[i].x2 : return self.children[i].insert(x1, x2, name, referedObject) elif xx1 <= self.children[i].x1 and self.children[i].x2 <= xx2 : if rt == None : if type(referedObject) is types.ListType : rt = SegmentTree(xx1, xx2, name, referedObject, self, self.level+1) else : rt = SegmentTree(xx1, xx2, name, [referedObject], self, self.level+1) insertId = i rt.__addChild(self.children[i]) self.children[i].father = rt childrenToRemove.append(self.children[i]) elif xx1 <= self.children[i].x1 and xx2 <= self.children[i].x2 : insertId = i break if rt != None : self.__addChild(rt, insertId) for c in childrenToRemove : self.children.remove(c) else : if type(referedObject) is types.ListType : rt = SegmentTree(xx1, xx2, name, referedObject, self, self.level+1) else : rt = SegmentTree(xx1, xx2, name, [referedObject], self, self.level+1) if insertId != None : self.__addChild(rt, insertId) else : self.__addChild(rt) return rt
[ "def", "insert", "(", "self", ",", "x1", ",", "x2", ",", "name", "=", "''", ",", "referedObject", "=", "[", "]", ")", ":", "if", "x1", ">", "x2", ":", "xx1", ",", "xx2", "=", "x2", ",", "x1", "else", ":", "xx1", ",", "xx2", "=", "x1", ",", "x2", "rt", "=", "None", "insertId", "=", "None", "childrenToRemove", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "self", ".", "children", ")", ")", ":", "if", "self", ".", "children", "[", "i", "]", ".", "x1", "==", "xx1", "and", "xx2", "==", "self", ".", "children", "[", "i", "]", ".", "x2", ":", "self", ".", "children", "[", "i", "]", ".", "name", "=", "self", ".", "children", "[", "i", "]", ".", "name", "+", "' U '", "+", "name", "self", ".", "children", "[", "i", "]", ".", "referedObject", ".", "append", "(", "referedObject", ")", "return", "self", ".", "children", "[", "i", "]", "if", "self", ".", "children", "[", "i", "]", ".", "x1", "<=", "xx1", "and", "xx2", "<=", "self", ".", "children", "[", "i", "]", ".", "x2", ":", "return", "self", ".", "children", "[", "i", "]", ".", "insert", "(", "x1", ",", "x2", ",", "name", ",", "referedObject", ")", "elif", "xx1", "<=", "self", ".", "children", "[", "i", "]", ".", "x1", "and", "self", ".", "children", "[", "i", "]", ".", "x2", "<=", "xx2", ":", "if", "rt", "==", "None", ":", "if", "type", "(", "referedObject", ")", "is", "types", ".", "ListType", ":", "rt", "=", "SegmentTree", "(", "xx1", ",", "xx2", ",", "name", ",", "referedObject", ",", "self", ",", "self", ".", "level", "+", "1", ")", "else", ":", "rt", "=", "SegmentTree", "(", "xx1", ",", "xx2", ",", "name", ",", "[", "referedObject", "]", ",", "self", ",", "self", ".", "level", "+", "1", ")", "insertId", "=", "i", "rt", ".", "__addChild", "(", "self", ".", "children", "[", "i", "]", ")", "self", ".", "children", "[", "i", "]", ".", "father", "=", "rt", "childrenToRemove", ".", "append", "(", "self", ".", "children", "[", "i", "]", ")", "elif", "xx1", "<=", "self", ".", "children", "[", "i", "]", ".", "x1", "and", "xx2", "<=", "self", ".", "children", "[", "i", "]", ".", "x2", ":", "insertId", "=", "i", "break", "if", "rt", "!=", "None", ":", "self", ".", "__addChild", "(", "rt", ",", "insertId", ")", "for", "c", "in", "childrenToRemove", ":", "self", ".", "children", ".", "remove", "(", "c", ")", "else", ":", "if", "type", "(", "referedObject", ")", "is", "types", ".", "ListType", ":", "rt", "=", "SegmentTree", "(", "xx1", ",", "xx2", ",", "name", ",", "referedObject", ",", "self", ",", "self", ".", "level", "+", "1", ")", "else", ":", "rt", "=", "SegmentTree", "(", "xx1", ",", "xx2", ",", "name", ",", "[", "referedObject", "]", ",", "self", ",", "self", ".", "level", "+", "1", ")", "if", "insertId", "!=", "None", ":", "self", ".", "__addChild", "(", "rt", ",", "insertId", ")", "else", ":", "self", ".", "__addChild", "(", "rt", ")", "return", "rt" ]
Insert the segment in it's right place and returns it. If there's already a segment S as S.x1 == x1 and S.x2 == x2. S.name will be changed to 'S.name U name' and the referedObject will be appended to the already existing list
[ "Insert", "the", "segment", "in", "it", "s", "right", "place", "and", "returns", "it", ".", "If", "there", "s", "already", "a", "segment", "S", "as", "S", ".", "x1", "==", "x1", "and", "S", ".", "x2", "==", "x2", ".", "S", ".", "name", "will", "be", "changed", "to", "S", ".", "name", "U", "name", "and", "the", "referedObject", "will", "be", "appended", "to", "the", "already", "existing", "list" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L77-L131
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.intersect
def intersect(self, x1, x2 = None) : """Returns a list of all segments intersected by [x1, x2]""" def condition(x1, x2, tree) : #print self.id, tree.x1, tree.x2, x1, x2 if (tree.x1 != None and tree.x2 != None) and (tree.x1 <= x1 and x1 < tree.x2 or tree.x1 <= x2 and x2 < tree.x2) : return True return False if x2 == None : xx1, xx2 = x1, x1 elif x1 > x2 : xx1, xx2 = x2, x1 else : xx1, xx2 = x1, x2 c1 = self.__dichotomicSearch(xx1) c2 = self.__dichotomicSearch(xx2) if c1 == -1 or c2 == -1 : return [] if xx1 < self.children[c1].x1 : c1 -= 1 inter = self.__radiateDown(x1, x2, c1, condition) if self.children[c1].id == self.children[c2].id : inter.extend(self.__radiateUp(x1, x2, c2+1, condition)) else : inter.extend(self.__radiateUp(x1, x2, c2, condition)) ret = [] for c in inter : ret.extend(c.intersect(x1, x2)) inter.extend(ret) return inter
python
def intersect(self, x1, x2 = None) : """Returns a list of all segments intersected by [x1, x2]""" def condition(x1, x2, tree) : #print self.id, tree.x1, tree.x2, x1, x2 if (tree.x1 != None and tree.x2 != None) and (tree.x1 <= x1 and x1 < tree.x2 or tree.x1 <= x2 and x2 < tree.x2) : return True return False if x2 == None : xx1, xx2 = x1, x1 elif x1 > x2 : xx1, xx2 = x2, x1 else : xx1, xx2 = x1, x2 c1 = self.__dichotomicSearch(xx1) c2 = self.__dichotomicSearch(xx2) if c1 == -1 or c2 == -1 : return [] if xx1 < self.children[c1].x1 : c1 -= 1 inter = self.__radiateDown(x1, x2, c1, condition) if self.children[c1].id == self.children[c2].id : inter.extend(self.__radiateUp(x1, x2, c2+1, condition)) else : inter.extend(self.__radiateUp(x1, x2, c2, condition)) ret = [] for c in inter : ret.extend(c.intersect(x1, x2)) inter.extend(ret) return inter
[ "def", "intersect", "(", "self", ",", "x1", ",", "x2", "=", "None", ")", ":", "def", "condition", "(", "x1", ",", "x2", ",", "tree", ")", ":", "#print self.id, tree.x1, tree.x2, x1, x2", "if", "(", "tree", ".", "x1", "!=", "None", "and", "tree", ".", "x2", "!=", "None", ")", "and", "(", "tree", ".", "x1", "<=", "x1", "and", "x1", "<", "tree", ".", "x2", "or", "tree", ".", "x1", "<=", "x2", "and", "x2", "<", "tree", ".", "x2", ")", ":", "return", "True", "return", "False", "if", "x2", "==", "None", ":", "xx1", ",", "xx2", "=", "x1", ",", "x1", "elif", "x1", ">", "x2", ":", "xx1", ",", "xx2", "=", "x2", ",", "x1", "else", ":", "xx1", ",", "xx2", "=", "x1", ",", "x2", "c1", "=", "self", ".", "__dichotomicSearch", "(", "xx1", ")", "c2", "=", "self", ".", "__dichotomicSearch", "(", "xx2", ")", "if", "c1", "==", "-", "1", "or", "c2", "==", "-", "1", ":", "return", "[", "]", "if", "xx1", "<", "self", ".", "children", "[", "c1", "]", ".", "x1", ":", "c1", "-=", "1", "inter", "=", "self", ".", "__radiateDown", "(", "x1", ",", "x2", ",", "c1", ",", "condition", ")", "if", "self", ".", "children", "[", "c1", "]", ".", "id", "==", "self", ".", "children", "[", "c2", "]", ".", "id", ":", "inter", ".", "extend", "(", "self", ".", "__radiateUp", "(", "x1", ",", "x2", ",", "c2", "+", "1", ",", "condition", ")", ")", "else", ":", "inter", ".", "extend", "(", "self", ".", "__radiateUp", "(", "x1", ",", "x2", ",", "c2", ",", "condition", ")", ")", "ret", "=", "[", "]", "for", "c", "in", "inter", ":", "ret", ".", "extend", "(", "c", ".", "intersect", "(", "x1", ",", "x2", ")", ")", "inter", ".", "extend", "(", "ret", ")", "return", "inter" ]
Returns a list of all segments intersected by [x1, x2]
[ "Returns", "a", "list", "of", "all", "segments", "intersected", "by", "[", "x1", "x2", "]" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L141-L177
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.__radiateDown
def __radiateDown(self, x1, x2, childId, condition) : "Radiates down: walks self.children downward until condition is no longer verifed or there's no childrens left " ret = [] i = childId while 0 <= i : if condition(x1, x2, self.children[i]) : ret.append(self.children[i]) else : break i -= 1 return ret
python
def __radiateDown(self, x1, x2, childId, condition) : "Radiates down: walks self.children downward until condition is no longer verifed or there's no childrens left " ret = [] i = childId while 0 <= i : if condition(x1, x2, self.children[i]) : ret.append(self.children[i]) else : break i -= 1 return ret
[ "def", "__radiateDown", "(", "self", ",", "x1", ",", "x2", ",", "childId", ",", "condition", ")", ":", "ret", "=", "[", "]", "i", "=", "childId", "while", "0", "<=", "i", ":", "if", "condition", "(", "x1", ",", "x2", ",", "self", ".", "children", "[", "i", "]", ")", ":", "ret", ".", "append", "(", "self", ".", "children", "[", "i", "]", ")", "else", ":", "break", "i", "-=", "1", "return", "ret" ]
Radiates down: walks self.children downward until condition is no longer verifed or there's no childrens left
[ "Radiates", "down", ":", "walks", "self", ".", "children", "downward", "until", "condition", "is", "no", "longer", "verifed", "or", "there", "s", "no", "childrens", "left" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L196-L206
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.__radiateUp
def __radiateUp(self, x1, x2, childId, condition) : "Radiates uo: walks self.children upward until condition is no longer verifed or there's no childrens left " ret = [] i = childId while i < len(self.children): if condition(x1, x2, self.children[i]) : ret.append(self.children[i]) else : break i += 1 return ret
python
def __radiateUp(self, x1, x2, childId, condition) : "Radiates uo: walks self.children upward until condition is no longer verifed or there's no childrens left " ret = [] i = childId while i < len(self.children): if condition(x1, x2, self.children[i]) : ret.append(self.children[i]) else : break i += 1 return ret
[ "def", "__radiateUp", "(", "self", ",", "x1", ",", "x2", ",", "childId", ",", "condition", ")", ":", "ret", "=", "[", "]", "i", "=", "childId", "while", "i", "<", "len", "(", "self", ".", "children", ")", ":", "if", "condition", "(", "x1", ",", "x2", ",", "self", ".", "children", "[", "i", "]", ")", ":", "ret", ".", "append", "(", "self", ".", "children", "[", "i", "]", ")", "else", ":", "break", "i", "+=", "1", "return", "ret" ]
Radiates uo: walks self.children upward until condition is no longer verifed or there's no childrens left
[ "Radiates", "uo", ":", "walks", "self", ".", "children", "upward", "until", "condition", "is", "no", "longer", "verifed", "or", "there", "s", "no", "childrens", "left" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L208-L218
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.removeGaps
def removeGaps(self) : """Remove all gaps between regions""" for i in range(1, len(self.children)) : if self.children[i].x1 > self.children[i-1].x2: aux_moveTree(self.children[i-1].x2-self.children[i].x1, self.children[i])
python
def removeGaps(self) : """Remove all gaps between regions""" for i in range(1, len(self.children)) : if self.children[i].x1 > self.children[i-1].x2: aux_moveTree(self.children[i-1].x2-self.children[i].x1, self.children[i])
[ "def", "removeGaps", "(", "self", ")", ":", "for", "i", "in", "range", "(", "1", ",", "len", "(", "self", ".", "children", ")", ")", ":", "if", "self", ".", "children", "[", "i", "]", ".", "x1", ">", "self", ".", "children", "[", "i", "-", "1", "]", ".", "x2", ":", "aux_moveTree", "(", "self", ".", "children", "[", "i", "-", "1", "]", ".", "x2", "-", "self", ".", "children", "[", "i", "]", ".", "x1", ",", "self", ".", "children", "[", "i", "]", ")" ]
Remove all gaps between regions
[ "Remove", "all", "gaps", "between", "regions" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L224-L229
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.getIndexedLength
def getIndexedLength(self) : """Returns the total length of indexed regions""" if self.x1 != None and self.x2 != None: return self.x2 - self.x1 else : if len(self.children) == 0 : return 0 else : l = self.children[0].x2 - self.children[0].x1 for i in range(1, len(self.children)) : l += self.children[i].x2 - self.children[i].x1 - max(0, self.children[i-1].x2 - self.children[i].x1) return l
python
def getIndexedLength(self) : """Returns the total length of indexed regions""" if self.x1 != None and self.x2 != None: return self.x2 - self.x1 else : if len(self.children) == 0 : return 0 else : l = self.children[0].x2 - self.children[0].x1 for i in range(1, len(self.children)) : l += self.children[i].x2 - self.children[i].x1 - max(0, self.children[i-1].x2 - self.children[i].x1) return l
[ "def", "getIndexedLength", "(", "self", ")", ":", "if", "self", ".", "x1", "!=", "None", "and", "self", ".", "x2", "!=", "None", ":", "return", "self", ".", "x2", "-", "self", ".", "x1", "else", ":", "if", "len", "(", "self", ".", "children", ")", "==", "0", ":", "return", "0", "else", ":", "l", "=", "self", ".", "children", "[", "0", "]", ".", "x2", "-", "self", ".", "children", "[", "0", "]", ".", "x1", "for", "i", "in", "range", "(", "1", ",", "len", "(", "self", ".", "children", ")", ")", ":", "l", "+=", "self", ".", "children", "[", "i", "]", ".", "x2", "-", "self", ".", "children", "[", "i", "]", ".", "x1", "-", "max", "(", "0", ",", "self", ".", "children", "[", "i", "-", "1", "]", ".", "x2", "-", "self", ".", "children", "[", "i", "]", ".", "x1", ")", "return", "l" ]
Returns the total length of indexed regions
[ "Returns", "the", "total", "length", "of", "indexed", "regions" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L243-L254
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.getFirstLevel
def getFirstLevel(self) : """returns a list of couples (x1, x2) of all the first level indexed regions""" res = [] if len(self.children) > 0 : for c in self.children: res.append((c.x1, c.x2)) else : if self.x1 != None : res = [(self.x1, self.x2)] else : res = None return res
python
def getFirstLevel(self) : """returns a list of couples (x1, x2) of all the first level indexed regions""" res = [] if len(self.children) > 0 : for c in self.children: res.append((c.x1, c.x2)) else : if self.x1 != None : res = [(self.x1, self.x2)] else : res = None return res
[ "def", "getFirstLevel", "(", "self", ")", ":", "res", "=", "[", "]", "if", "len", "(", "self", ".", "children", ")", ">", "0", ":", "for", "c", "in", "self", ".", "children", ":", "res", ".", "append", "(", "(", "c", ".", "x1", ",", "c", ".", "x2", ")", ")", "else", ":", "if", "self", ".", "x1", "!=", "None", ":", "res", "=", "[", "(", "self", ".", "x1", ",", "self", ".", "x2", ")", "]", "else", ":", "res", "=", "None", "return", "res" ]
returns a list of couples (x1, x2) of all the first level indexed regions
[ "returns", "a", "list", "of", "couples", "(", "x1", "x2", ")", "of", "all", "the", "first", "level", "indexed", "regions" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L256-L267
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.flatten
def flatten(self) : """Flattens the tree. The tree become a tree of depth 1 where overlapping regions have been merged together""" if len(self.children) > 1 : children = self.children self.emptyChildren() children[0].emptyChildren() x1 = children[0].x1 x2 = children[0].x2 refObjs = [children[0].referedObject] name = children[0].name for i in range(1, len(children)) : children[i].emptyChildren() if children[i-1] >= children[i] : x2 = children[i].x2 refObjs.append(children[i].referedObject) name += " U " + children[i].name else : if len(refObjs) == 1 : refObjs = refObjs[0] self.insert(x1, x2, name, refObjs) x1 = children[i].x1 x2 = children[i].x2 refObjs = [children[i].referedObject] name = children[i].name if len(refObjs) == 1 : refObjs = refObjs[0] self.insert(x1, x2, name, refObjs)
python
def flatten(self) : """Flattens the tree. The tree become a tree of depth 1 where overlapping regions have been merged together""" if len(self.children) > 1 : children = self.children self.emptyChildren() children[0].emptyChildren() x1 = children[0].x1 x2 = children[0].x2 refObjs = [children[0].referedObject] name = children[0].name for i in range(1, len(children)) : children[i].emptyChildren() if children[i-1] >= children[i] : x2 = children[i].x2 refObjs.append(children[i].referedObject) name += " U " + children[i].name else : if len(refObjs) == 1 : refObjs = refObjs[0] self.insert(x1, x2, name, refObjs) x1 = children[i].x1 x2 = children[i].x2 refObjs = [children[i].referedObject] name = children[i].name if len(refObjs) == 1 : refObjs = refObjs[0] self.insert(x1, x2, name, refObjs)
[ "def", "flatten", "(", "self", ")", ":", "if", "len", "(", "self", ".", "children", ")", ">", "1", ":", "children", "=", "self", ".", "children", "self", ".", "emptyChildren", "(", ")", "children", "[", "0", "]", ".", "emptyChildren", "(", ")", "x1", "=", "children", "[", "0", "]", ".", "x1", "x2", "=", "children", "[", "0", "]", ".", "x2", "refObjs", "=", "[", "children", "[", "0", "]", ".", "referedObject", "]", "name", "=", "children", "[", "0", "]", ".", "name", "for", "i", "in", "range", "(", "1", ",", "len", "(", "children", ")", ")", ":", "children", "[", "i", "]", ".", "emptyChildren", "(", ")", "if", "children", "[", "i", "-", "1", "]", ">=", "children", "[", "i", "]", ":", "x2", "=", "children", "[", "i", "]", ".", "x2", "refObjs", ".", "append", "(", "children", "[", "i", "]", ".", "referedObject", ")", "name", "+=", "\" U \"", "+", "children", "[", "i", "]", ".", "name", "else", ":", "if", "len", "(", "refObjs", ")", "==", "1", ":", "refObjs", "=", "refObjs", "[", "0", "]", "self", ".", "insert", "(", "x1", ",", "x2", ",", "name", ",", "refObjs", ")", "x1", "=", "children", "[", "i", "]", ".", "x1", "x2", "=", "children", "[", "i", "]", ".", "x2", "refObjs", "=", "[", "children", "[", "i", "]", ".", "referedObject", "]", "name", "=", "children", "[", "i", "]", ".", "name", "if", "len", "(", "refObjs", ")", "==", "1", ":", "refObjs", "=", "refObjs", "[", "0", "]", "self", ".", "insert", "(", "x1", ",", "x2", ",", "name", ",", "refObjs", ")" ]
Flattens the tree. The tree become a tree of depth 1 where overlapping regions have been merged together
[ "Flattens", "the", "tree", ".", "The", "tree", "become", "a", "tree", "of", "depth", "1", "where", "overlapping", "regions", "have", "been", "merged", "together" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L269-L300
tariqdaouda/pyGeno
pyGeno/tools/SegmentTree.py
SegmentTree.move
def move(self, newX1) : """Moves tree to a new starting position, updates x1s of children""" if self.x1 != None and self.x2 != None : offset = newX1-self.x1 aux_moveTree(offset, self) elif len(self.children) > 0 : offset = newX1-self.children[0].x1 aux_moveTree(offset, self)
python
def move(self, newX1) : """Moves tree to a new starting position, updates x1s of children""" if self.x1 != None and self.x2 != None : offset = newX1-self.x1 aux_moveTree(offset, self) elif len(self.children) > 0 : offset = newX1-self.children[0].x1 aux_moveTree(offset, self)
[ "def", "move", "(", "self", ",", "newX1", ")", ":", "if", "self", ".", "x1", "!=", "None", "and", "self", ".", "x2", "!=", "None", ":", "offset", "=", "newX1", "-", "self", ".", "x1", "aux_moveTree", "(", "offset", ",", "self", ")", "elif", "len", "(", "self", ".", "children", ")", ">", "0", ":", "offset", "=", "newX1", "-", "self", ".", "children", "[", "0", "]", ".", "x1", "aux_moveTree", "(", "offset", ",", "self", ")" ]
Moves tree to a new starting position, updates x1s of children
[ "Moves", "tree", "to", "a", "new", "starting", "position", "updates", "x1s", "of", "children" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/SegmentTree.py#L302-L309
tariqdaouda/pyGeno
pyGeno/tools/BinarySequence.py
BinarySequence.encode
def encode(self, sequence): """Returns a tuple (binary reprensentation, default sequence, polymorphisms list)""" polymorphisms = [] defaultSequence = '' binSequence = array.array(self.forma.typecode) b = 0 i = 0 trueI = 0 #not inc in case if poly poly = set() while i < len(sequence)-1: b = b | self.forma[self.charToBin[sequence[i]]] if sequence[i+1] == '/' : poly.add(sequence[i]) i += 2 else : binSequence.append(b) if len(poly) > 0 : poly.add(sequence[i]) polymorphisms.append((trueI, poly)) poly = set() bb = 0 while b % 2 != 0 : b = b/2 defaultSequence += sequence[i] b = 0 i += 1 trueI += 1 if i < len(sequence) : b = b | self.forma[self.charToBin[sequence[i]]] binSequence.append(b) if len(poly) > 0 : if sequence[i] not in poly : poly.add(sequence[i]) polymorphisms.append((trueI, poly)) defaultSequence += sequence[i] return (binSequence, defaultSequence, polymorphisms)
python
def encode(self, sequence): """Returns a tuple (binary reprensentation, default sequence, polymorphisms list)""" polymorphisms = [] defaultSequence = '' binSequence = array.array(self.forma.typecode) b = 0 i = 0 trueI = 0 #not inc in case if poly poly = set() while i < len(sequence)-1: b = b | self.forma[self.charToBin[sequence[i]]] if sequence[i+1] == '/' : poly.add(sequence[i]) i += 2 else : binSequence.append(b) if len(poly) > 0 : poly.add(sequence[i]) polymorphisms.append((trueI, poly)) poly = set() bb = 0 while b % 2 != 0 : b = b/2 defaultSequence += sequence[i] b = 0 i += 1 trueI += 1 if i < len(sequence) : b = b | self.forma[self.charToBin[sequence[i]]] binSequence.append(b) if len(poly) > 0 : if sequence[i] not in poly : poly.add(sequence[i]) polymorphisms.append((trueI, poly)) defaultSequence += sequence[i] return (binSequence, defaultSequence, polymorphisms)
[ "def", "encode", "(", "self", ",", "sequence", ")", ":", "polymorphisms", "=", "[", "]", "defaultSequence", "=", "''", "binSequence", "=", "array", ".", "array", "(", "self", ".", "forma", ".", "typecode", ")", "b", "=", "0", "i", "=", "0", "trueI", "=", "0", "#not inc in case if poly", "poly", "=", "set", "(", ")", "while", "i", "<", "len", "(", "sequence", ")", "-", "1", ":", "b", "=", "b", "|", "self", ".", "forma", "[", "self", ".", "charToBin", "[", "sequence", "[", "i", "]", "]", "]", "if", "sequence", "[", "i", "+", "1", "]", "==", "'/'", ":", "poly", ".", "add", "(", "sequence", "[", "i", "]", ")", "i", "+=", "2", "else", ":", "binSequence", ".", "append", "(", "b", ")", "if", "len", "(", "poly", ")", ">", "0", ":", "poly", ".", "add", "(", "sequence", "[", "i", "]", ")", "polymorphisms", ".", "append", "(", "(", "trueI", ",", "poly", ")", ")", "poly", "=", "set", "(", ")", "bb", "=", "0", "while", "b", "%", "2", "!=", "0", ":", "b", "=", "b", "/", "2", "defaultSequence", "+=", "sequence", "[", "i", "]", "b", "=", "0", "i", "+=", "1", "trueI", "+=", "1", "if", "i", "<", "len", "(", "sequence", ")", ":", "b", "=", "b", "|", "self", ".", "forma", "[", "self", ".", "charToBin", "[", "sequence", "[", "i", "]", "]", "]", "binSequence", ".", "append", "(", "b", ")", "if", "len", "(", "poly", ")", ">", "0", ":", "if", "sequence", "[", "i", "]", "not", "in", "poly", ":", "poly", ".", "add", "(", "sequence", "[", "i", "]", ")", "polymorphisms", ".", "append", "(", "(", "trueI", ",", "poly", ")", ")", "defaultSequence", "+=", "sequence", "[", "i", "]", "return", "(", "binSequence", ",", "defaultSequence", ",", "polymorphisms", ")" ]
Returns a tuple (binary reprensentation, default sequence, polymorphisms list)
[ "Returns", "a", "tuple", "(", "binary", "reprensentation", "default", "sequence", "polymorphisms", "list", ")" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/BinarySequence.py#L21-L61
tariqdaouda/pyGeno
pyGeno/tools/BinarySequence.py
BinarySequence.findPolymorphisms
def findPolymorphisms(self, strSeq, strict = False): """ Compares strSeq with self.sequence. If not 'strict', this function ignores the cases of matching heterozygocity (ex: for a given position i, strSeq[i] = A and self.sequence[i] = 'A/G'). If 'strict' it returns all positions where strSeq differs self,sequence """ arr = self.encode(strSeq)[0] res = [] if not strict : for i in range(len(arr)+len(self)) : if i >= len(arr) or i > len(self) : break if arr[i] & self[i] == 0: res.append(i) else : for i in range(len(arr)+len(self)) : if i >= len(arr) or i > len(self) : break if arr[i] != self[i] : res.append(i) return res
python
def findPolymorphisms(self, strSeq, strict = False): """ Compares strSeq with self.sequence. If not 'strict', this function ignores the cases of matching heterozygocity (ex: for a given position i, strSeq[i] = A and self.sequence[i] = 'A/G'). If 'strict' it returns all positions where strSeq differs self,sequence """ arr = self.encode(strSeq)[0] res = [] if not strict : for i in range(len(arr)+len(self)) : if i >= len(arr) or i > len(self) : break if arr[i] & self[i] == 0: res.append(i) else : for i in range(len(arr)+len(self)) : if i >= len(arr) or i > len(self) : break if arr[i] != self[i] : res.append(i) return res
[ "def", "findPolymorphisms", "(", "self", ",", "strSeq", ",", "strict", "=", "False", ")", ":", "arr", "=", "self", ".", "encode", "(", "strSeq", ")", "[", "0", "]", "res", "=", "[", "]", "if", "not", "strict", ":", "for", "i", "in", "range", "(", "len", "(", "arr", ")", "+", "len", "(", "self", ")", ")", ":", "if", "i", ">=", "len", "(", "arr", ")", "or", "i", ">", "len", "(", "self", ")", ":", "break", "if", "arr", "[", "i", "]", "&", "self", "[", "i", "]", "==", "0", ":", "res", ".", "append", "(", "i", ")", "else", ":", "for", "i", "in", "range", "(", "len", "(", "arr", ")", "+", "len", "(", "self", ")", ")", ":", "if", "i", ">=", "len", "(", "arr", ")", "or", "i", ">", "len", "(", "self", ")", ":", "break", "if", "arr", "[", "i", "]", "!=", "self", "[", "i", "]", ":", "res", ".", "append", "(", "i", ")", "return", "res" ]
Compares strSeq with self.sequence. If not 'strict', this function ignores the cases of matching heterozygocity (ex: for a given position i, strSeq[i] = A and self.sequence[i] = 'A/G'). If 'strict' it returns all positions where strSeq differs self,sequence
[ "Compares", "strSeq", "with", "self", ".", "sequence", ".", "If", "not", "strict", "this", "function", "ignores", "the", "cases", "of", "matching", "heterozygocity", "(", "ex", ":", "for", "a", "given", "position", "i", "strSeq", "[", "i", "]", "=", "A", "and", "self", ".", "sequence", "[", "i", "]", "=", "A", "/", "G", ")", ".", "If", "strict", "it", "returns", "all", "positions", "where", "strSeq", "differs", "self", "sequence" ]
train
https://github.com/tariqdaouda/pyGeno/blob/474b1250bf78ce5c7e7c3bbbfdbad9635d5a7d14/pyGeno/tools/BinarySequence.py#L75-L94