id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
228,300 | ecederstrand/exchangelib | exchangelib/services.py | GetFolder.call | def call(self, folders, additional_fields, shape):
"""
Takes a folder ID and returns the full information for that folder.
:param folders: a list of Folder objects
:param additional_fields: the extra fields that should be returned with the folder, as FieldPath objects
:param shape: The set of attributes to return
:return: XML elements for the folders, in stable order
"""
# We can't easily find the correct folder class from the returned XML. Instead, return objects with the same
# class as the folder instance it was requested with.
from .folders import Folder, DistinguishedFolderId, RootOfHierarchy
folders_list = list(folders) # Convert to a list, in case 'folders' is a generator
for folder, elem in zip(folders_list, self._get_elements(payload=self.get_payload(
folders=folders,
additional_fields=additional_fields,
shape=shape,
))):
if isinstance(elem, Exception):
yield elem
continue
if isinstance(folder, RootOfHierarchy):
f = folder.from_xml(elem=elem, account=self.account)
elif isinstance(folder, Folder):
f = folder.from_xml(elem=elem, root=folder.root)
elif isinstance(folder, DistinguishedFolderId):
# We don't know the root, so assume account.root.
for folder_cls in self.account.root.WELLKNOWN_FOLDERS:
if folder_cls.DISTINGUISHED_FOLDER_ID == folder.id:
break
else:
raise ValueError('Unknown distinguished folder ID: %s', folder.id)
f = folder_cls.from_xml(elem=elem, root=self.account.root)
else:
# 'folder' is a generic FolderId instance. We don't know the root so assume account.root.
f = Folder.from_xml(elem=elem, root=self.account.root)
if isinstance(folder, DistinguishedFolderId):
f.is_distinguished = True
elif isinstance(folder, Folder) and folder.is_distinguished:
f.is_distinguished = True
yield f | python | def call(self, folders, additional_fields, shape):
"""
Takes a folder ID and returns the full information for that folder.
:param folders: a list of Folder objects
:param additional_fields: the extra fields that should be returned with the folder, as FieldPath objects
:param shape: The set of attributes to return
:return: XML elements for the folders, in stable order
"""
# We can't easily find the correct folder class from the returned XML. Instead, return objects with the same
# class as the folder instance it was requested with.
from .folders import Folder, DistinguishedFolderId, RootOfHierarchy
folders_list = list(folders) # Convert to a list, in case 'folders' is a generator
for folder, elem in zip(folders_list, self._get_elements(payload=self.get_payload(
folders=folders,
additional_fields=additional_fields,
shape=shape,
))):
if isinstance(elem, Exception):
yield elem
continue
if isinstance(folder, RootOfHierarchy):
f = folder.from_xml(elem=elem, account=self.account)
elif isinstance(folder, Folder):
f = folder.from_xml(elem=elem, root=folder.root)
elif isinstance(folder, DistinguishedFolderId):
# We don't know the root, so assume account.root.
for folder_cls in self.account.root.WELLKNOWN_FOLDERS:
if folder_cls.DISTINGUISHED_FOLDER_ID == folder.id:
break
else:
raise ValueError('Unknown distinguished folder ID: %s', folder.id)
f = folder_cls.from_xml(elem=elem, root=self.account.root)
else:
# 'folder' is a generic FolderId instance. We don't know the root so assume account.root.
f = Folder.from_xml(elem=elem, root=self.account.root)
if isinstance(folder, DistinguishedFolderId):
f.is_distinguished = True
elif isinstance(folder, Folder) and folder.is_distinguished:
f.is_distinguished = True
yield f | [
"def",
"call",
"(",
"self",
",",
"folders",
",",
"additional_fields",
",",
"shape",
")",
":",
"# We can't easily find the correct folder class from the returned XML. Instead, return objects with the same",
"# class as the folder instance it was requested with.",
"from",
".",
"folders",
"import",
"Folder",
",",
"DistinguishedFolderId",
",",
"RootOfHierarchy",
"folders_list",
"=",
"list",
"(",
"folders",
")",
"# Convert to a list, in case 'folders' is a generator",
"for",
"folder",
",",
"elem",
"in",
"zip",
"(",
"folders_list",
",",
"self",
".",
"_get_elements",
"(",
"payload",
"=",
"self",
".",
"get_payload",
"(",
"folders",
"=",
"folders",
",",
"additional_fields",
"=",
"additional_fields",
",",
"shape",
"=",
"shape",
",",
")",
")",
")",
":",
"if",
"isinstance",
"(",
"elem",
",",
"Exception",
")",
":",
"yield",
"elem",
"continue",
"if",
"isinstance",
"(",
"folder",
",",
"RootOfHierarchy",
")",
":",
"f",
"=",
"folder",
".",
"from_xml",
"(",
"elem",
"=",
"elem",
",",
"account",
"=",
"self",
".",
"account",
")",
"elif",
"isinstance",
"(",
"folder",
",",
"Folder",
")",
":",
"f",
"=",
"folder",
".",
"from_xml",
"(",
"elem",
"=",
"elem",
",",
"root",
"=",
"folder",
".",
"root",
")",
"elif",
"isinstance",
"(",
"folder",
",",
"DistinguishedFolderId",
")",
":",
"# We don't know the root, so assume account.root.",
"for",
"folder_cls",
"in",
"self",
".",
"account",
".",
"root",
".",
"WELLKNOWN_FOLDERS",
":",
"if",
"folder_cls",
".",
"DISTINGUISHED_FOLDER_ID",
"==",
"folder",
".",
"id",
":",
"break",
"else",
":",
"raise",
"ValueError",
"(",
"'Unknown distinguished folder ID: %s'",
",",
"folder",
".",
"id",
")",
"f",
"=",
"folder_cls",
".",
"from_xml",
"(",
"elem",
"=",
"elem",
",",
"root",
"=",
"self",
".",
"account",
".",
"root",
")",
"else",
":",
"# 'folder' is a generic FolderId instance. We don't know the root so assume account.root.",
"f",
"=",
"Folder",
".",
"from_xml",
"(",
"elem",
"=",
"elem",
",",
"root",
"=",
"self",
".",
"account",
".",
"root",
")",
"if",
"isinstance",
"(",
"folder",
",",
"DistinguishedFolderId",
")",
":",
"f",
".",
"is_distinguished",
"=",
"True",
"elif",
"isinstance",
"(",
"folder",
",",
"Folder",
")",
"and",
"folder",
".",
"is_distinguished",
":",
"f",
".",
"is_distinguished",
"=",
"True",
"yield",
"f"
] | Takes a folder ID and returns the full information for that folder.
:param folders: a list of Folder objects
:param additional_fields: the extra fields that should be returned with the folder, as FieldPath objects
:param shape: The set of attributes to return
:return: XML elements for the folders, in stable order | [
"Takes",
"a",
"folder",
"ID",
"and",
"returns",
"the",
"full",
"information",
"for",
"that",
"folder",
"."
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/services.py#L1132-L1172 |
228,301 | ecederstrand/exchangelib | exchangelib/services.py | UploadItems.get_payload | def get_payload(self, items):
"""Upload given items to given account
data is an iterable of tuples where the first element is a Folder
instance representing the ParentFolder that the item will be placed in
and the second element is a Data string returned from an ExportItems
call.
"""
from .properties import ParentFolderId
uploaditems = create_element('m:%s' % self.SERVICE_NAME)
itemselement = create_element('m:Items')
uploaditems.append(itemselement)
for parent_folder, data_str in items:
item = create_element('t:Item', CreateAction='CreateNew')
parentfolderid = ParentFolderId(parent_folder.id, parent_folder.changekey)
set_xml_value(item, parentfolderid, version=self.account.version)
add_xml_child(item, 't:Data', data_str)
itemselement.append(item)
return uploaditems | python | def get_payload(self, items):
"""Upload given items to given account
data is an iterable of tuples where the first element is a Folder
instance representing the ParentFolder that the item will be placed in
and the second element is a Data string returned from an ExportItems
call.
"""
from .properties import ParentFolderId
uploaditems = create_element('m:%s' % self.SERVICE_NAME)
itemselement = create_element('m:Items')
uploaditems.append(itemselement)
for parent_folder, data_str in items:
item = create_element('t:Item', CreateAction='CreateNew')
parentfolderid = ParentFolderId(parent_folder.id, parent_folder.changekey)
set_xml_value(item, parentfolderid, version=self.account.version)
add_xml_child(item, 't:Data', data_str)
itemselement.append(item)
return uploaditems | [
"def",
"get_payload",
"(",
"self",
",",
"items",
")",
":",
"from",
".",
"properties",
"import",
"ParentFolderId",
"uploaditems",
"=",
"create_element",
"(",
"'m:%s'",
"%",
"self",
".",
"SERVICE_NAME",
")",
"itemselement",
"=",
"create_element",
"(",
"'m:Items'",
")",
"uploaditems",
".",
"append",
"(",
"itemselement",
")",
"for",
"parent_folder",
",",
"data_str",
"in",
"items",
":",
"item",
"=",
"create_element",
"(",
"'t:Item'",
",",
"CreateAction",
"=",
"'CreateNew'",
")",
"parentfolderid",
"=",
"ParentFolderId",
"(",
"parent_folder",
".",
"id",
",",
"parent_folder",
".",
"changekey",
")",
"set_xml_value",
"(",
"item",
",",
"parentfolderid",
",",
"version",
"=",
"self",
".",
"account",
".",
"version",
")",
"add_xml_child",
"(",
"item",
",",
"'t:Data'",
",",
"data_str",
")",
"itemselement",
".",
"append",
"(",
"item",
")",
"return",
"uploaditems"
] | Upload given items to given account
data is an iterable of tuples where the first element is a Folder
instance representing the ParentFolder that the item will be placed in
and the second element is a Data string returned from an ExportItems
call. | [
"Upload",
"given",
"items",
"to",
"given",
"account"
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/services.py#L1880-L1898 |
228,302 | ecederstrand/exchangelib | exchangelib/folders.py | FolderCollection.find_items | def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None,
calendar_view=None, page_size=None, max_items=None, offset=0):
"""
Private method to call the FindItem service
:param q: a Q instance containing any restrictions
:param shape: controls whether to return (id, chanegkey) tuples or Item objects. If additional_fields is
non-null, we always return Item objects.
:param depth: controls the whether to return soft-deleted items or not.
:param additional_fields: the extra properties we want on the return objects. Default is no properties. Be
aware that complex fields can only be fetched with fetch() (i.e. the GetItem service).
:param order_fields: the SortOrder fields, if any
:param calendar_view: a CalendarView instance, if any
:param page_size: the requested number of items per page
:param max_items: the max number of items to return
:param offset: the offset relative to the first item in the item collection
:return: a generator for the returned item IDs or items
"""
if shape not in SHAPE_CHOICES:
raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES))
if depth not in ITEM_TRAVERSAL_CHOICES:
raise ValueError("'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES))
if not self.folders:
log.debug('Folder list is empty')
return
if additional_fields:
for f in additional_fields:
self.validate_item_field(field=f)
for f in additional_fields:
if f.field.is_complex:
raise ValueError("find_items() does not support field '%s'. Use fetch() instead" % f.field.name)
if calendar_view is not None and not isinstance(calendar_view, CalendarView):
raise ValueError("'calendar_view' %s must be a CalendarView instance" % calendar_view)
# Build up any restrictions
if q.is_empty():
restriction = None
query_string = None
elif q.query_string:
restriction = None
query_string = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
else:
restriction = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
query_string = None
log.debug(
'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)',
self.folders,
self.account,
shape,
depth,
additional_fields,
restriction.q if restriction else None,
)
items = FindItem(account=self.account, folders=self.folders, chunk_size=page_size).call(
additional_fields=additional_fields,
restriction=restriction,
order_fields=order_fields,
shape=shape,
query_string=query_string,
depth=depth,
calendar_view=calendar_view,
max_items=calendar_view.max_items if calendar_view else max_items,
offset=offset,
)
if shape == ID_ONLY and additional_fields is None:
for i in items:
yield i if isinstance(i, Exception) else Item.id_from_xml(i)
else:
for i in items:
if isinstance(i, Exception):
yield i
else:
yield Folder.item_model_from_tag(i.tag).from_xml(elem=i, account=self.account) | python | def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None,
calendar_view=None, page_size=None, max_items=None, offset=0):
"""
Private method to call the FindItem service
:param q: a Q instance containing any restrictions
:param shape: controls whether to return (id, chanegkey) tuples or Item objects. If additional_fields is
non-null, we always return Item objects.
:param depth: controls the whether to return soft-deleted items or not.
:param additional_fields: the extra properties we want on the return objects. Default is no properties. Be
aware that complex fields can only be fetched with fetch() (i.e. the GetItem service).
:param order_fields: the SortOrder fields, if any
:param calendar_view: a CalendarView instance, if any
:param page_size: the requested number of items per page
:param max_items: the max number of items to return
:param offset: the offset relative to the first item in the item collection
:return: a generator for the returned item IDs or items
"""
if shape not in SHAPE_CHOICES:
raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES))
if depth not in ITEM_TRAVERSAL_CHOICES:
raise ValueError("'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES))
if not self.folders:
log.debug('Folder list is empty')
return
if additional_fields:
for f in additional_fields:
self.validate_item_field(field=f)
for f in additional_fields:
if f.field.is_complex:
raise ValueError("find_items() does not support field '%s'. Use fetch() instead" % f.field.name)
if calendar_view is not None and not isinstance(calendar_view, CalendarView):
raise ValueError("'calendar_view' %s must be a CalendarView instance" % calendar_view)
# Build up any restrictions
if q.is_empty():
restriction = None
query_string = None
elif q.query_string:
restriction = None
query_string = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
else:
restriction = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
query_string = None
log.debug(
'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)',
self.folders,
self.account,
shape,
depth,
additional_fields,
restriction.q if restriction else None,
)
items = FindItem(account=self.account, folders=self.folders, chunk_size=page_size).call(
additional_fields=additional_fields,
restriction=restriction,
order_fields=order_fields,
shape=shape,
query_string=query_string,
depth=depth,
calendar_view=calendar_view,
max_items=calendar_view.max_items if calendar_view else max_items,
offset=offset,
)
if shape == ID_ONLY and additional_fields is None:
for i in items:
yield i if isinstance(i, Exception) else Item.id_from_xml(i)
else:
for i in items:
if isinstance(i, Exception):
yield i
else:
yield Folder.item_model_from_tag(i.tag).from_xml(elem=i, account=self.account) | [
"def",
"find_items",
"(",
"self",
",",
"q",
",",
"shape",
"=",
"ID_ONLY",
",",
"depth",
"=",
"SHALLOW",
",",
"additional_fields",
"=",
"None",
",",
"order_fields",
"=",
"None",
",",
"calendar_view",
"=",
"None",
",",
"page_size",
"=",
"None",
",",
"max_items",
"=",
"None",
",",
"offset",
"=",
"0",
")",
":",
"if",
"shape",
"not",
"in",
"SHAPE_CHOICES",
":",
"raise",
"ValueError",
"(",
"\"'shape' %s must be one of %s\"",
"%",
"(",
"shape",
",",
"SHAPE_CHOICES",
")",
")",
"if",
"depth",
"not",
"in",
"ITEM_TRAVERSAL_CHOICES",
":",
"raise",
"ValueError",
"(",
"\"'depth' %s must be one of %s\"",
"%",
"(",
"depth",
",",
"ITEM_TRAVERSAL_CHOICES",
")",
")",
"if",
"not",
"self",
".",
"folders",
":",
"log",
".",
"debug",
"(",
"'Folder list is empty'",
")",
"return",
"if",
"additional_fields",
":",
"for",
"f",
"in",
"additional_fields",
":",
"self",
".",
"validate_item_field",
"(",
"field",
"=",
"f",
")",
"for",
"f",
"in",
"additional_fields",
":",
"if",
"f",
".",
"field",
".",
"is_complex",
":",
"raise",
"ValueError",
"(",
"\"find_items() does not support field '%s'. Use fetch() instead\"",
"%",
"f",
".",
"field",
".",
"name",
")",
"if",
"calendar_view",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"calendar_view",
",",
"CalendarView",
")",
":",
"raise",
"ValueError",
"(",
"\"'calendar_view' %s must be a CalendarView instance\"",
"%",
"calendar_view",
")",
"# Build up any restrictions",
"if",
"q",
".",
"is_empty",
"(",
")",
":",
"restriction",
"=",
"None",
"query_string",
"=",
"None",
"elif",
"q",
".",
"query_string",
":",
"restriction",
"=",
"None",
"query_string",
"=",
"Restriction",
"(",
"q",
",",
"folders",
"=",
"self",
".",
"folders",
",",
"applies_to",
"=",
"Restriction",
".",
"ITEMS",
")",
"else",
":",
"restriction",
"=",
"Restriction",
"(",
"q",
",",
"folders",
"=",
"self",
".",
"folders",
",",
"applies_to",
"=",
"Restriction",
".",
"ITEMS",
")",
"query_string",
"=",
"None",
"log",
".",
"debug",
"(",
"'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)'",
",",
"self",
".",
"folders",
",",
"self",
".",
"account",
",",
"shape",
",",
"depth",
",",
"additional_fields",
",",
"restriction",
".",
"q",
"if",
"restriction",
"else",
"None",
",",
")",
"items",
"=",
"FindItem",
"(",
"account",
"=",
"self",
".",
"account",
",",
"folders",
"=",
"self",
".",
"folders",
",",
"chunk_size",
"=",
"page_size",
")",
".",
"call",
"(",
"additional_fields",
"=",
"additional_fields",
",",
"restriction",
"=",
"restriction",
",",
"order_fields",
"=",
"order_fields",
",",
"shape",
"=",
"shape",
",",
"query_string",
"=",
"query_string",
",",
"depth",
"=",
"depth",
",",
"calendar_view",
"=",
"calendar_view",
",",
"max_items",
"=",
"calendar_view",
".",
"max_items",
"if",
"calendar_view",
"else",
"max_items",
",",
"offset",
"=",
"offset",
",",
")",
"if",
"shape",
"==",
"ID_ONLY",
"and",
"additional_fields",
"is",
"None",
":",
"for",
"i",
"in",
"items",
":",
"yield",
"i",
"if",
"isinstance",
"(",
"i",
",",
"Exception",
")",
"else",
"Item",
".",
"id_from_xml",
"(",
"i",
")",
"else",
":",
"for",
"i",
"in",
"items",
":",
"if",
"isinstance",
"(",
"i",
",",
"Exception",
")",
":",
"yield",
"i",
"else",
":",
"yield",
"Folder",
".",
"item_model_from_tag",
"(",
"i",
".",
"tag",
")",
".",
"from_xml",
"(",
"elem",
"=",
"i",
",",
"account",
"=",
"self",
".",
"account",
")"
] | Private method to call the FindItem service
:param q: a Q instance containing any restrictions
:param shape: controls whether to return (id, chanegkey) tuples or Item objects. If additional_fields is
non-null, we always return Item objects.
:param depth: controls the whether to return soft-deleted items or not.
:param additional_fields: the extra properties we want on the return objects. Default is no properties. Be
aware that complex fields can only be fetched with fetch() (i.e. the GetItem service).
:param order_fields: the SortOrder fields, if any
:param calendar_view: a CalendarView instance, if any
:param page_size: the requested number of items per page
:param max_items: the max number of items to return
:param offset: the offset relative to the first item in the item collection
:return: a generator for the returned item IDs or items | [
"Private",
"method",
"to",
"call",
"the",
"FindItem",
"service"
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/folders.py#L185-L257 |
228,303 | ecederstrand/exchangelib | exchangelib/folders.py | RootOfHierarchy.get_distinguished | def get_distinguished(cls, account):
"""Gets the distinguished folder for this folder class"""
if not cls.DISTINGUISHED_FOLDER_ID:
raise ValueError('Class %s must have a DISTINGUISHED_FOLDER_ID value' % cls)
folders = list(FolderCollection(
account=account,
folders=[cls(account=account, name=cls.DISTINGUISHED_FOLDER_ID, is_distinguished=True)]
).get_folders()
)
if not folders:
raise ErrorFolderNotFound('Could not find distinguished folder %s' % cls.DISTINGUISHED_FOLDER_ID)
if len(folders) != 1:
raise ValueError('Expected result length 1, but got %s' % folders)
folder = folders[0]
if isinstance(folder, Exception):
raise folder
if folder.__class__ != cls:
raise ValueError("Expected 'folder' %r to be a %s instance" % (folder, cls))
return folder | python | def get_distinguished(cls, account):
"""Gets the distinguished folder for this folder class"""
if not cls.DISTINGUISHED_FOLDER_ID:
raise ValueError('Class %s must have a DISTINGUISHED_FOLDER_ID value' % cls)
folders = list(FolderCollection(
account=account,
folders=[cls(account=account, name=cls.DISTINGUISHED_FOLDER_ID, is_distinguished=True)]
).get_folders()
)
if not folders:
raise ErrorFolderNotFound('Could not find distinguished folder %s' % cls.DISTINGUISHED_FOLDER_ID)
if len(folders) != 1:
raise ValueError('Expected result length 1, but got %s' % folders)
folder = folders[0]
if isinstance(folder, Exception):
raise folder
if folder.__class__ != cls:
raise ValueError("Expected 'folder' %r to be a %s instance" % (folder, cls))
return folder | [
"def",
"get_distinguished",
"(",
"cls",
",",
"account",
")",
":",
"if",
"not",
"cls",
".",
"DISTINGUISHED_FOLDER_ID",
":",
"raise",
"ValueError",
"(",
"'Class %s must have a DISTINGUISHED_FOLDER_ID value'",
"%",
"cls",
")",
"folders",
"=",
"list",
"(",
"FolderCollection",
"(",
"account",
"=",
"account",
",",
"folders",
"=",
"[",
"cls",
"(",
"account",
"=",
"account",
",",
"name",
"=",
"cls",
".",
"DISTINGUISHED_FOLDER_ID",
",",
"is_distinguished",
"=",
"True",
")",
"]",
")",
".",
"get_folders",
"(",
")",
")",
"if",
"not",
"folders",
":",
"raise",
"ErrorFolderNotFound",
"(",
"'Could not find distinguished folder %s'",
"%",
"cls",
".",
"DISTINGUISHED_FOLDER_ID",
")",
"if",
"len",
"(",
"folders",
")",
"!=",
"1",
":",
"raise",
"ValueError",
"(",
"'Expected result length 1, but got %s'",
"%",
"folders",
")",
"folder",
"=",
"folders",
"[",
"0",
"]",
"if",
"isinstance",
"(",
"folder",
",",
"Exception",
")",
":",
"raise",
"folder",
"if",
"folder",
".",
"__class__",
"!=",
"cls",
":",
"raise",
"ValueError",
"(",
"\"Expected 'folder' %r to be a %s instance\"",
"%",
"(",
"folder",
",",
"cls",
")",
")",
"return",
"folder"
] | Gets the distinguished folder for this folder class | [
"Gets",
"the",
"distinguished",
"folder",
"for",
"this",
"folder",
"class"
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/folders.py#L1489-L1507 |
228,304 | ecederstrand/exchangelib | exchangelib/folders.py | RootOfHierarchy.folder_cls_from_folder_name | def folder_cls_from_folder_name(cls, folder_name, locale):
"""Returns the folder class that matches a localized folder name.
locale is a string, e.g. 'da_DK'
"""
for folder_cls in cls.WELLKNOWN_FOLDERS + NON_DELETEABLE_FOLDERS:
if folder_name.lower() in folder_cls.localized_names(locale):
return folder_cls
raise KeyError() | python | def folder_cls_from_folder_name(cls, folder_name, locale):
"""Returns the folder class that matches a localized folder name.
locale is a string, e.g. 'da_DK'
"""
for folder_cls in cls.WELLKNOWN_FOLDERS + NON_DELETEABLE_FOLDERS:
if folder_name.lower() in folder_cls.localized_names(locale):
return folder_cls
raise KeyError() | [
"def",
"folder_cls_from_folder_name",
"(",
"cls",
",",
"folder_name",
",",
"locale",
")",
":",
"for",
"folder_cls",
"in",
"cls",
".",
"WELLKNOWN_FOLDERS",
"+",
"NON_DELETEABLE_FOLDERS",
":",
"if",
"folder_name",
".",
"lower",
"(",
")",
"in",
"folder_cls",
".",
"localized_names",
"(",
"locale",
")",
":",
"return",
"folder_cls",
"raise",
"KeyError",
"(",
")"
] | Returns the folder class that matches a localized folder name.
locale is a string, e.g. 'da_DK' | [
"Returns",
"the",
"folder",
"class",
"that",
"matches",
"a",
"localized",
"folder",
"name",
"."
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/folders.py#L1594-L1602 |
228,305 | ecederstrand/exchangelib | exchangelib/items.py | RegisterMixIn.register | def register(cls, attr_name, attr_cls):
"""
Register a custom extended property in this item class so they can be accessed just like any other attribute
"""
if not cls.INSERT_AFTER_FIELD:
raise ValueError('Class %s is missing INSERT_AFTER_FIELD value' % cls)
try:
cls.get_field_by_fieldname(attr_name)
except InvalidField:
pass
else:
raise ValueError("'%s' is already registered" % attr_name)
if not issubclass(attr_cls, ExtendedProperty):
raise ValueError("%r must be a subclass of ExtendedProperty" % attr_cls)
# Check if class attributes are properly defined
attr_cls.validate_cls()
# ExtendedProperty is not a real field, but a placeholder in the fields list. See
# https://msdn.microsoft.com/en-us/library/office/aa580790(v=exchg.150).aspx
#
# Find the correct index for the new extended property, and insert.
field = ExtendedPropertyField(attr_name, value_cls=attr_cls)
cls.add_field(field, insert_after=cls.INSERT_AFTER_FIELD) | python | def register(cls, attr_name, attr_cls):
"""
Register a custom extended property in this item class so they can be accessed just like any other attribute
"""
if not cls.INSERT_AFTER_FIELD:
raise ValueError('Class %s is missing INSERT_AFTER_FIELD value' % cls)
try:
cls.get_field_by_fieldname(attr_name)
except InvalidField:
pass
else:
raise ValueError("'%s' is already registered" % attr_name)
if not issubclass(attr_cls, ExtendedProperty):
raise ValueError("%r must be a subclass of ExtendedProperty" % attr_cls)
# Check if class attributes are properly defined
attr_cls.validate_cls()
# ExtendedProperty is not a real field, but a placeholder in the fields list. See
# https://msdn.microsoft.com/en-us/library/office/aa580790(v=exchg.150).aspx
#
# Find the correct index for the new extended property, and insert.
field = ExtendedPropertyField(attr_name, value_cls=attr_cls)
cls.add_field(field, insert_after=cls.INSERT_AFTER_FIELD) | [
"def",
"register",
"(",
"cls",
",",
"attr_name",
",",
"attr_cls",
")",
":",
"if",
"not",
"cls",
".",
"INSERT_AFTER_FIELD",
":",
"raise",
"ValueError",
"(",
"'Class %s is missing INSERT_AFTER_FIELD value'",
"%",
"cls",
")",
"try",
":",
"cls",
".",
"get_field_by_fieldname",
"(",
"attr_name",
")",
"except",
"InvalidField",
":",
"pass",
"else",
":",
"raise",
"ValueError",
"(",
"\"'%s' is already registered\"",
"%",
"attr_name",
")",
"if",
"not",
"issubclass",
"(",
"attr_cls",
",",
"ExtendedProperty",
")",
":",
"raise",
"ValueError",
"(",
"\"%r must be a subclass of ExtendedProperty\"",
"%",
"attr_cls",
")",
"# Check if class attributes are properly defined",
"attr_cls",
".",
"validate_cls",
"(",
")",
"# ExtendedProperty is not a real field, but a placeholder in the fields list. See",
"# https://msdn.microsoft.com/en-us/library/office/aa580790(v=exchg.150).aspx",
"#",
"# Find the correct index for the new extended property, and insert.",
"field",
"=",
"ExtendedPropertyField",
"(",
"attr_name",
",",
"value_cls",
"=",
"attr_cls",
")",
"cls",
".",
"add_field",
"(",
"field",
",",
"insert_after",
"=",
"cls",
".",
"INSERT_AFTER_FIELD",
")"
] | Register a custom extended property in this item class so they can be accessed just like any other attribute | [
"Register",
"a",
"custom",
"extended",
"property",
"in",
"this",
"item",
"class",
"so",
"they",
"can",
"be",
"accessed",
"just",
"like",
"any",
"other",
"attribute"
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/items.py#L92-L113 |
228,306 | ecederstrand/exchangelib | exchangelib/items.py | Item.attach | def attach(self, attachments):
"""Add an attachment, or a list of attachments, to this item. If the item has already been saved, the
attachments will be created on the server immediately. If the item has not yet been saved, the attachments will
be created on the server the item is saved.
Adding attachments to an existing item will update the changekey of the item.
"""
if not is_iterable(attachments, generators_allowed=True):
attachments = [attachments]
for a in attachments:
if not a.parent_item:
a.parent_item = self
if self.id and not a.attachment_id:
# Already saved object. Attach the attachment server-side now
a.attach()
if a not in self.attachments:
self.attachments.append(a) | python | def attach(self, attachments):
"""Add an attachment, or a list of attachments, to this item. If the item has already been saved, the
attachments will be created on the server immediately. If the item has not yet been saved, the attachments will
be created on the server the item is saved.
Adding attachments to an existing item will update the changekey of the item.
"""
if not is_iterable(attachments, generators_allowed=True):
attachments = [attachments]
for a in attachments:
if not a.parent_item:
a.parent_item = self
if self.id and not a.attachment_id:
# Already saved object. Attach the attachment server-side now
a.attach()
if a not in self.attachments:
self.attachments.append(a) | [
"def",
"attach",
"(",
"self",
",",
"attachments",
")",
":",
"if",
"not",
"is_iterable",
"(",
"attachments",
",",
"generators_allowed",
"=",
"True",
")",
":",
"attachments",
"=",
"[",
"attachments",
"]",
"for",
"a",
"in",
"attachments",
":",
"if",
"not",
"a",
".",
"parent_item",
":",
"a",
".",
"parent_item",
"=",
"self",
"if",
"self",
".",
"id",
"and",
"not",
"a",
".",
"attachment_id",
":",
"# Already saved object. Attach the attachment server-side now",
"a",
".",
"attach",
"(",
")",
"if",
"a",
"not",
"in",
"self",
".",
"attachments",
":",
"self",
".",
"attachments",
".",
"append",
"(",
"a",
")"
] | Add an attachment, or a list of attachments, to this item. If the item has already been saved, the
attachments will be created on the server immediately. If the item has not yet been saved, the attachments will
be created on the server the item is saved.
Adding attachments to an existing item will update the changekey of the item. | [
"Add",
"an",
"attachment",
"or",
"a",
"list",
"of",
"attachments",
"to",
"this",
"item",
".",
"If",
"the",
"item",
"has",
"already",
"been",
"saved",
"the",
"attachments",
"will",
"be",
"created",
"on",
"the",
"server",
"immediately",
".",
"If",
"the",
"item",
"has",
"not",
"yet",
"been",
"saved",
"the",
"attachments",
"will",
"be",
"created",
"on",
"the",
"server",
"the",
"item",
"is",
"saved",
"."
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/items.py#L426-L442 |
228,307 | ecederstrand/exchangelib | exchangelib/items.py | Item.detach | def detach(self, attachments):
"""Remove an attachment, or a list of attachments, from this item. If the item has already been saved, the
attachments will be deleted on the server immediately. If the item has not yet been saved, the attachments will
simply not be created on the server the item is saved.
Removing attachments from an existing item will update the changekey of the item.
"""
if not is_iterable(attachments, generators_allowed=True):
attachments = [attachments]
for a in attachments:
if a.parent_item is not self:
raise ValueError('Attachment does not belong to this item')
if self.id:
# Item is already created. Detach the attachment server-side now
a.detach()
if a in self.attachments:
self.attachments.remove(a) | python | def detach(self, attachments):
"""Remove an attachment, or a list of attachments, from this item. If the item has already been saved, the
attachments will be deleted on the server immediately. If the item has not yet been saved, the attachments will
simply not be created on the server the item is saved.
Removing attachments from an existing item will update the changekey of the item.
"""
if not is_iterable(attachments, generators_allowed=True):
attachments = [attachments]
for a in attachments:
if a.parent_item is not self:
raise ValueError('Attachment does not belong to this item')
if self.id:
# Item is already created. Detach the attachment server-side now
a.detach()
if a in self.attachments:
self.attachments.remove(a) | [
"def",
"detach",
"(",
"self",
",",
"attachments",
")",
":",
"if",
"not",
"is_iterable",
"(",
"attachments",
",",
"generators_allowed",
"=",
"True",
")",
":",
"attachments",
"=",
"[",
"attachments",
"]",
"for",
"a",
"in",
"attachments",
":",
"if",
"a",
".",
"parent_item",
"is",
"not",
"self",
":",
"raise",
"ValueError",
"(",
"'Attachment does not belong to this item'",
")",
"if",
"self",
".",
"id",
":",
"# Item is already created. Detach the attachment server-side now",
"a",
".",
"detach",
"(",
")",
"if",
"a",
"in",
"self",
".",
"attachments",
":",
"self",
".",
"attachments",
".",
"remove",
"(",
"a",
")"
] | Remove an attachment, or a list of attachments, from this item. If the item has already been saved, the
attachments will be deleted on the server immediately. If the item has not yet been saved, the attachments will
simply not be created on the server the item is saved.
Removing attachments from an existing item will update the changekey of the item. | [
"Remove",
"an",
"attachment",
"or",
"a",
"list",
"of",
"attachments",
"from",
"this",
"item",
".",
"If",
"the",
"item",
"has",
"already",
"been",
"saved",
"the",
"attachments",
"will",
"be",
"deleted",
"on",
"the",
"server",
"immediately",
".",
"If",
"the",
"item",
"has",
"not",
"yet",
"been",
"saved",
"the",
"attachments",
"will",
"simply",
"not",
"be",
"created",
"on",
"the",
"server",
"the",
"item",
"is",
"saved",
"."
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/items.py#L444-L460 |
228,308 | ecederstrand/exchangelib | exchangelib/credentials.py | ServiceAccount.back_off_until | def back_off_until(self):
"""Returns the back off value as a datetime. Resets the current back off value if it has expired."""
if self._back_off_until is None:
return None
with self._back_off_lock:
if self._back_off_until is None:
return None
if self._back_off_until < datetime.datetime.now():
self._back_off_until = None # The backoff value has expired. Reset
return None
return self._back_off_until | python | def back_off_until(self):
"""Returns the back off value as a datetime. Resets the current back off value if it has expired."""
if self._back_off_until is None:
return None
with self._back_off_lock:
if self._back_off_until is None:
return None
if self._back_off_until < datetime.datetime.now():
self._back_off_until = None # The backoff value has expired. Reset
return None
return self._back_off_until | [
"def",
"back_off_until",
"(",
"self",
")",
":",
"if",
"self",
".",
"_back_off_until",
"is",
"None",
":",
"return",
"None",
"with",
"self",
".",
"_back_off_lock",
":",
"if",
"self",
".",
"_back_off_until",
"is",
"None",
":",
"return",
"None",
"if",
"self",
".",
"_back_off_until",
"<",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
":",
"self",
".",
"_back_off_until",
"=",
"None",
"# The backoff value has expired. Reset",
"return",
"None",
"return",
"self",
".",
"_back_off_until"
] | Returns the back off value as a datetime. Resets the current back off value if it has expired. | [
"Returns",
"the",
"back",
"off",
"value",
"as",
"a",
"datetime",
".",
"Resets",
"the",
"current",
"back",
"off",
"value",
"if",
"it",
"has",
"expired",
"."
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/credentials.py#L103-L113 |
228,309 | ecederstrand/exchangelib | exchangelib/winzone.py | generate_map | def generate_map(timeout=10):
""" Helper method to update the map if the CLDR database is updated """
r = requests.get(CLDR_WINZONE_URL, timeout=timeout)
if r.status_code != 200:
raise ValueError('Unexpected response: %s' % r)
tz_map = {}
for e in to_xml(r.content).find('windowsZones').find('mapTimezones').findall('mapZone'):
for location in e.get('type').split(' '):
if e.get('territory') == DEFAULT_TERRITORY or location not in tz_map:
# Prefer default territory. This is so MS_TIMEZONE_TO_PYTZ_MAP maps from MS timezone ID back to the
# "preferred" region/location timezone name.
tz_map[location] = e.get('other'), e.get('territory')
return tz_map | python | def generate_map(timeout=10):
""" Helper method to update the map if the CLDR database is updated """
r = requests.get(CLDR_WINZONE_URL, timeout=timeout)
if r.status_code != 200:
raise ValueError('Unexpected response: %s' % r)
tz_map = {}
for e in to_xml(r.content).find('windowsZones').find('mapTimezones').findall('mapZone'):
for location in e.get('type').split(' '):
if e.get('territory') == DEFAULT_TERRITORY or location not in tz_map:
# Prefer default territory. This is so MS_TIMEZONE_TO_PYTZ_MAP maps from MS timezone ID back to the
# "preferred" region/location timezone name.
tz_map[location] = e.get('other'), e.get('territory')
return tz_map | [
"def",
"generate_map",
"(",
"timeout",
"=",
"10",
")",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"CLDR_WINZONE_URL",
",",
"timeout",
"=",
"timeout",
")",
"if",
"r",
".",
"status_code",
"!=",
"200",
":",
"raise",
"ValueError",
"(",
"'Unexpected response: %s'",
"%",
"r",
")",
"tz_map",
"=",
"{",
"}",
"for",
"e",
"in",
"to_xml",
"(",
"r",
".",
"content",
")",
".",
"find",
"(",
"'windowsZones'",
")",
".",
"find",
"(",
"'mapTimezones'",
")",
".",
"findall",
"(",
"'mapZone'",
")",
":",
"for",
"location",
"in",
"e",
".",
"get",
"(",
"'type'",
")",
".",
"split",
"(",
"' '",
")",
":",
"if",
"e",
".",
"get",
"(",
"'territory'",
")",
"==",
"DEFAULT_TERRITORY",
"or",
"location",
"not",
"in",
"tz_map",
":",
"# Prefer default territory. This is so MS_TIMEZONE_TO_PYTZ_MAP maps from MS timezone ID back to the",
"# \"preferred\" region/location timezone name.",
"tz_map",
"[",
"location",
"]",
"=",
"e",
".",
"get",
"(",
"'other'",
")",
",",
"e",
".",
"get",
"(",
"'territory'",
")",
"return",
"tz_map"
] | Helper method to update the map if the CLDR database is updated | [
"Helper",
"method",
"to",
"update",
"the",
"map",
"if",
"the",
"CLDR",
"database",
"is",
"updated"
] | 736347b337c239fcd6d592db5b29e819f753c1ba | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/winzone.py#L11-L23 |
228,310 | tanghaibao/goatools | scripts/compare_gos.py | run | def run():
"""Compare two or more sets of GO IDs. Best done using sections."""
obj = CompareGOsCli()
obj.write(obj.kws.get('xlsx'), obj.kws.get('ofile'), obj.kws.get('verbose', False)) | python | def run():
"""Compare two or more sets of GO IDs. Best done using sections."""
obj = CompareGOsCli()
obj.write(obj.kws.get('xlsx'), obj.kws.get('ofile'), obj.kws.get('verbose', False)) | [
"def",
"run",
"(",
")",
":",
"obj",
"=",
"CompareGOsCli",
"(",
")",
"obj",
".",
"write",
"(",
"obj",
".",
"kws",
".",
"get",
"(",
"'xlsx'",
")",
",",
"obj",
".",
"kws",
".",
"get",
"(",
"'ofile'",
")",
",",
"obj",
".",
"kws",
".",
"get",
"(",
"'verbose'",
",",
"False",
")",
")"
] | Compare two or more sets of GO IDs. Best done using sections. | [
"Compare",
"two",
"or",
"more",
"sets",
"of",
"GO",
"IDs",
".",
"Best",
"done",
"using",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/scripts/compare_gos.py#L10-L13 |
228,311 | tanghaibao/goatools | goatools/grouper/sorter_gos.py | SorterGoIds.sortby | def sortby(self, ntd):
"""Return function for sorting."""
if 'reldepth' in self.grprobj.gosubdag.prt_attr['flds']:
return [ntd.NS, -1*ntd.dcnt, ntd.reldepth]
else:
return [ntd.NS, -1*ntd.dcnt, ntd.depth] | python | def sortby(self, ntd):
"""Return function for sorting."""
if 'reldepth' in self.grprobj.gosubdag.prt_attr['flds']:
return [ntd.NS, -1*ntd.dcnt, ntd.reldepth]
else:
return [ntd.NS, -1*ntd.dcnt, ntd.depth] | [
"def",
"sortby",
"(",
"self",
",",
"ntd",
")",
":",
"if",
"'reldepth'",
"in",
"self",
".",
"grprobj",
".",
"gosubdag",
".",
"prt_attr",
"[",
"'flds'",
"]",
":",
"return",
"[",
"ntd",
".",
"NS",
",",
"-",
"1",
"*",
"ntd",
".",
"dcnt",
",",
"ntd",
".",
"reldepth",
"]",
"else",
":",
"return",
"[",
"ntd",
".",
"NS",
",",
"-",
"1",
"*",
"ntd",
".",
"dcnt",
",",
"ntd",
".",
"depth",
"]"
] | Return function for sorting. | [
"Return",
"function",
"for",
"sorting",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_gos.py#L33-L38 |
228,312 | tanghaibao/goatools | goatools/grouper/sorter_gos.py | SorterGoIds.get_nts_sorted | def get_nts_sorted(self, hdrgo_prt, hdrgos, hdrgo_sort):
"""Return a flat list of grouped and sorted GO terms."""
nts_flat = []
self.get_sorted_hdrgo2usrgos(hdrgos, nts_flat, hdrgo_prt, hdrgo_sort)
return nts_flat | python | def get_nts_sorted(self, hdrgo_prt, hdrgos, hdrgo_sort):
"""Return a flat list of grouped and sorted GO terms."""
nts_flat = []
self.get_sorted_hdrgo2usrgos(hdrgos, nts_flat, hdrgo_prt, hdrgo_sort)
return nts_flat | [
"def",
"get_nts_sorted",
"(",
"self",
",",
"hdrgo_prt",
",",
"hdrgos",
",",
"hdrgo_sort",
")",
":",
"nts_flat",
"=",
"[",
"]",
"self",
".",
"get_sorted_hdrgo2usrgos",
"(",
"hdrgos",
",",
"nts_flat",
",",
"hdrgo_prt",
",",
"hdrgo_sort",
")",
"return",
"nts_flat"
] | Return a flat list of grouped and sorted GO terms. | [
"Return",
"a",
"flat",
"list",
"of",
"grouped",
"and",
"sorted",
"GO",
"terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_gos.py#L64-L68 |
228,313 | tanghaibao/goatools | goatools/grouper/sorter_gos.py | SorterGoIds.get_sorted_hdrgo2usrgos | def get_sorted_hdrgo2usrgos(self, hdrgos, flat_list=None, hdrgo_prt=True, hdrgo_sort=True):
"""Return GO IDs sorting using go2nt's namedtuple."""
# Return user-specfied sort or default sort of header and user GO IDs
sorted_hdrgos_usrgos = []
h2u_get = self.grprobj.hdrgo2usrgos.get
# Sort GO group headers using GO info in go2nt
hdr_go2nt = self._get_go2nt(hdrgos)
if hdrgo_sort is True:
hdr_go2nt = sorted(hdr_go2nt.items(), key=lambda t: self.hdrgo_sortby(t[1]))
for hdrgo_id, hdrgo_nt in hdr_go2nt:
if flat_list is not None:
if hdrgo_prt or hdrgo_id in self.grprobj.usrgos:
flat_list.append(hdrgo_nt)
# Sort user GOs which are under the current GO header
usrgos_unsorted = h2u_get(hdrgo_id)
if usrgos_unsorted:
usrgo2nt = self._get_go2nt(usrgos_unsorted)
usrgont_sorted = sorted(usrgo2nt.items(), key=lambda t: self.usrgo_sortby(t[1]))
usrgos_sorted, usrnts_sorted = zip(*usrgont_sorted)
if flat_list is not None:
flat_list.extend(usrnts_sorted)
sorted_hdrgos_usrgos.append((hdrgo_id, usrgos_sorted))
else:
sorted_hdrgos_usrgos.append((hdrgo_id, []))
return cx.OrderedDict(sorted_hdrgos_usrgos) | python | def get_sorted_hdrgo2usrgos(self, hdrgos, flat_list=None, hdrgo_prt=True, hdrgo_sort=True):
"""Return GO IDs sorting using go2nt's namedtuple."""
# Return user-specfied sort or default sort of header and user GO IDs
sorted_hdrgos_usrgos = []
h2u_get = self.grprobj.hdrgo2usrgos.get
# Sort GO group headers using GO info in go2nt
hdr_go2nt = self._get_go2nt(hdrgos)
if hdrgo_sort is True:
hdr_go2nt = sorted(hdr_go2nt.items(), key=lambda t: self.hdrgo_sortby(t[1]))
for hdrgo_id, hdrgo_nt in hdr_go2nt:
if flat_list is not None:
if hdrgo_prt or hdrgo_id in self.grprobj.usrgos:
flat_list.append(hdrgo_nt)
# Sort user GOs which are under the current GO header
usrgos_unsorted = h2u_get(hdrgo_id)
if usrgos_unsorted:
usrgo2nt = self._get_go2nt(usrgos_unsorted)
usrgont_sorted = sorted(usrgo2nt.items(), key=lambda t: self.usrgo_sortby(t[1]))
usrgos_sorted, usrnts_sorted = zip(*usrgont_sorted)
if flat_list is not None:
flat_list.extend(usrnts_sorted)
sorted_hdrgos_usrgos.append((hdrgo_id, usrgos_sorted))
else:
sorted_hdrgos_usrgos.append((hdrgo_id, []))
return cx.OrderedDict(sorted_hdrgos_usrgos) | [
"def",
"get_sorted_hdrgo2usrgos",
"(",
"self",
",",
"hdrgos",
",",
"flat_list",
"=",
"None",
",",
"hdrgo_prt",
"=",
"True",
",",
"hdrgo_sort",
"=",
"True",
")",
":",
"# Return user-specfied sort or default sort of header and user GO IDs",
"sorted_hdrgos_usrgos",
"=",
"[",
"]",
"h2u_get",
"=",
"self",
".",
"grprobj",
".",
"hdrgo2usrgos",
".",
"get",
"# Sort GO group headers using GO info in go2nt",
"hdr_go2nt",
"=",
"self",
".",
"_get_go2nt",
"(",
"hdrgos",
")",
"if",
"hdrgo_sort",
"is",
"True",
":",
"hdr_go2nt",
"=",
"sorted",
"(",
"hdr_go2nt",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"t",
":",
"self",
".",
"hdrgo_sortby",
"(",
"t",
"[",
"1",
"]",
")",
")",
"for",
"hdrgo_id",
",",
"hdrgo_nt",
"in",
"hdr_go2nt",
":",
"if",
"flat_list",
"is",
"not",
"None",
":",
"if",
"hdrgo_prt",
"or",
"hdrgo_id",
"in",
"self",
".",
"grprobj",
".",
"usrgos",
":",
"flat_list",
".",
"append",
"(",
"hdrgo_nt",
")",
"# Sort user GOs which are under the current GO header",
"usrgos_unsorted",
"=",
"h2u_get",
"(",
"hdrgo_id",
")",
"if",
"usrgos_unsorted",
":",
"usrgo2nt",
"=",
"self",
".",
"_get_go2nt",
"(",
"usrgos_unsorted",
")",
"usrgont_sorted",
"=",
"sorted",
"(",
"usrgo2nt",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"t",
":",
"self",
".",
"usrgo_sortby",
"(",
"t",
"[",
"1",
"]",
")",
")",
"usrgos_sorted",
",",
"usrnts_sorted",
"=",
"zip",
"(",
"*",
"usrgont_sorted",
")",
"if",
"flat_list",
"is",
"not",
"None",
":",
"flat_list",
".",
"extend",
"(",
"usrnts_sorted",
")",
"sorted_hdrgos_usrgos",
".",
"append",
"(",
"(",
"hdrgo_id",
",",
"usrgos_sorted",
")",
")",
"else",
":",
"sorted_hdrgos_usrgos",
".",
"append",
"(",
"(",
"hdrgo_id",
",",
"[",
"]",
")",
")",
"return",
"cx",
".",
"OrderedDict",
"(",
"sorted_hdrgos_usrgos",
")"
] | Return GO IDs sorting using go2nt's namedtuple. | [
"Return",
"GO",
"IDs",
"sorting",
"using",
"go2nt",
"s",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_gos.py#L70-L94 |
228,314 | tanghaibao/goatools | goatools/grouper/sorter_gos.py | SorterGoIds._get_go2nt | def _get_go2nt(self, goids):
"""Get go2nt for given goids."""
go2nt_all = self.grprobj.go2nt
return {go:go2nt_all[go] for go in goids} | python | def _get_go2nt(self, goids):
"""Get go2nt for given goids."""
go2nt_all = self.grprobj.go2nt
return {go:go2nt_all[go] for go in goids} | [
"def",
"_get_go2nt",
"(",
"self",
",",
"goids",
")",
":",
"go2nt_all",
"=",
"self",
".",
"grprobj",
".",
"go2nt",
"return",
"{",
"go",
":",
"go2nt_all",
"[",
"go",
"]",
"for",
"go",
"in",
"goids",
"}"
] | Get go2nt for given goids. | [
"Get",
"go2nt",
"for",
"given",
"goids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_gos.py#L96-L99 |
228,315 | tanghaibao/goatools | goatools/grouper/sorter_gos.py | SorterGoIds._init_hdrgo_sortby | def _init_hdrgo_sortby(self, hdrgo_sortby, sortby):
"""Initialize header sort function."""
if hdrgo_sortby is not None:
return hdrgo_sortby
if sortby is not None:
return sortby
return self.sortby | python | def _init_hdrgo_sortby(self, hdrgo_sortby, sortby):
"""Initialize header sort function."""
if hdrgo_sortby is not None:
return hdrgo_sortby
if sortby is not None:
return sortby
return self.sortby | [
"def",
"_init_hdrgo_sortby",
"(",
"self",
",",
"hdrgo_sortby",
",",
"sortby",
")",
":",
"if",
"hdrgo_sortby",
"is",
"not",
"None",
":",
"return",
"hdrgo_sortby",
"if",
"sortby",
"is",
"not",
"None",
":",
"return",
"sortby",
"return",
"self",
".",
"sortby"
] | Initialize header sort function. | [
"Initialize",
"header",
"sort",
"function",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_gos.py#L101-L107 |
228,316 | tanghaibao/goatools | goatools/godag_plot.py | plot_goid2goobj | def plot_goid2goobj(fout_png, goid2goobj, *args, **kws):
"""Given a dict containing GO id and its goobj, create a plot of paths from GO ids."""
engine = kws['engine'] if 'engine' in kws else 'pydot'
godagsmall = OboToGoDagSmall(goid2goobj=goid2goobj).godag
godagplot = GODagSmallPlot(godagsmall, *args, **kws)
godagplot.plt(fout_png, engine) | python | def plot_goid2goobj(fout_png, goid2goobj, *args, **kws):
"""Given a dict containing GO id and its goobj, create a plot of paths from GO ids."""
engine = kws['engine'] if 'engine' in kws else 'pydot'
godagsmall = OboToGoDagSmall(goid2goobj=goid2goobj).godag
godagplot = GODagSmallPlot(godagsmall, *args, **kws)
godagplot.plt(fout_png, engine) | [
"def",
"plot_goid2goobj",
"(",
"fout_png",
",",
"goid2goobj",
",",
"*",
"args",
",",
"*",
"*",
"kws",
")",
":",
"engine",
"=",
"kws",
"[",
"'engine'",
"]",
"if",
"'engine'",
"in",
"kws",
"else",
"'pydot'",
"godagsmall",
"=",
"OboToGoDagSmall",
"(",
"goid2goobj",
"=",
"goid2goobj",
")",
".",
"godag",
"godagplot",
"=",
"GODagSmallPlot",
"(",
"godagsmall",
",",
"*",
"args",
",",
"*",
"*",
"kws",
")",
"godagplot",
".",
"plt",
"(",
"fout_png",
",",
"engine",
")"
] | Given a dict containing GO id and its goobj, create a plot of paths from GO ids. | [
"Given",
"a",
"dict",
"containing",
"GO",
"id",
"and",
"its",
"goobj",
"create",
"a",
"plot",
"of",
"paths",
"from",
"GO",
"ids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_plot.py#L19-L24 |
228,317 | tanghaibao/goatools | goatools/godag_plot.py | GODagSmallPlot._init_study_items_max | def _init_study_items_max(self):
"""User can limit the number of genes printed in a GO term."""
if self.study_items is None:
return None
if self.study_items is True:
return None
if isinstance(self.study_items, int):
return self.study_items
return None | python | def _init_study_items_max(self):
"""User can limit the number of genes printed in a GO term."""
if self.study_items is None:
return None
if self.study_items is True:
return None
if isinstance(self.study_items, int):
return self.study_items
return None | [
"def",
"_init_study_items_max",
"(",
"self",
")",
":",
"if",
"self",
".",
"study_items",
"is",
"None",
":",
"return",
"None",
"if",
"self",
".",
"study_items",
"is",
"True",
":",
"return",
"None",
"if",
"isinstance",
"(",
"self",
".",
"study_items",
",",
"int",
")",
":",
"return",
"self",
".",
"study_items",
"return",
"None"
] | User can limit the number of genes printed in a GO term. | [
"User",
"can",
"limit",
"the",
"number",
"of",
"genes",
"printed",
"in",
"a",
"GO",
"term",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_plot.py#L105-L113 |
228,318 | tanghaibao/goatools | goatools/godag_plot.py | GODagSmallPlot._init_go2res | def _init_go2res(**kws):
"""Initialize GOEA results."""
if 'goea_results' in kws:
return {res.GO:res for res in kws['goea_results']}
if 'go2nt' in kws:
return kws['go2nt'] | python | def _init_go2res(**kws):
"""Initialize GOEA results."""
if 'goea_results' in kws:
return {res.GO:res for res in kws['goea_results']}
if 'go2nt' in kws:
return kws['go2nt'] | [
"def",
"_init_go2res",
"(",
"*",
"*",
"kws",
")",
":",
"if",
"'goea_results'",
"in",
"kws",
":",
"return",
"{",
"res",
".",
"GO",
":",
"res",
"for",
"res",
"in",
"kws",
"[",
"'goea_results'",
"]",
"}",
"if",
"'go2nt'",
"in",
"kws",
":",
"return",
"kws",
"[",
"'go2nt'",
"]"
] | Initialize GOEA results. | [
"Initialize",
"GOEA",
"results",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_plot.py#L116-L121 |
228,319 | tanghaibao/goatools | goatools/godag_plot.py | GODagSmallPlot._get_pydot | def _get_pydot(self):
"""Return pydot package. Load pydot, if necessary."""
if self.pydot:
return self.pydot
self.pydot = __import__("pydot")
return self.pydot | python | def _get_pydot(self):
"""Return pydot package. Load pydot, if necessary."""
if self.pydot:
return self.pydot
self.pydot = __import__("pydot")
return self.pydot | [
"def",
"_get_pydot",
"(",
"self",
")",
":",
"if",
"self",
".",
"pydot",
":",
"return",
"self",
".",
"pydot",
"self",
".",
"pydot",
"=",
"__import__",
"(",
"\"pydot\"",
")",
"return",
"self",
".",
"pydot"
] | Return pydot package. Load pydot, if necessary. | [
"Return",
"pydot",
"package",
".",
"Load",
"pydot",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_plot.py#L217-L222 |
228,320 | tanghaibao/goatools | goatools/wr_tbl.py | wr_xlsx | def wr_xlsx(fout_xlsx, data_xlsx, **kws):
"""Write a spreadsheet into a xlsx file."""
from goatools.wr_tbl_class import WrXlsx
# optional keyword args: fld2col_widths hdrs prt_if sort_by fld2fmt prt_flds
items_str = kws.get("items", "items") if "items" not in kws else kws["items"]
if data_xlsx:
# Open xlsx file
xlsxobj = WrXlsx(fout_xlsx, data_xlsx[0]._fields, **kws)
worksheet = xlsxobj.add_worksheet()
# Write title (optional) and headers.
row_idx = xlsxobj.wr_title(worksheet)
row_idx = xlsxobj.wr_hdrs(worksheet, row_idx)
row_idx_data0 = row_idx
# Write data
row_idx = xlsxobj.wr_data(data_xlsx, row_idx, worksheet)
# Close xlsx file
xlsxobj.workbook.close()
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT}\n".format(
N=row_idx-row_idx_data0, ITEMS=items_str, FOUT=fout_xlsx))
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_xlsx)) | python | def wr_xlsx(fout_xlsx, data_xlsx, **kws):
"""Write a spreadsheet into a xlsx file."""
from goatools.wr_tbl_class import WrXlsx
# optional keyword args: fld2col_widths hdrs prt_if sort_by fld2fmt prt_flds
items_str = kws.get("items", "items") if "items" not in kws else kws["items"]
if data_xlsx:
# Open xlsx file
xlsxobj = WrXlsx(fout_xlsx, data_xlsx[0]._fields, **kws)
worksheet = xlsxobj.add_worksheet()
# Write title (optional) and headers.
row_idx = xlsxobj.wr_title(worksheet)
row_idx = xlsxobj.wr_hdrs(worksheet, row_idx)
row_idx_data0 = row_idx
# Write data
row_idx = xlsxobj.wr_data(data_xlsx, row_idx, worksheet)
# Close xlsx file
xlsxobj.workbook.close()
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT}\n".format(
N=row_idx-row_idx_data0, ITEMS=items_str, FOUT=fout_xlsx))
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_xlsx)) | [
"def",
"wr_xlsx",
"(",
"fout_xlsx",
",",
"data_xlsx",
",",
"*",
"*",
"kws",
")",
":",
"from",
"goatools",
".",
"wr_tbl_class",
"import",
"WrXlsx",
"# optional keyword args: fld2col_widths hdrs prt_if sort_by fld2fmt prt_flds",
"items_str",
"=",
"kws",
".",
"get",
"(",
"\"items\"",
",",
"\"items\"",
")",
"if",
"\"items\"",
"not",
"in",
"kws",
"else",
"kws",
"[",
"\"items\"",
"]",
"if",
"data_xlsx",
":",
"# Open xlsx file",
"xlsxobj",
"=",
"WrXlsx",
"(",
"fout_xlsx",
",",
"data_xlsx",
"[",
"0",
"]",
".",
"_fields",
",",
"*",
"*",
"kws",
")",
"worksheet",
"=",
"xlsxobj",
".",
"add_worksheet",
"(",
")",
"# Write title (optional) and headers.",
"row_idx",
"=",
"xlsxobj",
".",
"wr_title",
"(",
"worksheet",
")",
"row_idx",
"=",
"xlsxobj",
".",
"wr_hdrs",
"(",
"worksheet",
",",
"row_idx",
")",
"row_idx_data0",
"=",
"row_idx",
"# Write data",
"row_idx",
"=",
"xlsxobj",
".",
"wr_data",
"(",
"data_xlsx",
",",
"row_idx",
",",
"worksheet",
")",
"# Close xlsx file",
"xlsxobj",
".",
"workbook",
".",
"close",
"(",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" {N:>5} {ITEMS} WROTE: {FOUT}\\n\"",
".",
"format",
"(",
"N",
"=",
"row_idx",
"-",
"row_idx_data0",
",",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_xlsx",
")",
")",
"else",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" 0 {ITEMS}. NOT WRITING {FOUT}\\n\"",
".",
"format",
"(",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_xlsx",
")",
")"
] | Write a spreadsheet into a xlsx file. | [
"Write",
"a",
"spreadsheet",
"into",
"a",
"xlsx",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L63-L84 |
228,321 | tanghaibao/goatools | goatools/wr_tbl.py | wr_xlsx_sections | def wr_xlsx_sections(fout_xlsx, xlsx_data, **kws):
"""Write xlsx file containing section names followed by lines of namedtuple data."""
from goatools.wr_tbl_class import WrXlsx
items_str = "items" if "items" not in kws else kws["items"]
prt_hdr_min = 10
num_items = 0
if xlsx_data:
# Basic data checks
assert len(xlsx_data[0]) == 2, "wr_xlsx_sections EXPECTED: [(section, nts), ..."
assert xlsx_data[0][1], \
"wr_xlsx_sections EXPECTED SECTION({S}) LIST TO HAVE DATA".format(S=xlsx_data[0][0])
# Open xlsx file and write title (optional) and headers.
xlsxobj = WrXlsx(fout_xlsx, xlsx_data[0][1][0]._fields, **kws)
worksheet = xlsxobj.add_worksheet()
row_idx = xlsxobj.wr_title(worksheet)
hdrs_wrote = False
# Write data
for section_text, data_nts in xlsx_data:
num_items += len(data_nts)
fmt = xlsxobj.wbfmtobj.get_fmt_section()
row_idx = xlsxobj.wr_row_mergeall(worksheet, section_text, fmt, row_idx)
if hdrs_wrote is False or len(data_nts) > prt_hdr_min:
row_idx = xlsxobj.wr_hdrs(worksheet, row_idx)
hdrs_wrote = True
row_idx = xlsxobj.wr_data(data_nts, row_idx, worksheet)
# Close xlsx file
xlsxobj.workbook.close()
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT} ({S} sections)\n".format(
N=num_items, ITEMS=items_str, FOUT=fout_xlsx, S=len(xlsx_data)))
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_xlsx)) | python | def wr_xlsx_sections(fout_xlsx, xlsx_data, **kws):
"""Write xlsx file containing section names followed by lines of namedtuple data."""
from goatools.wr_tbl_class import WrXlsx
items_str = "items" if "items" not in kws else kws["items"]
prt_hdr_min = 10
num_items = 0
if xlsx_data:
# Basic data checks
assert len(xlsx_data[0]) == 2, "wr_xlsx_sections EXPECTED: [(section, nts), ..."
assert xlsx_data[0][1], \
"wr_xlsx_sections EXPECTED SECTION({S}) LIST TO HAVE DATA".format(S=xlsx_data[0][0])
# Open xlsx file and write title (optional) and headers.
xlsxobj = WrXlsx(fout_xlsx, xlsx_data[0][1][0]._fields, **kws)
worksheet = xlsxobj.add_worksheet()
row_idx = xlsxobj.wr_title(worksheet)
hdrs_wrote = False
# Write data
for section_text, data_nts in xlsx_data:
num_items += len(data_nts)
fmt = xlsxobj.wbfmtobj.get_fmt_section()
row_idx = xlsxobj.wr_row_mergeall(worksheet, section_text, fmt, row_idx)
if hdrs_wrote is False or len(data_nts) > prt_hdr_min:
row_idx = xlsxobj.wr_hdrs(worksheet, row_idx)
hdrs_wrote = True
row_idx = xlsxobj.wr_data(data_nts, row_idx, worksheet)
# Close xlsx file
xlsxobj.workbook.close()
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT} ({S} sections)\n".format(
N=num_items, ITEMS=items_str, FOUT=fout_xlsx, S=len(xlsx_data)))
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_xlsx)) | [
"def",
"wr_xlsx_sections",
"(",
"fout_xlsx",
",",
"xlsx_data",
",",
"*",
"*",
"kws",
")",
":",
"from",
"goatools",
".",
"wr_tbl_class",
"import",
"WrXlsx",
"items_str",
"=",
"\"items\"",
"if",
"\"items\"",
"not",
"in",
"kws",
"else",
"kws",
"[",
"\"items\"",
"]",
"prt_hdr_min",
"=",
"10",
"num_items",
"=",
"0",
"if",
"xlsx_data",
":",
"# Basic data checks",
"assert",
"len",
"(",
"xlsx_data",
"[",
"0",
"]",
")",
"==",
"2",
",",
"\"wr_xlsx_sections EXPECTED: [(section, nts), ...\"",
"assert",
"xlsx_data",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"\"wr_xlsx_sections EXPECTED SECTION({S}) LIST TO HAVE DATA\"",
".",
"format",
"(",
"S",
"=",
"xlsx_data",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"# Open xlsx file and write title (optional) and headers.",
"xlsxobj",
"=",
"WrXlsx",
"(",
"fout_xlsx",
",",
"xlsx_data",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"_fields",
",",
"*",
"*",
"kws",
")",
"worksheet",
"=",
"xlsxobj",
".",
"add_worksheet",
"(",
")",
"row_idx",
"=",
"xlsxobj",
".",
"wr_title",
"(",
"worksheet",
")",
"hdrs_wrote",
"=",
"False",
"# Write data",
"for",
"section_text",
",",
"data_nts",
"in",
"xlsx_data",
":",
"num_items",
"+=",
"len",
"(",
"data_nts",
")",
"fmt",
"=",
"xlsxobj",
".",
"wbfmtobj",
".",
"get_fmt_section",
"(",
")",
"row_idx",
"=",
"xlsxobj",
".",
"wr_row_mergeall",
"(",
"worksheet",
",",
"section_text",
",",
"fmt",
",",
"row_idx",
")",
"if",
"hdrs_wrote",
"is",
"False",
"or",
"len",
"(",
"data_nts",
")",
">",
"prt_hdr_min",
":",
"row_idx",
"=",
"xlsxobj",
".",
"wr_hdrs",
"(",
"worksheet",
",",
"row_idx",
")",
"hdrs_wrote",
"=",
"True",
"row_idx",
"=",
"xlsxobj",
".",
"wr_data",
"(",
"data_nts",
",",
"row_idx",
",",
"worksheet",
")",
"# Close xlsx file",
"xlsxobj",
".",
"workbook",
".",
"close",
"(",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" {N:>5} {ITEMS} WROTE: {FOUT} ({S} sections)\\n\"",
".",
"format",
"(",
"N",
"=",
"num_items",
",",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_xlsx",
",",
"S",
"=",
"len",
"(",
"xlsx_data",
")",
")",
")",
"else",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" 0 {ITEMS}. NOT WRITING {FOUT}\\n\"",
".",
"format",
"(",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_xlsx",
")",
")"
] | Write xlsx file containing section names followed by lines of namedtuple data. | [
"Write",
"xlsx",
"file",
"containing",
"section",
"names",
"followed",
"by",
"lines",
"of",
"namedtuple",
"data",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L86-L117 |
228,322 | tanghaibao/goatools | goatools/wr_tbl.py | wr_tsv | def wr_tsv(fout_tsv, tsv_data, **kws):
"""Write a file of tab-separated table data"""
items_str = "items" if "items" not in kws else kws["items"]
if tsv_data:
ifstrm = sys.stdout if fout_tsv is None else open(fout_tsv, 'w')
num_items = prt_tsv(ifstrm, tsv_data, **kws)
if fout_tsv is not None:
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT}\n".format(
N=num_items, ITEMS=items_str, FOUT=fout_tsv))
ifstrm.close()
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_tsv)) | python | def wr_tsv(fout_tsv, tsv_data, **kws):
"""Write a file of tab-separated table data"""
items_str = "items" if "items" not in kws else kws["items"]
if tsv_data:
ifstrm = sys.stdout if fout_tsv is None else open(fout_tsv, 'w')
num_items = prt_tsv(ifstrm, tsv_data, **kws)
if fout_tsv is not None:
sys.stdout.write(" {N:>5} {ITEMS} WROTE: {FOUT}\n".format(
N=num_items, ITEMS=items_str, FOUT=fout_tsv))
ifstrm.close()
else:
sys.stdout.write(" 0 {ITEMS}. NOT WRITING {FOUT}\n".format(
ITEMS=items_str, FOUT=fout_tsv)) | [
"def",
"wr_tsv",
"(",
"fout_tsv",
",",
"tsv_data",
",",
"*",
"*",
"kws",
")",
":",
"items_str",
"=",
"\"items\"",
"if",
"\"items\"",
"not",
"in",
"kws",
"else",
"kws",
"[",
"\"items\"",
"]",
"if",
"tsv_data",
":",
"ifstrm",
"=",
"sys",
".",
"stdout",
"if",
"fout_tsv",
"is",
"None",
"else",
"open",
"(",
"fout_tsv",
",",
"'w'",
")",
"num_items",
"=",
"prt_tsv",
"(",
"ifstrm",
",",
"tsv_data",
",",
"*",
"*",
"kws",
")",
"if",
"fout_tsv",
"is",
"not",
"None",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" {N:>5} {ITEMS} WROTE: {FOUT}\\n\"",
".",
"format",
"(",
"N",
"=",
"num_items",
",",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_tsv",
")",
")",
"ifstrm",
".",
"close",
"(",
")",
"else",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" 0 {ITEMS}. NOT WRITING {FOUT}\\n\"",
".",
"format",
"(",
"ITEMS",
"=",
"items_str",
",",
"FOUT",
"=",
"fout_tsv",
")",
")"
] | Write a file of tab-separated table data | [
"Write",
"a",
"file",
"of",
"tab",
"-",
"separated",
"table",
"data"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L119-L131 |
228,323 | tanghaibao/goatools | goatools/wr_tbl.py | prt_tsv_sections | def prt_tsv_sections(prt, tsv_data, **kws):
"""Write tsv file containing section names followed by lines of namedtuple data."""
prt_hdr_min = 10 # Print hdr on the 1st section and for any following 'large' sections
num_items = 0
if tsv_data:
# Basic data checks
assert len(tsv_data[0]) == 2, "wr_tsv_sections EXPECTED: [(section, nts), ..."
assert tsv_data[0][1], \
"wr_tsv_sections EXPECTED SECTION({S}) LIST TO HAVE DATA".format(S=tsv_data[0][0])
hdrs_wrote = False
sep = "\t" if 'sep' not in kws else kws['sep']
prt_flds = kws['prt_flds'] if 'prt_flds' in kws else tsv_data[0]._fields
fill = sep*(len(prt_flds) - 1)
# Write data
for section_text, data_nts in tsv_data:
prt.write("{SEC}{FILL}\n".format(SEC=section_text, FILL=fill))
if hdrs_wrote is False or len(data_nts) > prt_hdr_min:
prt_tsv_hdr(prt, data_nts, **kws)
hdrs_wrote = True
num_items += prt_tsv_dat(prt, data_nts, **kws)
return num_items
else:
return 0 | python | def prt_tsv_sections(prt, tsv_data, **kws):
"""Write tsv file containing section names followed by lines of namedtuple data."""
prt_hdr_min = 10 # Print hdr on the 1st section and for any following 'large' sections
num_items = 0
if tsv_data:
# Basic data checks
assert len(tsv_data[0]) == 2, "wr_tsv_sections EXPECTED: [(section, nts), ..."
assert tsv_data[0][1], \
"wr_tsv_sections EXPECTED SECTION({S}) LIST TO HAVE DATA".format(S=tsv_data[0][0])
hdrs_wrote = False
sep = "\t" if 'sep' not in kws else kws['sep']
prt_flds = kws['prt_flds'] if 'prt_flds' in kws else tsv_data[0]._fields
fill = sep*(len(prt_flds) - 1)
# Write data
for section_text, data_nts in tsv_data:
prt.write("{SEC}{FILL}\n".format(SEC=section_text, FILL=fill))
if hdrs_wrote is False or len(data_nts) > prt_hdr_min:
prt_tsv_hdr(prt, data_nts, **kws)
hdrs_wrote = True
num_items += prt_tsv_dat(prt, data_nts, **kws)
return num_items
else:
return 0 | [
"def",
"prt_tsv_sections",
"(",
"prt",
",",
"tsv_data",
",",
"*",
"*",
"kws",
")",
":",
"prt_hdr_min",
"=",
"10",
"# Print hdr on the 1st section and for any following 'large' sections",
"num_items",
"=",
"0",
"if",
"tsv_data",
":",
"# Basic data checks",
"assert",
"len",
"(",
"tsv_data",
"[",
"0",
"]",
")",
"==",
"2",
",",
"\"wr_tsv_sections EXPECTED: [(section, nts), ...\"",
"assert",
"tsv_data",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"\"wr_tsv_sections EXPECTED SECTION({S}) LIST TO HAVE DATA\"",
".",
"format",
"(",
"S",
"=",
"tsv_data",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"hdrs_wrote",
"=",
"False",
"sep",
"=",
"\"\\t\"",
"if",
"'sep'",
"not",
"in",
"kws",
"else",
"kws",
"[",
"'sep'",
"]",
"prt_flds",
"=",
"kws",
"[",
"'prt_flds'",
"]",
"if",
"'prt_flds'",
"in",
"kws",
"else",
"tsv_data",
"[",
"0",
"]",
".",
"_fields",
"fill",
"=",
"sep",
"*",
"(",
"len",
"(",
"prt_flds",
")",
"-",
"1",
")",
"# Write data",
"for",
"section_text",
",",
"data_nts",
"in",
"tsv_data",
":",
"prt",
".",
"write",
"(",
"\"{SEC}{FILL}\\n\"",
".",
"format",
"(",
"SEC",
"=",
"section_text",
",",
"FILL",
"=",
"fill",
")",
")",
"if",
"hdrs_wrote",
"is",
"False",
"or",
"len",
"(",
"data_nts",
")",
">",
"prt_hdr_min",
":",
"prt_tsv_hdr",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
"hdrs_wrote",
"=",
"True",
"num_items",
"+=",
"prt_tsv_dat",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
"return",
"num_items",
"else",
":",
"return",
"0"
] | Write tsv file containing section names followed by lines of namedtuple data. | [
"Write",
"tsv",
"file",
"containing",
"section",
"names",
"followed",
"by",
"lines",
"of",
"namedtuple",
"data",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L133-L155 |
228,324 | tanghaibao/goatools | goatools/wr_tbl.py | prt_tsv | def prt_tsv(prt, data_nts, **kws):
"""Print tab-separated table headers and data"""
# User-controlled printing options
prt_tsv_hdr(prt, data_nts, **kws)
return prt_tsv_dat(prt, data_nts, **kws) | python | def prt_tsv(prt, data_nts, **kws):
"""Print tab-separated table headers and data"""
# User-controlled printing options
prt_tsv_hdr(prt, data_nts, **kws)
return prt_tsv_dat(prt, data_nts, **kws) | [
"def",
"prt_tsv",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
":",
"# User-controlled printing options",
"prt_tsv_hdr",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
"return",
"prt_tsv_dat",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")"
] | Print tab-separated table headers and data | [
"Print",
"tab",
"-",
"separated",
"table",
"headers",
"and",
"data"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L157-L161 |
228,325 | tanghaibao/goatools | goatools/wr_tbl.py | prt_tsv_hdr | def prt_tsv_hdr(prt, data_nts, **kws):
"""Print tab-separated table headers"""
sep = "\t" if 'sep' not in kws else kws['sep']
flds_all = data_nts[0]._fields
hdrs = get_hdrs(flds_all, **kws)
prt.write("# {}\n".format(sep.join(hdrs))) | python | def prt_tsv_hdr(prt, data_nts, **kws):
"""Print tab-separated table headers"""
sep = "\t" if 'sep' not in kws else kws['sep']
flds_all = data_nts[0]._fields
hdrs = get_hdrs(flds_all, **kws)
prt.write("# {}\n".format(sep.join(hdrs))) | [
"def",
"prt_tsv_hdr",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
":",
"sep",
"=",
"\"\\t\"",
"if",
"'sep'",
"not",
"in",
"kws",
"else",
"kws",
"[",
"'sep'",
"]",
"flds_all",
"=",
"data_nts",
"[",
"0",
"]",
".",
"_fields",
"hdrs",
"=",
"get_hdrs",
"(",
"flds_all",
",",
"*",
"*",
"kws",
")",
"prt",
".",
"write",
"(",
"\"# {}\\n\"",
".",
"format",
"(",
"sep",
".",
"join",
"(",
"hdrs",
")",
")",
")"
] | Print tab-separated table headers | [
"Print",
"tab",
"-",
"separated",
"table",
"headers"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L163-L168 |
228,326 | tanghaibao/goatools | goatools/wr_tbl.py | prt_tsv_dat | def prt_tsv_dat(prt, data_nts, **kws):
"""Print tab-separated table data"""
sep = "\t" if 'sep' not in kws else kws['sep']
fld2fmt = None if 'fld2fmt' not in kws else kws['fld2fmt']
if 'sort_by' in kws:
data_nts = sorted(data_nts, key=kws['sort_by'])
prt_if = kws['prt_if'] if 'prt_if' in kws else None
prt_flds = kws['prt_flds'] if 'prt_flds' in kws else data_nts[0]._fields
items = 0
for nt_data_row in data_nts:
if prt_if is None or prt_if(nt_data_row):
if fld2fmt is not None:
row_fld_vals = [(fld, getattr(nt_data_row, fld)) for fld in prt_flds]
row_vals = _fmt_fields(row_fld_vals, fld2fmt)
else:
row_vals = [getattr(nt_data_row, fld) for fld in prt_flds]
prt.write("{}\n".format(sep.join(str(d) for d in row_vals)))
items += 1
return items | python | def prt_tsv_dat(prt, data_nts, **kws):
"""Print tab-separated table data"""
sep = "\t" if 'sep' not in kws else kws['sep']
fld2fmt = None if 'fld2fmt' not in kws else kws['fld2fmt']
if 'sort_by' in kws:
data_nts = sorted(data_nts, key=kws['sort_by'])
prt_if = kws['prt_if'] if 'prt_if' in kws else None
prt_flds = kws['prt_flds'] if 'prt_flds' in kws else data_nts[0]._fields
items = 0
for nt_data_row in data_nts:
if prt_if is None or prt_if(nt_data_row):
if fld2fmt is not None:
row_fld_vals = [(fld, getattr(nt_data_row, fld)) for fld in prt_flds]
row_vals = _fmt_fields(row_fld_vals, fld2fmt)
else:
row_vals = [getattr(nt_data_row, fld) for fld in prt_flds]
prt.write("{}\n".format(sep.join(str(d) for d in row_vals)))
items += 1
return items | [
"def",
"prt_tsv_dat",
"(",
"prt",
",",
"data_nts",
",",
"*",
"*",
"kws",
")",
":",
"sep",
"=",
"\"\\t\"",
"if",
"'sep'",
"not",
"in",
"kws",
"else",
"kws",
"[",
"'sep'",
"]",
"fld2fmt",
"=",
"None",
"if",
"'fld2fmt'",
"not",
"in",
"kws",
"else",
"kws",
"[",
"'fld2fmt'",
"]",
"if",
"'sort_by'",
"in",
"kws",
":",
"data_nts",
"=",
"sorted",
"(",
"data_nts",
",",
"key",
"=",
"kws",
"[",
"'sort_by'",
"]",
")",
"prt_if",
"=",
"kws",
"[",
"'prt_if'",
"]",
"if",
"'prt_if'",
"in",
"kws",
"else",
"None",
"prt_flds",
"=",
"kws",
"[",
"'prt_flds'",
"]",
"if",
"'prt_flds'",
"in",
"kws",
"else",
"data_nts",
"[",
"0",
"]",
".",
"_fields",
"items",
"=",
"0",
"for",
"nt_data_row",
"in",
"data_nts",
":",
"if",
"prt_if",
"is",
"None",
"or",
"prt_if",
"(",
"nt_data_row",
")",
":",
"if",
"fld2fmt",
"is",
"not",
"None",
":",
"row_fld_vals",
"=",
"[",
"(",
"fld",
",",
"getattr",
"(",
"nt_data_row",
",",
"fld",
")",
")",
"for",
"fld",
"in",
"prt_flds",
"]",
"row_vals",
"=",
"_fmt_fields",
"(",
"row_fld_vals",
",",
"fld2fmt",
")",
"else",
":",
"row_vals",
"=",
"[",
"getattr",
"(",
"nt_data_row",
",",
"fld",
")",
"for",
"fld",
"in",
"prt_flds",
"]",
"prt",
".",
"write",
"(",
"\"{}\\n\"",
".",
"format",
"(",
"sep",
".",
"join",
"(",
"str",
"(",
"d",
")",
"for",
"d",
"in",
"row_vals",
")",
")",
")",
"items",
"+=",
"1",
"return",
"items"
] | Print tab-separated table data | [
"Print",
"tab",
"-",
"separated",
"table",
"data"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L170-L188 |
228,327 | tanghaibao/goatools | goatools/wr_tbl.py | _chk_flds_fmt | def _chk_flds_fmt(nt_fields, prtfmt):
"""Check that all fields in the prtfmt have corresponding data in the namedtuple."""
fmtflds = get_fmtflds(prtfmt)
missing_data = set(fmtflds).difference(set(nt_fields))
# All data needed for print is present, return.
if not missing_data:
return
#raise Exception('MISSING DATA({M}).'.format(M=" ".join(missing_data)))
msg = ['CANNOT PRINT USING: "{PF}"'.format(PF=prtfmt.rstrip())]
for fld in fmtflds:
errmrk = "" if fld in nt_fields else "ERROR-->"
msg.append(" {ERR:8} {FLD}".format(ERR=errmrk, FLD=fld))
raise Exception('\n'.join(msg)) | python | def _chk_flds_fmt(nt_fields, prtfmt):
"""Check that all fields in the prtfmt have corresponding data in the namedtuple."""
fmtflds = get_fmtflds(prtfmt)
missing_data = set(fmtflds).difference(set(nt_fields))
# All data needed for print is present, return.
if not missing_data:
return
#raise Exception('MISSING DATA({M}).'.format(M=" ".join(missing_data)))
msg = ['CANNOT PRINT USING: "{PF}"'.format(PF=prtfmt.rstrip())]
for fld in fmtflds:
errmrk = "" if fld in nt_fields else "ERROR-->"
msg.append(" {ERR:8} {FLD}".format(ERR=errmrk, FLD=fld))
raise Exception('\n'.join(msg)) | [
"def",
"_chk_flds_fmt",
"(",
"nt_fields",
",",
"prtfmt",
")",
":",
"fmtflds",
"=",
"get_fmtflds",
"(",
"prtfmt",
")",
"missing_data",
"=",
"set",
"(",
"fmtflds",
")",
".",
"difference",
"(",
"set",
"(",
"nt_fields",
")",
")",
"# All data needed for print is present, return.",
"if",
"not",
"missing_data",
":",
"return",
"#raise Exception('MISSING DATA({M}).'.format(M=\" \".join(missing_data)))",
"msg",
"=",
"[",
"'CANNOT PRINT USING: \"{PF}\"'",
".",
"format",
"(",
"PF",
"=",
"prtfmt",
".",
"rstrip",
"(",
")",
")",
"]",
"for",
"fld",
"in",
"fmtflds",
":",
"errmrk",
"=",
"\"\"",
"if",
"fld",
"in",
"nt_fields",
"else",
"\"ERROR-->\"",
"msg",
".",
"append",
"(",
"\" {ERR:8} {FLD}\"",
".",
"format",
"(",
"ERR",
"=",
"errmrk",
",",
"FLD",
"=",
"fld",
")",
")",
"raise",
"Exception",
"(",
"'\\n'",
".",
"join",
"(",
"msg",
")",
")"
] | Check that all fields in the prtfmt have corresponding data in the namedtuple. | [
"Check",
"that",
"all",
"fields",
"in",
"the",
"prtfmt",
"have",
"corresponding",
"data",
"in",
"the",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L199-L211 |
228,328 | tanghaibao/goatools | goatools/wr_tbl.py | _prt_txt_hdr | def _prt_txt_hdr(prt, prtfmt):
"""Print header for text report."""
tblhdrs = get_fmtfldsdict(prtfmt)
# If needed, reformat for format_string for header, which has strings, not floats.
hdrfmt = re.sub(r':(\d+)\.\S+}', r':\1}', prtfmt)
hdrfmt = re.sub(r':(0+)(\d+)}', r':\2}', hdrfmt)
prt.write("#{}".format(hdrfmt.format(**tblhdrs))) | python | def _prt_txt_hdr(prt, prtfmt):
"""Print header for text report."""
tblhdrs = get_fmtfldsdict(prtfmt)
# If needed, reformat for format_string for header, which has strings, not floats.
hdrfmt = re.sub(r':(\d+)\.\S+}', r':\1}', prtfmt)
hdrfmt = re.sub(r':(0+)(\d+)}', r':\2}', hdrfmt)
prt.write("#{}".format(hdrfmt.format(**tblhdrs))) | [
"def",
"_prt_txt_hdr",
"(",
"prt",
",",
"prtfmt",
")",
":",
"tblhdrs",
"=",
"get_fmtfldsdict",
"(",
"prtfmt",
")",
"# If needed, reformat for format_string for header, which has strings, not floats.",
"hdrfmt",
"=",
"re",
".",
"sub",
"(",
"r':(\\d+)\\.\\S+}'",
",",
"r':\\1}'",
",",
"prtfmt",
")",
"hdrfmt",
"=",
"re",
".",
"sub",
"(",
"r':(0+)(\\d+)}'",
",",
"r':\\2}'",
",",
"hdrfmt",
")",
"prt",
".",
"write",
"(",
"\"#{}\"",
".",
"format",
"(",
"hdrfmt",
".",
"format",
"(",
"*",
"*",
"tblhdrs",
")",
")",
")"
] | Print header for text report. | [
"Print",
"header",
"for",
"text",
"report",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L223-L229 |
228,329 | tanghaibao/goatools | goatools/wr_tbl.py | mk_fmtfld | def mk_fmtfld(nt_item, joinchr=" ", eol="\n"):
"""Given a namedtuple, return a format_field string."""
fldstrs = []
# Default formats based on fieldname
fld2fmt = {
'hdrgo' : lambda f: "{{{FLD}:1,}}".format(FLD=f),
'dcnt' : lambda f: "{{{FLD}:6,}}".format(FLD=f),
'level' : lambda f: "L{{{FLD}:02,}}".format(FLD=f),
'depth' : lambda f: "D{{{FLD}:02,}}".format(FLD=f),
}
for fld in nt_item._fields:
if fld in fld2fmt:
val = fld2fmt[fld](fld)
else:
val = "{{{FLD}}}".format(FLD=fld)
fldstrs.append(val)
return "{LINE}{EOL}".format(LINE=joinchr.join(fldstrs), EOL=eol) | python | def mk_fmtfld(nt_item, joinchr=" ", eol="\n"):
"""Given a namedtuple, return a format_field string."""
fldstrs = []
# Default formats based on fieldname
fld2fmt = {
'hdrgo' : lambda f: "{{{FLD}:1,}}".format(FLD=f),
'dcnt' : lambda f: "{{{FLD}:6,}}".format(FLD=f),
'level' : lambda f: "L{{{FLD}:02,}}".format(FLD=f),
'depth' : lambda f: "D{{{FLD}:02,}}".format(FLD=f),
}
for fld in nt_item._fields:
if fld in fld2fmt:
val = fld2fmt[fld](fld)
else:
val = "{{{FLD}}}".format(FLD=fld)
fldstrs.append(val)
return "{LINE}{EOL}".format(LINE=joinchr.join(fldstrs), EOL=eol) | [
"def",
"mk_fmtfld",
"(",
"nt_item",
",",
"joinchr",
"=",
"\" \"",
",",
"eol",
"=",
"\"\\n\"",
")",
":",
"fldstrs",
"=",
"[",
"]",
"# Default formats based on fieldname",
"fld2fmt",
"=",
"{",
"'hdrgo'",
":",
"lambda",
"f",
":",
"\"{{{FLD}:1,}}\"",
".",
"format",
"(",
"FLD",
"=",
"f",
")",
",",
"'dcnt'",
":",
"lambda",
"f",
":",
"\"{{{FLD}:6,}}\"",
".",
"format",
"(",
"FLD",
"=",
"f",
")",
",",
"'level'",
":",
"lambda",
"f",
":",
"\"L{{{FLD}:02,}}\"",
".",
"format",
"(",
"FLD",
"=",
"f",
")",
",",
"'depth'",
":",
"lambda",
"f",
":",
"\"D{{{FLD}:02,}}\"",
".",
"format",
"(",
"FLD",
"=",
"f",
")",
",",
"}",
"for",
"fld",
"in",
"nt_item",
".",
"_fields",
":",
"if",
"fld",
"in",
"fld2fmt",
":",
"val",
"=",
"fld2fmt",
"[",
"fld",
"]",
"(",
"fld",
")",
"else",
":",
"val",
"=",
"\"{{{FLD}}}\"",
".",
"format",
"(",
"FLD",
"=",
"fld",
")",
"fldstrs",
".",
"append",
"(",
"val",
")",
"return",
"\"{LINE}{EOL}\"",
".",
"format",
"(",
"LINE",
"=",
"joinchr",
".",
"join",
"(",
"fldstrs",
")",
",",
"EOL",
"=",
"eol",
")"
] | Given a namedtuple, return a format_field string. | [
"Given",
"a",
"namedtuple",
"return",
"a",
"format_field",
"string",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl.py#L231-L247 |
228,330 | tanghaibao/goatools | goatools/cli/compare_gos.py | CompareGOsCli._get_prtfmt | def _get_prtfmt(self, objgowr, verbose):
"""Get print format containing markers."""
prtfmt = objgowr.get_prtfmt('fmt')
prtfmt = prtfmt.replace('# ', '')
# print('PPPPPPPPPPP', prtfmt)
if not verbose:
prtfmt = prtfmt.replace('{hdr1usr01:2}', '')
prtfmt = prtfmt.replace('{childcnt:3} L{level:02} ', '')
prtfmt = prtfmt.replace('{num_usrgos:>4} uGOs ', '')
prtfmt = prtfmt.replace('{D1:5} {REL} {rel}', '')
prtfmt = prtfmt.replace('R{reldepth:02} ', '')
# print('PPPPPPPPPPP', prtfmt)
marks = ''.join(['{{{}}}'.format(nt.hdr) for nt in self.go_ntsets])
return '{MARKS} {PRTFMT}'.format(MARKS=marks, PRTFMT=prtfmt) | python | def _get_prtfmt(self, objgowr, verbose):
"""Get print format containing markers."""
prtfmt = objgowr.get_prtfmt('fmt')
prtfmt = prtfmt.replace('# ', '')
# print('PPPPPPPPPPP', prtfmt)
if not verbose:
prtfmt = prtfmt.replace('{hdr1usr01:2}', '')
prtfmt = prtfmt.replace('{childcnt:3} L{level:02} ', '')
prtfmt = prtfmt.replace('{num_usrgos:>4} uGOs ', '')
prtfmt = prtfmt.replace('{D1:5} {REL} {rel}', '')
prtfmt = prtfmt.replace('R{reldepth:02} ', '')
# print('PPPPPPPPPPP', prtfmt)
marks = ''.join(['{{{}}}'.format(nt.hdr) for nt in self.go_ntsets])
return '{MARKS} {PRTFMT}'.format(MARKS=marks, PRTFMT=prtfmt) | [
"def",
"_get_prtfmt",
"(",
"self",
",",
"objgowr",
",",
"verbose",
")",
":",
"prtfmt",
"=",
"objgowr",
".",
"get_prtfmt",
"(",
"'fmt'",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'# '",
",",
"''",
")",
"# print('PPPPPPPPPPP', prtfmt)",
"if",
"not",
"verbose",
":",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{hdr1usr01:2}'",
",",
"''",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{childcnt:3} L{level:02} '",
",",
"''",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{num_usrgos:>4} uGOs '",
",",
"''",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{D1:5} {REL} {rel}'",
",",
"''",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'R{reldepth:02} '",
",",
"''",
")",
"# print('PPPPPPPPPPP', prtfmt)",
"marks",
"=",
"''",
".",
"join",
"(",
"[",
"'{{{}}}'",
".",
"format",
"(",
"nt",
".",
"hdr",
")",
"for",
"nt",
"in",
"self",
".",
"go_ntsets",
"]",
")",
"return",
"'{MARKS} {PRTFMT}'",
".",
"format",
"(",
"MARKS",
"=",
"marks",
",",
"PRTFMT",
"=",
"prtfmt",
")"
] | Get print format containing markers. | [
"Get",
"print",
"format",
"containing",
"markers",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L113-L126 |
228,331 | tanghaibao/goatools | goatools/cli/compare_gos.py | CompareGOsCli._wr_ver_n_key | def _wr_ver_n_key(self, fout_txt, verbose):
"""Write GO DAG version and key indicating presence of GO ID in a list."""
with open(fout_txt, 'w') as prt:
self._prt_ver_n_key(prt, verbose)
print(' WROTE: {TXT}'.format(TXT=fout_txt)) | python | def _wr_ver_n_key(self, fout_txt, verbose):
"""Write GO DAG version and key indicating presence of GO ID in a list."""
with open(fout_txt, 'w') as prt:
self._prt_ver_n_key(prt, verbose)
print(' WROTE: {TXT}'.format(TXT=fout_txt)) | [
"def",
"_wr_ver_n_key",
"(",
"self",
",",
"fout_txt",
",",
"verbose",
")",
":",
"with",
"open",
"(",
"fout_txt",
",",
"'w'",
")",
"as",
"prt",
":",
"self",
".",
"_prt_ver_n_key",
"(",
"prt",
",",
"verbose",
")",
"print",
"(",
"' WROTE: {TXT}'",
".",
"format",
"(",
"TXT",
"=",
"fout_txt",
")",
")"
] | Write GO DAG version and key indicating presence of GO ID in a list. | [
"Write",
"GO",
"DAG",
"version",
"and",
"key",
"indicating",
"presence",
"of",
"GO",
"ID",
"in",
"a",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L153-L157 |
228,332 | tanghaibao/goatools | goatools/cli/compare_gos.py | CompareGOsCli._prt_ver_n_key | def _prt_ver_n_key(self, prt, verbose):
"""Print GO DAG version and key indicating presence of GO ID in a list."""
pre = '# '
prt.write('# ----------------------------------------------------------------\n')
prt.write('# - Description of GO ID fields\n')
prt.write('# ----------------------------------------------------------------\n')
prt.write("# Versions:\n# {VER}\n".format(VER="\n# ".join(self.objgrpd.ver_list)))
prt.write('\n# Marker keys:\n')
for ntgos in self.go_ntsets:
prt.write('# X -> GO is present in {HDR}\n'.format(HDR=ntgos.hdr))
if verbose:
prt.write('\n# Markers for header GO IDs and user GO IDs:\n')
prt.write("# '**' -> GO term is both a header and a user GO ID\n")
prt.write("# '* ' -> GO term is a header, but not a user GO ID\n")
prt.write("# ' ' -> GO term is a user GO ID\n")
prt.write('\n# GO Namspaces:\n')
prt.write('# BP -> Biological Process\n')
prt.write('# MF -> Molecular Function\n')
prt.write('# CC -> Cellualr Component\n')
if verbose:
prt.write('\n# Example fields: 5 uGOs 362 47 L04 D04 R04\n')
prt.write('# N uGOs -> number of user GO IDs under this GO header\n')
prt.write('# First integer -> number of GO descendants\n')
prt.write('# Second integer -> number of GO children for the current GO ID\n')
prt.write('\n# Depth information:\n')
if not verbose:
prt.write('# int -> number of GO descendants\n')
if verbose:
prt.write('# Lnn -> level (minimum distance from root to node)\n')
prt.write('# Dnn -> depth (maximum distance from root to node)\n')
if verbose:
prt.write('# Rnn -> depth accounting for relationships\n\n')
RelationshipStr().prt_keys(prt, pre)
if verbose:
prt.write('\n')
objd1 = GoDepth1LettersWr(self.gosubdag.rcntobj)
objd1.prt_header(prt, 'DEPTH-01 GO terms and their aliases', pre)
objd1.prt_txt(prt, pre) | python | def _prt_ver_n_key(self, prt, verbose):
"""Print GO DAG version and key indicating presence of GO ID in a list."""
pre = '# '
prt.write('# ----------------------------------------------------------------\n')
prt.write('# - Description of GO ID fields\n')
prt.write('# ----------------------------------------------------------------\n')
prt.write("# Versions:\n# {VER}\n".format(VER="\n# ".join(self.objgrpd.ver_list)))
prt.write('\n# Marker keys:\n')
for ntgos in self.go_ntsets:
prt.write('# X -> GO is present in {HDR}\n'.format(HDR=ntgos.hdr))
if verbose:
prt.write('\n# Markers for header GO IDs and user GO IDs:\n')
prt.write("# '**' -> GO term is both a header and a user GO ID\n")
prt.write("# '* ' -> GO term is a header, but not a user GO ID\n")
prt.write("# ' ' -> GO term is a user GO ID\n")
prt.write('\n# GO Namspaces:\n')
prt.write('# BP -> Biological Process\n')
prt.write('# MF -> Molecular Function\n')
prt.write('# CC -> Cellualr Component\n')
if verbose:
prt.write('\n# Example fields: 5 uGOs 362 47 L04 D04 R04\n')
prt.write('# N uGOs -> number of user GO IDs under this GO header\n')
prt.write('# First integer -> number of GO descendants\n')
prt.write('# Second integer -> number of GO children for the current GO ID\n')
prt.write('\n# Depth information:\n')
if not verbose:
prt.write('# int -> number of GO descendants\n')
if verbose:
prt.write('# Lnn -> level (minimum distance from root to node)\n')
prt.write('# Dnn -> depth (maximum distance from root to node)\n')
if verbose:
prt.write('# Rnn -> depth accounting for relationships\n\n')
RelationshipStr().prt_keys(prt, pre)
if verbose:
prt.write('\n')
objd1 = GoDepth1LettersWr(self.gosubdag.rcntobj)
objd1.prt_header(prt, 'DEPTH-01 GO terms and their aliases', pre)
objd1.prt_txt(prt, pre) | [
"def",
"_prt_ver_n_key",
"(",
"self",
",",
"prt",
",",
"verbose",
")",
":",
"pre",
"=",
"'# '",
"prt",
".",
"write",
"(",
"'# ----------------------------------------------------------------\\n'",
")",
"prt",
".",
"write",
"(",
"'# - Description of GO ID fields\\n'",
")",
"prt",
".",
"write",
"(",
"'# ----------------------------------------------------------------\\n'",
")",
"prt",
".",
"write",
"(",
"\"# Versions:\\n# {VER}\\n\"",
".",
"format",
"(",
"VER",
"=",
"\"\\n# \"",
".",
"join",
"(",
"self",
".",
"objgrpd",
".",
"ver_list",
")",
")",
")",
"prt",
".",
"write",
"(",
"'\\n# Marker keys:\\n'",
")",
"for",
"ntgos",
"in",
"self",
".",
"go_ntsets",
":",
"prt",
".",
"write",
"(",
"'# X -> GO is present in {HDR}\\n'",
".",
"format",
"(",
"HDR",
"=",
"ntgos",
".",
"hdr",
")",
")",
"if",
"verbose",
":",
"prt",
".",
"write",
"(",
"'\\n# Markers for header GO IDs and user GO IDs:\\n'",
")",
"prt",
".",
"write",
"(",
"\"# '**' -> GO term is both a header and a user GO ID\\n\"",
")",
"prt",
".",
"write",
"(",
"\"# '* ' -> GO term is a header, but not a user GO ID\\n\"",
")",
"prt",
".",
"write",
"(",
"\"# ' ' -> GO term is a user GO ID\\n\"",
")",
"prt",
".",
"write",
"(",
"'\\n# GO Namspaces:\\n'",
")",
"prt",
".",
"write",
"(",
"'# BP -> Biological Process\\n'",
")",
"prt",
".",
"write",
"(",
"'# MF -> Molecular Function\\n'",
")",
"prt",
".",
"write",
"(",
"'# CC -> Cellualr Component\\n'",
")",
"if",
"verbose",
":",
"prt",
".",
"write",
"(",
"'\\n# Example fields: 5 uGOs 362 47 L04 D04 R04\\n'",
")",
"prt",
".",
"write",
"(",
"'# N uGOs -> number of user GO IDs under this GO header\\n'",
")",
"prt",
".",
"write",
"(",
"'# First integer -> number of GO descendants\\n'",
")",
"prt",
".",
"write",
"(",
"'# Second integer -> number of GO children for the current GO ID\\n'",
")",
"prt",
".",
"write",
"(",
"'\\n# Depth information:\\n'",
")",
"if",
"not",
"verbose",
":",
"prt",
".",
"write",
"(",
"'# int -> number of GO descendants\\n'",
")",
"if",
"verbose",
":",
"prt",
".",
"write",
"(",
"'# Lnn -> level (minimum distance from root to node)\\n'",
")",
"prt",
".",
"write",
"(",
"'# Dnn -> depth (maximum distance from root to node)\\n'",
")",
"if",
"verbose",
":",
"prt",
".",
"write",
"(",
"'# Rnn -> depth accounting for relationships\\n\\n'",
")",
"RelationshipStr",
"(",
")",
".",
"prt_keys",
"(",
"prt",
",",
"pre",
")",
"if",
"verbose",
":",
"prt",
".",
"write",
"(",
"'\\n'",
")",
"objd1",
"=",
"GoDepth1LettersWr",
"(",
"self",
".",
"gosubdag",
".",
"rcntobj",
")",
"objd1",
".",
"prt_header",
"(",
"prt",
",",
"'DEPTH-01 GO terms and their aliases'",
",",
"pre",
")",
"objd1",
".",
"prt_txt",
"(",
"prt",
",",
"pre",
")"
] | Print GO DAG version and key indicating presence of GO ID in a list. | [
"Print",
"GO",
"DAG",
"version",
"and",
"key",
"indicating",
"presence",
"of",
"GO",
"ID",
"in",
"a",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L160-L197 |
228,333 | tanghaibao/goatools | goatools/cli/compare_gos.py | _Init.get_grouped | def get_grouped(self, go_ntsets, go_all, gosubdag, **kws):
"""Get Grouped object."""
kws_grpd = {k:v for k, v in kws.items() if k in Grouped.kws_dict}
kws_grpd['go2nt'] = self._init_go2ntpresent(go_ntsets, go_all, gosubdag)
return Grouped(gosubdag, self.godag.version, **kws_grpd) | python | def get_grouped(self, go_ntsets, go_all, gosubdag, **kws):
"""Get Grouped object."""
kws_grpd = {k:v for k, v in kws.items() if k in Grouped.kws_dict}
kws_grpd['go2nt'] = self._init_go2ntpresent(go_ntsets, go_all, gosubdag)
return Grouped(gosubdag, self.godag.version, **kws_grpd) | [
"def",
"get_grouped",
"(",
"self",
",",
"go_ntsets",
",",
"go_all",
",",
"gosubdag",
",",
"*",
"*",
"kws",
")",
":",
"kws_grpd",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"kws",
".",
"items",
"(",
")",
"if",
"k",
"in",
"Grouped",
".",
"kws_dict",
"}",
"kws_grpd",
"[",
"'go2nt'",
"]",
"=",
"self",
".",
"_init_go2ntpresent",
"(",
"go_ntsets",
",",
"go_all",
",",
"gosubdag",
")",
"return",
"Grouped",
"(",
"gosubdag",
",",
"self",
".",
"godag",
".",
"version",
",",
"*",
"*",
"kws_grpd",
")"
] | Get Grouped object. | [
"Get",
"Grouped",
"object",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L214-L218 |
228,334 | tanghaibao/goatools | goatools/cli/compare_gos.py | _Init._init_go2ntpresent | def _init_go2ntpresent(go_ntsets, go_all, gosubdag):
"""Mark all GO IDs with an X if present in the user GO list."""
go2ntpresent = {}
ntobj = namedtuple('NtPresent', " ".join(nt.hdr for nt in go_ntsets))
# Get present marks for GO sources
for goid_all in go_all:
present_true = [goid_all in nt.go_set for nt in go_ntsets]
present_str = ['X' if tf else '.' for tf in present_true]
go2ntpresent[goid_all] = ntobj._make(present_str)
# Get present marks for all other GO ancestors
goids_ancestors = set(gosubdag.go2obj).difference(go2ntpresent)
assert not goids_ancestors.intersection(go_all)
strmark = ['.' for _ in range(len(go_ntsets))]
for goid in goids_ancestors:
go2ntpresent[goid] = ntobj._make(strmark)
return go2ntpresent | python | def _init_go2ntpresent(go_ntsets, go_all, gosubdag):
"""Mark all GO IDs with an X if present in the user GO list."""
go2ntpresent = {}
ntobj = namedtuple('NtPresent', " ".join(nt.hdr for nt in go_ntsets))
# Get present marks for GO sources
for goid_all in go_all:
present_true = [goid_all in nt.go_set for nt in go_ntsets]
present_str = ['X' if tf else '.' for tf in present_true]
go2ntpresent[goid_all] = ntobj._make(present_str)
# Get present marks for all other GO ancestors
goids_ancestors = set(gosubdag.go2obj).difference(go2ntpresent)
assert not goids_ancestors.intersection(go_all)
strmark = ['.' for _ in range(len(go_ntsets))]
for goid in goids_ancestors:
go2ntpresent[goid] = ntobj._make(strmark)
return go2ntpresent | [
"def",
"_init_go2ntpresent",
"(",
"go_ntsets",
",",
"go_all",
",",
"gosubdag",
")",
":",
"go2ntpresent",
"=",
"{",
"}",
"ntobj",
"=",
"namedtuple",
"(",
"'NtPresent'",
",",
"\" \"",
".",
"join",
"(",
"nt",
".",
"hdr",
"for",
"nt",
"in",
"go_ntsets",
")",
")",
"# Get present marks for GO sources",
"for",
"goid_all",
"in",
"go_all",
":",
"present_true",
"=",
"[",
"goid_all",
"in",
"nt",
".",
"go_set",
"for",
"nt",
"in",
"go_ntsets",
"]",
"present_str",
"=",
"[",
"'X'",
"if",
"tf",
"else",
"'.'",
"for",
"tf",
"in",
"present_true",
"]",
"go2ntpresent",
"[",
"goid_all",
"]",
"=",
"ntobj",
".",
"_make",
"(",
"present_str",
")",
"# Get present marks for all other GO ancestors",
"goids_ancestors",
"=",
"set",
"(",
"gosubdag",
".",
"go2obj",
")",
".",
"difference",
"(",
"go2ntpresent",
")",
"assert",
"not",
"goids_ancestors",
".",
"intersection",
"(",
"go_all",
")",
"strmark",
"=",
"[",
"'.'",
"for",
"_",
"in",
"range",
"(",
"len",
"(",
"go_ntsets",
")",
")",
"]",
"for",
"goid",
"in",
"goids_ancestors",
":",
"go2ntpresent",
"[",
"goid",
"]",
"=",
"ntobj",
".",
"_make",
"(",
"strmark",
")",
"return",
"go2ntpresent"
] | Mark all GO IDs with an X if present in the user GO list. | [
"Mark",
"all",
"GO",
"IDs",
"with",
"an",
"X",
"if",
"present",
"in",
"the",
"user",
"GO",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L221-L236 |
228,335 | tanghaibao/goatools | goatools/cli/compare_gos.py | _Init.get_go_ntsets | def get_go_ntsets(self, go_fins):
"""For each file containing GOs, extract GO IDs, store filename and header."""
nts = []
ntobj = namedtuple('NtGOFiles', 'hdr go_set, go_fin')
go_sets = self._init_go_sets(go_fins)
hdrs = [os.path.splitext(os.path.basename(f))[0] for f in go_fins]
assert len(go_fins) == len(go_sets)
assert len(go_fins) == len(hdrs)
for hdr, go_set, go_fin in zip(hdrs, go_sets, go_fins):
nts.append(ntobj(hdr=hdr, go_set=go_set, go_fin=go_fin))
return nts | python | def get_go_ntsets(self, go_fins):
"""For each file containing GOs, extract GO IDs, store filename and header."""
nts = []
ntobj = namedtuple('NtGOFiles', 'hdr go_set, go_fin')
go_sets = self._init_go_sets(go_fins)
hdrs = [os.path.splitext(os.path.basename(f))[0] for f in go_fins]
assert len(go_fins) == len(go_sets)
assert len(go_fins) == len(hdrs)
for hdr, go_set, go_fin in zip(hdrs, go_sets, go_fins):
nts.append(ntobj(hdr=hdr, go_set=go_set, go_fin=go_fin))
return nts | [
"def",
"get_go_ntsets",
"(",
"self",
",",
"go_fins",
")",
":",
"nts",
"=",
"[",
"]",
"ntobj",
"=",
"namedtuple",
"(",
"'NtGOFiles'",
",",
"'hdr go_set, go_fin'",
")",
"go_sets",
"=",
"self",
".",
"_init_go_sets",
"(",
"go_fins",
")",
"hdrs",
"=",
"[",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"f",
")",
")",
"[",
"0",
"]",
"for",
"f",
"in",
"go_fins",
"]",
"assert",
"len",
"(",
"go_fins",
")",
"==",
"len",
"(",
"go_sets",
")",
"assert",
"len",
"(",
"go_fins",
")",
"==",
"len",
"(",
"hdrs",
")",
"for",
"hdr",
",",
"go_set",
",",
"go_fin",
"in",
"zip",
"(",
"hdrs",
",",
"go_sets",
",",
"go_fins",
")",
":",
"nts",
".",
"append",
"(",
"ntobj",
"(",
"hdr",
"=",
"hdr",
",",
"go_set",
"=",
"go_set",
",",
"go_fin",
"=",
"go_fin",
")",
")",
"return",
"nts"
] | For each file containing GOs, extract GO IDs, store filename and header. | [
"For",
"each",
"file",
"containing",
"GOs",
"extract",
"GO",
"IDs",
"store",
"filename",
"and",
"header",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L238-L248 |
228,336 | tanghaibao/goatools | goatools/cli/compare_gos.py | _Init._init_go_sets | def _init_go_sets(self, go_fins):
"""Get lists of GO IDs."""
go_sets = []
assert go_fins, "EXPECTED FILES CONTAINING GO IDs"
assert len(go_fins) >= 2, "EXPECTED 2+ GO LISTS. FOUND: {L}".format(
L=' '.join(go_fins))
obj = GetGOs(self.godag)
for fin in go_fins:
assert os.path.exists(fin), "GO FILE({F}) DOES NOT EXIST".format(F=fin)
go_sets.append(obj.get_usrgos(fin, sys.stdout))
return go_sets | python | def _init_go_sets(self, go_fins):
"""Get lists of GO IDs."""
go_sets = []
assert go_fins, "EXPECTED FILES CONTAINING GO IDs"
assert len(go_fins) >= 2, "EXPECTED 2+ GO LISTS. FOUND: {L}".format(
L=' '.join(go_fins))
obj = GetGOs(self.godag)
for fin in go_fins:
assert os.path.exists(fin), "GO FILE({F}) DOES NOT EXIST".format(F=fin)
go_sets.append(obj.get_usrgos(fin, sys.stdout))
return go_sets | [
"def",
"_init_go_sets",
"(",
"self",
",",
"go_fins",
")",
":",
"go_sets",
"=",
"[",
"]",
"assert",
"go_fins",
",",
"\"EXPECTED FILES CONTAINING GO IDs\"",
"assert",
"len",
"(",
"go_fins",
")",
">=",
"2",
",",
"\"EXPECTED 2+ GO LISTS. FOUND: {L}\"",
".",
"format",
"(",
"L",
"=",
"' '",
".",
"join",
"(",
"go_fins",
")",
")",
"obj",
"=",
"GetGOs",
"(",
"self",
".",
"godag",
")",
"for",
"fin",
"in",
"go_fins",
":",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"fin",
")",
",",
"\"GO FILE({F}) DOES NOT EXIST\"",
".",
"format",
"(",
"F",
"=",
"fin",
")",
"go_sets",
".",
"append",
"(",
"obj",
".",
"get_usrgos",
"(",
"fin",
",",
"sys",
".",
"stdout",
")",
")",
"return",
"go_sets"
] | Get lists of GO IDs. | [
"Get",
"lists",
"of",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/compare_gos.py#L250-L260 |
228,337 | tanghaibao/goatools | goatools/gosubdag/godag_rcnt.py | CountRelatives.get_parents_letters | def get_parents_letters(self, goobj):
"""Get the letters representing all parent terms which are depth-01 GO terms."""
parents_all = set.union(self.go2parents[goobj.id])
parents_all.add(goobj.id)
# print "{}({}) D{:02}".format(goobj.id, goobj.name, goobj.depth), parents_all
parents_d1 = parents_all.intersection(self.gos_depth1)
return [self.goone2ntletter[g].D1 for g in parents_d1] | python | def get_parents_letters(self, goobj):
"""Get the letters representing all parent terms which are depth-01 GO terms."""
parents_all = set.union(self.go2parents[goobj.id])
parents_all.add(goobj.id)
# print "{}({}) D{:02}".format(goobj.id, goobj.name, goobj.depth), parents_all
parents_d1 = parents_all.intersection(self.gos_depth1)
return [self.goone2ntletter[g].D1 for g in parents_d1] | [
"def",
"get_parents_letters",
"(",
"self",
",",
"goobj",
")",
":",
"parents_all",
"=",
"set",
".",
"union",
"(",
"self",
".",
"go2parents",
"[",
"goobj",
".",
"id",
"]",
")",
"parents_all",
".",
"add",
"(",
"goobj",
".",
"id",
")",
"# print \"{}({}) D{:02}\".format(goobj.id, goobj.name, goobj.depth), parents_all",
"parents_d1",
"=",
"parents_all",
".",
"intersection",
"(",
"self",
".",
"gos_depth1",
")",
"return",
"[",
"self",
".",
"goone2ntletter",
"[",
"g",
"]",
".",
"D1",
"for",
"g",
"in",
"parents_d1",
"]"
] | Get the letters representing all parent terms which are depth-01 GO terms. | [
"Get",
"the",
"letters",
"representing",
"all",
"parent",
"terms",
"which",
"are",
"depth",
"-",
"01",
"GO",
"terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt.py#L28-L34 |
228,338 | tanghaibao/goatools | goatools/gosubdag/godag_rcnt.py | CountRelatives.get_d1str | def get_d1str(self, goobj, reverse=False):
"""Get D1-string representing all parent terms which are depth-01 GO terms."""
return "".join(sorted(self.get_parents_letters(goobj), reverse=reverse)) | python | def get_d1str(self, goobj, reverse=False):
"""Get D1-string representing all parent terms which are depth-01 GO terms."""
return "".join(sorted(self.get_parents_letters(goobj), reverse=reverse)) | [
"def",
"get_d1str",
"(",
"self",
",",
"goobj",
",",
"reverse",
"=",
"False",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"sorted",
"(",
"self",
".",
"get_parents_letters",
"(",
"goobj",
")",
",",
"reverse",
"=",
"reverse",
")",
")"
] | Get D1-string representing all parent terms which are depth-01 GO terms. | [
"Get",
"D1",
"-",
"string",
"representing",
"all",
"parent",
"terms",
"which",
"are",
"depth",
"-",
"01",
"GO",
"terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt.py#L36-L38 |
228,339 | tanghaibao/goatools | goatools/gosubdag/go_most_specific.py | get_most_specific_dcnt | def get_most_specific_dcnt(goids, go2nt):
"""Get the GO ID with the lowest descendants count."""
# go2nt_usr = {go:go2nt[go] for go in goids}
# return min(go2nt_usr.items(), key=lambda t: t[1].dcnt)[0]
return min(_get_go2nt(goids, go2nt), key=lambda t: t[1].dcnt)[0] | python | def get_most_specific_dcnt(goids, go2nt):
"""Get the GO ID with the lowest descendants count."""
# go2nt_usr = {go:go2nt[go] for go in goids}
# return min(go2nt_usr.items(), key=lambda t: t[1].dcnt)[0]
return min(_get_go2nt(goids, go2nt), key=lambda t: t[1].dcnt)[0] | [
"def",
"get_most_specific_dcnt",
"(",
"goids",
",",
"go2nt",
")",
":",
"# go2nt_usr = {go:go2nt[go] for go in goids}",
"# return min(go2nt_usr.items(), key=lambda t: t[1].dcnt)[0]",
"return",
"min",
"(",
"_get_go2nt",
"(",
"goids",
",",
"go2nt",
")",
",",
"key",
"=",
"lambda",
"t",
":",
"t",
"[",
"1",
"]",
".",
"dcnt",
")",
"[",
"0",
"]"
] | Get the GO ID with the lowest descendants count. | [
"Get",
"the",
"GO",
"ID",
"with",
"the",
"lowest",
"descendants",
"count",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_most_specific.py#L7-L11 |
228,340 | tanghaibao/goatools | goatools/gosubdag/go_most_specific.py | _get_go2nt | def _get_go2nt(goids, go2nt_all):
"""Get user go2nt using main GO IDs, not alt IDs."""
go_nt_list = []
goids_seen = set()
for goid_usr in goids:
ntgo = go2nt_all[goid_usr]
goid_main = ntgo.id
if goid_main not in goids_seen:
goids_seen.add(goid_main)
go_nt_list.append((goid_main, ntgo))
return go_nt_list | python | def _get_go2nt(goids, go2nt_all):
"""Get user go2nt using main GO IDs, not alt IDs."""
go_nt_list = []
goids_seen = set()
for goid_usr in goids:
ntgo = go2nt_all[goid_usr]
goid_main = ntgo.id
if goid_main not in goids_seen:
goids_seen.add(goid_main)
go_nt_list.append((goid_main, ntgo))
return go_nt_list | [
"def",
"_get_go2nt",
"(",
"goids",
",",
"go2nt_all",
")",
":",
"go_nt_list",
"=",
"[",
"]",
"goids_seen",
"=",
"set",
"(",
")",
"for",
"goid_usr",
"in",
"goids",
":",
"ntgo",
"=",
"go2nt_all",
"[",
"goid_usr",
"]",
"goid_main",
"=",
"ntgo",
".",
"id",
"if",
"goid_main",
"not",
"in",
"goids_seen",
":",
"goids_seen",
".",
"add",
"(",
"goid_main",
")",
"go_nt_list",
".",
"append",
"(",
"(",
"goid_main",
",",
"ntgo",
")",
")",
"return",
"go_nt_list"
] | Get user go2nt using main GO IDs, not alt IDs. | [
"Get",
"user",
"go2nt",
"using",
"main",
"GO",
"IDs",
"not",
"alt",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_most_specific.py#L25-L35 |
228,341 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | AArtGeneProductSetsOne.prt_gos_grouped | def prt_gos_grouped(self, prt, **kws_grp):
"""Print grouped GO list."""
prtfmt = self.datobj.kws['fmtgo']
wrobj = WrXlsxSortedGos(self.name, self.sortobj)
# Keyword arguments: control content: hdrgo_prt section_prt top_n use_sections
desc2nts = self.sortobj.get_desc2nts(**kws_grp)
wrobj.prt_txt_desc2nts(prt, desc2nts, prtfmt) | python | def prt_gos_grouped(self, prt, **kws_grp):
"""Print grouped GO list."""
prtfmt = self.datobj.kws['fmtgo']
wrobj = WrXlsxSortedGos(self.name, self.sortobj)
# Keyword arguments: control content: hdrgo_prt section_prt top_n use_sections
desc2nts = self.sortobj.get_desc2nts(**kws_grp)
wrobj.prt_txt_desc2nts(prt, desc2nts, prtfmt) | [
"def",
"prt_gos_grouped",
"(",
"self",
",",
"prt",
",",
"*",
"*",
"kws_grp",
")",
":",
"prtfmt",
"=",
"self",
".",
"datobj",
".",
"kws",
"[",
"'fmtgo'",
"]",
"wrobj",
"=",
"WrXlsxSortedGos",
"(",
"self",
".",
"name",
",",
"self",
".",
"sortobj",
")",
"# Keyword arguments: control content: hdrgo_prt section_prt top_n use_sections",
"desc2nts",
"=",
"self",
".",
"sortobj",
".",
"get_desc2nts",
"(",
"*",
"*",
"kws_grp",
")",
"wrobj",
".",
"prt_txt_desc2nts",
"(",
"prt",
",",
"desc2nts",
",",
"prtfmt",
")"
] | Print grouped GO list. | [
"Print",
"grouped",
"GO",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L74-L80 |
228,342 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | AArtGeneProductSetsOne.prt_gos_flat | def prt_gos_flat(self, prt):
"""Print flat GO list."""
prtfmt = self.datobj.kws['fmtgo']
_go2nt = self.sortobj.grprobj.go2nt
go2nt = {go:_go2nt[go] for go in self.go2nt}
prt.write("\n{N} GO IDs:\n".format(N=len(go2nt)))
_sortby = self._get_sortgo()
for ntgo in sorted(go2nt.values(), key=_sortby):
prt.write(prtfmt.format(**ntgo._asdict())) | python | def prt_gos_flat(self, prt):
"""Print flat GO list."""
prtfmt = self.datobj.kws['fmtgo']
_go2nt = self.sortobj.grprobj.go2nt
go2nt = {go:_go2nt[go] for go in self.go2nt}
prt.write("\n{N} GO IDs:\n".format(N=len(go2nt)))
_sortby = self._get_sortgo()
for ntgo in sorted(go2nt.values(), key=_sortby):
prt.write(prtfmt.format(**ntgo._asdict())) | [
"def",
"prt_gos_flat",
"(",
"self",
",",
"prt",
")",
":",
"prtfmt",
"=",
"self",
".",
"datobj",
".",
"kws",
"[",
"'fmtgo'",
"]",
"_go2nt",
"=",
"self",
".",
"sortobj",
".",
"grprobj",
".",
"go2nt",
"go2nt",
"=",
"{",
"go",
":",
"_go2nt",
"[",
"go",
"]",
"for",
"go",
"in",
"self",
".",
"go2nt",
"}",
"prt",
".",
"write",
"(",
"\"\\n{N} GO IDs:\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"go2nt",
")",
")",
")",
"_sortby",
"=",
"self",
".",
"_get_sortgo",
"(",
")",
"for",
"ntgo",
"in",
"sorted",
"(",
"go2nt",
".",
"values",
"(",
")",
",",
"key",
"=",
"_sortby",
")",
":",
"prt",
".",
"write",
"(",
"prtfmt",
".",
"format",
"(",
"*",
"*",
"ntgo",
".",
"_asdict",
"(",
")",
")",
")"
] | Print flat GO list. | [
"Print",
"flat",
"GO",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L82-L90 |
228,343 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | AArtGeneProductSetsOne._get_sortgo | def _get_sortgo(self):
"""Get function for sorting GO terms in a list of namedtuples."""
if 'sortgo' in self.datobj.kws:
return self.datobj.kws['sortgo']
return self.datobj.grprdflt.gosubdag.prt_attr['sort'] + "\n" | python | def _get_sortgo(self):
"""Get function for sorting GO terms in a list of namedtuples."""
if 'sortgo' in self.datobj.kws:
return self.datobj.kws['sortgo']
return self.datobj.grprdflt.gosubdag.prt_attr['sort'] + "\n" | [
"def",
"_get_sortgo",
"(",
"self",
")",
":",
"if",
"'sortgo'",
"in",
"self",
".",
"datobj",
".",
"kws",
":",
"return",
"self",
".",
"datobj",
".",
"kws",
"[",
"'sortgo'",
"]",
"return",
"self",
".",
"datobj",
".",
"grprdflt",
".",
"gosubdag",
".",
"prt_attr",
"[",
"'sort'",
"]",
"+",
"\"\\n\""
] | Get function for sorting GO terms in a list of namedtuples. | [
"Get",
"function",
"for",
"sorting",
"GO",
"terms",
"in",
"a",
"list",
"of",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L93-L97 |
228,344 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | AArtGeneProductSetsOne.get_gene2binvec | def get_gene2binvec(self):
"""Return a boolean vector for each gene representing GO section membership."""
_sec2chr = self.sec2chr
return {g:[s in s2gos for s in _sec2chr] for g, s2gos in self.gene2section2gos.items()} | python | def get_gene2binvec(self):
"""Return a boolean vector for each gene representing GO section membership."""
_sec2chr = self.sec2chr
return {g:[s in s2gos for s in _sec2chr] for g, s2gos in self.gene2section2gos.items()} | [
"def",
"get_gene2binvec",
"(",
"self",
")",
":",
"_sec2chr",
"=",
"self",
".",
"sec2chr",
"return",
"{",
"g",
":",
"[",
"s",
"in",
"s2gos",
"for",
"s",
"in",
"_sec2chr",
"]",
"for",
"g",
",",
"s2gos",
"in",
"self",
".",
"gene2section2gos",
".",
"items",
"(",
")",
"}"
] | Return a boolean vector for each gene representing GO section membership. | [
"Return",
"a",
"boolean",
"vector",
"for",
"each",
"gene",
"representing",
"GO",
"section",
"membership",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L140-L143 |
228,345 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | _Init.get_go2nt | def get_go2nt(self, goea_results):
"""Return go2nt with added formatted string versions of the P-values."""
go2obj = self.objaartall.grprdflt.gosubdag.go2obj
# Add string version of P-values
goea_nts = MgrNtGOEAs(goea_results).get_nts_strpval()
return {go2obj[nt.GO].id:nt for nt in goea_nts if nt.GO in go2obj} | python | def get_go2nt(self, goea_results):
"""Return go2nt with added formatted string versions of the P-values."""
go2obj = self.objaartall.grprdflt.gosubdag.go2obj
# Add string version of P-values
goea_nts = MgrNtGOEAs(goea_results).get_nts_strpval()
return {go2obj[nt.GO].id:nt for nt in goea_nts if nt.GO in go2obj} | [
"def",
"get_go2nt",
"(",
"self",
",",
"goea_results",
")",
":",
"go2obj",
"=",
"self",
".",
"objaartall",
".",
"grprdflt",
".",
"gosubdag",
".",
"go2obj",
"# Add string version of P-values",
"goea_nts",
"=",
"MgrNtGOEAs",
"(",
"goea_results",
")",
".",
"get_nts_strpval",
"(",
")",
"return",
"{",
"go2obj",
"[",
"nt",
".",
"GO",
"]",
".",
"id",
":",
"nt",
"for",
"nt",
"in",
"goea_nts",
"if",
"nt",
".",
"GO",
"in",
"go2obj",
"}"
] | Return go2nt with added formatted string versions of the P-values. | [
"Return",
"go2nt",
"with",
"added",
"formatted",
"string",
"versions",
"of",
"the",
"P",
"-",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L151-L156 |
228,346 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | _Init.get_sec2gos | def get_sec2gos(sortobj):
"""Initialize section_name2goids."""
sec_gos = []
for section_name, nts in sortobj.get_desc2nts_fnc(hdrgo_prt=True)['sections']:
sec_gos.append((section_name, set(nt.GO for nt in nts)))
return cx.OrderedDict(sec_gos) | python | def get_sec2gos(sortobj):
"""Initialize section_name2goids."""
sec_gos = []
for section_name, nts in sortobj.get_desc2nts_fnc(hdrgo_prt=True)['sections']:
sec_gos.append((section_name, set(nt.GO for nt in nts)))
return cx.OrderedDict(sec_gos) | [
"def",
"get_sec2gos",
"(",
"sortobj",
")",
":",
"sec_gos",
"=",
"[",
"]",
"for",
"section_name",
",",
"nts",
"in",
"sortobj",
".",
"get_desc2nts_fnc",
"(",
"hdrgo_prt",
"=",
"True",
")",
"[",
"'sections'",
"]",
":",
"sec_gos",
".",
"append",
"(",
"(",
"section_name",
",",
"set",
"(",
"nt",
".",
"GO",
"for",
"nt",
"in",
"nts",
")",
")",
")",
"return",
"cx",
".",
"OrderedDict",
"(",
"sec_gos",
")"
] | Initialize section_name2goids. | [
"Initialize",
"section_name2goids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L159-L164 |
228,347 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | _Init.get_gene2gos | def get_gene2gos(go2nt):
"""Create a gene product to GO set dict."""
gene2gos = cx.defaultdict(set)
nt0 = next(iter(go2nt.values()))
b_str = isinstance(nt0.study_items, str)
# print("NNNNTTTT", nt0)
for goid, ntgo in go2nt.items():
study_items = ntgo.study_items.split(', ') if b_str else ntgo.study_items
for geneid in study_items:
gene2gos[geneid].add(goid)
if b_str:
b_set = set(isinstance(g.isdigit(), int) for g in nt0.study_items.split(', '))
if b_set == set([True]):
return {int(g):gos for g, gos in gene2gos.items()}
return {g:gos for g, gos in gene2gos.items()} | python | def get_gene2gos(go2nt):
"""Create a gene product to GO set dict."""
gene2gos = cx.defaultdict(set)
nt0 = next(iter(go2nt.values()))
b_str = isinstance(nt0.study_items, str)
# print("NNNNTTTT", nt0)
for goid, ntgo in go2nt.items():
study_items = ntgo.study_items.split(', ') if b_str else ntgo.study_items
for geneid in study_items:
gene2gos[geneid].add(goid)
if b_str:
b_set = set(isinstance(g.isdigit(), int) for g in nt0.study_items.split(', '))
if b_set == set([True]):
return {int(g):gos for g, gos in gene2gos.items()}
return {g:gos for g, gos in gene2gos.items()} | [
"def",
"get_gene2gos",
"(",
"go2nt",
")",
":",
"gene2gos",
"=",
"cx",
".",
"defaultdict",
"(",
"set",
")",
"nt0",
"=",
"next",
"(",
"iter",
"(",
"go2nt",
".",
"values",
"(",
")",
")",
")",
"b_str",
"=",
"isinstance",
"(",
"nt0",
".",
"study_items",
",",
"str",
")",
"# print(\"NNNNTTTT\", nt0)",
"for",
"goid",
",",
"ntgo",
"in",
"go2nt",
".",
"items",
"(",
")",
":",
"study_items",
"=",
"ntgo",
".",
"study_items",
".",
"split",
"(",
"', '",
")",
"if",
"b_str",
"else",
"ntgo",
".",
"study_items",
"for",
"geneid",
"in",
"study_items",
":",
"gene2gos",
"[",
"geneid",
"]",
".",
"add",
"(",
"goid",
")",
"if",
"b_str",
":",
"b_set",
"=",
"set",
"(",
"isinstance",
"(",
"g",
".",
"isdigit",
"(",
")",
",",
"int",
")",
"for",
"g",
"in",
"nt0",
".",
"study_items",
".",
"split",
"(",
"', '",
")",
")",
"if",
"b_set",
"==",
"set",
"(",
"[",
"True",
"]",
")",
":",
"return",
"{",
"int",
"(",
"g",
")",
":",
"gos",
"for",
"g",
",",
"gos",
"in",
"gene2gos",
".",
"items",
"(",
")",
"}",
"return",
"{",
"g",
":",
"gos",
"for",
"g",
",",
"gos",
"in",
"gene2gos",
".",
"items",
"(",
")",
"}"
] | Create a gene product to GO set dict. | [
"Create",
"a",
"gene",
"product",
"to",
"GO",
"set",
"dict",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L167-L181 |
228,348 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | _Init.get_gene2aart | def get_gene2aart(gene2section2gos, sec2chr):
"""Return a string for each gene representing GO section membership."""
geneid2str = {}
for geneid, section2gos_gene in gene2section2gos.items():
letters = [abc if s in section2gos_gene else "." for s, abc in sec2chr.items()]
geneid2str[geneid] = "".join(letters)
return geneid2str | python | def get_gene2aart(gene2section2gos, sec2chr):
"""Return a string for each gene representing GO section membership."""
geneid2str = {}
for geneid, section2gos_gene in gene2section2gos.items():
letters = [abc if s in section2gos_gene else "." for s, abc in sec2chr.items()]
geneid2str[geneid] = "".join(letters)
return geneid2str | [
"def",
"get_gene2aart",
"(",
"gene2section2gos",
",",
"sec2chr",
")",
":",
"geneid2str",
"=",
"{",
"}",
"for",
"geneid",
",",
"section2gos_gene",
"in",
"gene2section2gos",
".",
"items",
"(",
")",
":",
"letters",
"=",
"[",
"abc",
"if",
"s",
"in",
"section2gos_gene",
"else",
"\".\"",
"for",
"s",
",",
"abc",
"in",
"sec2chr",
".",
"items",
"(",
")",
"]",
"geneid2str",
"[",
"geneid",
"]",
"=",
"\"\"",
".",
"join",
"(",
"letters",
")",
"return",
"geneid2str"
] | Return a string for each gene representing GO section membership. | [
"Return",
"a",
"string",
"for",
"each",
"gene",
"representing",
"GO",
"section",
"membership",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L192-L198 |
228,349 | tanghaibao/goatools | goatools/grouper/aart_geneproducts_one.py | _Init.get_gene2section2gos | def get_gene2section2gos(gene2gos, sec2gos):
"""Get a list of section aliases for each gene product ID."""
gene2section2gos = {}
for geneid, gos_gene in gene2gos.items():
section2gos = {}
for section_name, gos_sec in sec2gos.items():
gos_secgene = gos_gene.intersection(gos_sec)
if gos_secgene:
section2gos[section_name] = gos_secgene
gene2section2gos[geneid] = section2gos
return gene2section2gos | python | def get_gene2section2gos(gene2gos, sec2gos):
"""Get a list of section aliases for each gene product ID."""
gene2section2gos = {}
for geneid, gos_gene in gene2gos.items():
section2gos = {}
for section_name, gos_sec in sec2gos.items():
gos_secgene = gos_gene.intersection(gos_sec)
if gos_secgene:
section2gos[section_name] = gos_secgene
gene2section2gos[geneid] = section2gos
return gene2section2gos | [
"def",
"get_gene2section2gos",
"(",
"gene2gos",
",",
"sec2gos",
")",
":",
"gene2section2gos",
"=",
"{",
"}",
"for",
"geneid",
",",
"gos_gene",
"in",
"gene2gos",
".",
"items",
"(",
")",
":",
"section2gos",
"=",
"{",
"}",
"for",
"section_name",
",",
"gos_sec",
"in",
"sec2gos",
".",
"items",
"(",
")",
":",
"gos_secgene",
"=",
"gos_gene",
".",
"intersection",
"(",
"gos_sec",
")",
"if",
"gos_secgene",
":",
"section2gos",
"[",
"section_name",
"]",
"=",
"gos_secgene",
"gene2section2gos",
"[",
"geneid",
"]",
"=",
"section2gos",
"return",
"gene2section2gos"
] | Get a list of section aliases for each gene product ID. | [
"Get",
"a",
"list",
"of",
"section",
"aliases",
"for",
"each",
"gene",
"product",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_one.py#L201-L211 |
228,350 | tanghaibao/goatools | goatools/gosubdag/plot/gosubdag_plot.py | GoSubDagPlot._init_objcolor | def _init_objcolor(self, node_opts, **kwu):
"""Return user-created Go2Color object or create one."""
objgoea = node_opts.kws['dict'].get('objgoea', None)
# kwu: go2color go2bordercolor dflt_bordercolor key2col
return Go2Color(self.gosubdag, objgoea, **kwu) | python | def _init_objcolor(self, node_opts, **kwu):
"""Return user-created Go2Color object or create one."""
objgoea = node_opts.kws['dict'].get('objgoea', None)
# kwu: go2color go2bordercolor dflt_bordercolor key2col
return Go2Color(self.gosubdag, objgoea, **kwu) | [
"def",
"_init_objcolor",
"(",
"self",
",",
"node_opts",
",",
"*",
"*",
"kwu",
")",
":",
"objgoea",
"=",
"node_opts",
".",
"kws",
"[",
"'dict'",
"]",
".",
"get",
"(",
"'objgoea'",
",",
"None",
")",
"# kwu: go2color go2bordercolor dflt_bordercolor key2col",
"return",
"Go2Color",
"(",
"self",
".",
"gosubdag",
",",
"objgoea",
",",
"*",
"*",
"kwu",
")"
] | Return user-created Go2Color object or create one. | [
"Return",
"user",
"-",
"created",
"Go2Color",
"object",
"or",
"create",
"one",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/gosubdag_plot.py#L104-L108 |
228,351 | tanghaibao/goatools | goatools/gosubdag/plot/gosubdag_plot.py | GoSubDagPlot._init_gonodeopts | def _init_gonodeopts(self, **kws_usr):
"""Initialize a GO Node plot options object, GoNodeOpts."""
options = GoNodeOpts(self.gosubdag, **self.kws['node_go'])
# Add parent edge count if either is in kws: parentcnt, prt_pcnt
if not options.kws['set'].isdisjoint(['parentcnt', 'prt_pcnt']):
options.kws['dict']['c2ps'] = self.edgesobj.get_c2ps()
# GoeaResults(kws['goea_results'], **self.kws['goea']) if 'goea_results' in kws else None
if 'goea_results' in kws_usr:
objgoea = GoeaResults(kws_usr['goea_results'], **self.kws['goea'])
options.kws['dict']['objgoea'] = objgoea
return options | python | def _init_gonodeopts(self, **kws_usr):
"""Initialize a GO Node plot options object, GoNodeOpts."""
options = GoNodeOpts(self.gosubdag, **self.kws['node_go'])
# Add parent edge count if either is in kws: parentcnt, prt_pcnt
if not options.kws['set'].isdisjoint(['parentcnt', 'prt_pcnt']):
options.kws['dict']['c2ps'] = self.edgesobj.get_c2ps()
# GoeaResults(kws['goea_results'], **self.kws['goea']) if 'goea_results' in kws else None
if 'goea_results' in kws_usr:
objgoea = GoeaResults(kws_usr['goea_results'], **self.kws['goea'])
options.kws['dict']['objgoea'] = objgoea
return options | [
"def",
"_init_gonodeopts",
"(",
"self",
",",
"*",
"*",
"kws_usr",
")",
":",
"options",
"=",
"GoNodeOpts",
"(",
"self",
".",
"gosubdag",
",",
"*",
"*",
"self",
".",
"kws",
"[",
"'node_go'",
"]",
")",
"# Add parent edge count if either is in kws: parentcnt, prt_pcnt",
"if",
"not",
"options",
".",
"kws",
"[",
"'set'",
"]",
".",
"isdisjoint",
"(",
"[",
"'parentcnt'",
",",
"'prt_pcnt'",
"]",
")",
":",
"options",
".",
"kws",
"[",
"'dict'",
"]",
"[",
"'c2ps'",
"]",
"=",
"self",
".",
"edgesobj",
".",
"get_c2ps",
"(",
")",
"# GoeaResults(kws['goea_results'], **self.kws['goea']) if 'goea_results' in kws else None",
"if",
"'goea_results'",
"in",
"kws_usr",
":",
"objgoea",
"=",
"GoeaResults",
"(",
"kws_usr",
"[",
"'goea_results'",
"]",
",",
"*",
"*",
"self",
".",
"kws",
"[",
"'goea'",
"]",
")",
"options",
".",
"kws",
"[",
"'dict'",
"]",
"[",
"'objgoea'",
"]",
"=",
"objgoea",
"return",
"options"
] | Initialize a GO Node plot options object, GoNodeOpts. | [
"Initialize",
"a",
"GO",
"Node",
"plot",
"options",
"object",
"GoNodeOpts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/gosubdag_plot.py#L110-L120 |
228,352 | tanghaibao/goatools | goatools/gosubdag/plot/gosubdag_plot.py | GoSubDagPlot.prt_goids | def prt_goids(self, prt):
"""Print all GO IDs in the plot, plus their color."""
fmt = self.gosubdag.prt_attr['fmta']
nts = sorted(self.gosubdag.go2nt.values(), key=lambda nt: [nt.NS, nt.depth, nt.alt])
_get_color = self.pydotnodego.go2color.get
for ntgo in nts:
gostr = fmt.format(**ntgo._asdict())
col = _get_color(ntgo.GO, "")
prt.write("{COLOR:7} {GO}\n".format(COLOR=col, GO=gostr)) | python | def prt_goids(self, prt):
"""Print all GO IDs in the plot, plus their color."""
fmt = self.gosubdag.prt_attr['fmta']
nts = sorted(self.gosubdag.go2nt.values(), key=lambda nt: [nt.NS, nt.depth, nt.alt])
_get_color = self.pydotnodego.go2color.get
for ntgo in nts:
gostr = fmt.format(**ntgo._asdict())
col = _get_color(ntgo.GO, "")
prt.write("{COLOR:7} {GO}\n".format(COLOR=col, GO=gostr)) | [
"def",
"prt_goids",
"(",
"self",
",",
"prt",
")",
":",
"fmt",
"=",
"self",
".",
"gosubdag",
".",
"prt_attr",
"[",
"'fmta'",
"]",
"nts",
"=",
"sorted",
"(",
"self",
".",
"gosubdag",
".",
"go2nt",
".",
"values",
"(",
")",
",",
"key",
"=",
"lambda",
"nt",
":",
"[",
"nt",
".",
"NS",
",",
"nt",
".",
"depth",
",",
"nt",
".",
"alt",
"]",
")",
"_get_color",
"=",
"self",
".",
"pydotnodego",
".",
"go2color",
".",
"get",
"for",
"ntgo",
"in",
"nts",
":",
"gostr",
"=",
"fmt",
".",
"format",
"(",
"*",
"*",
"ntgo",
".",
"_asdict",
"(",
")",
")",
"col",
"=",
"_get_color",
"(",
"ntgo",
".",
"GO",
",",
"\"\"",
")",
"prt",
".",
"write",
"(",
"\"{COLOR:7} {GO}\\n\"",
".",
"format",
"(",
"COLOR",
"=",
"col",
",",
"GO",
"=",
"gostr",
")",
")"
] | Print all GO IDs in the plot, plus their color. | [
"Print",
"all",
"GO",
"IDs",
"in",
"the",
"plot",
"plus",
"their",
"color",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/gosubdag_plot.py#L122-L130 |
228,353 | tanghaibao/goatools | goatools/gosubdag/plot/gosubdag_plot.py | GoSubDagPlot._init_kws | def _init_kws(self, **kws_usr):
"""Return a dict containing user-specified plotting options."""
kws_self = {}
user_keys = set(kws_usr)
for objname, expset in self.exp_keys.items():
usrkeys_curr = user_keys.intersection(expset)
kws_self[objname] = get_kwargs(kws_usr, usrkeys_curr, usrkeys_curr)
dpi = str(kws_self['dag'].get('dpi', self.dflts['dpi']))
kws_self['dag']['dpi'] = dpi
return kws_self | python | def _init_kws(self, **kws_usr):
"""Return a dict containing user-specified plotting options."""
kws_self = {}
user_keys = set(kws_usr)
for objname, expset in self.exp_keys.items():
usrkeys_curr = user_keys.intersection(expset)
kws_self[objname] = get_kwargs(kws_usr, usrkeys_curr, usrkeys_curr)
dpi = str(kws_self['dag'].get('dpi', self.dflts['dpi']))
kws_self['dag']['dpi'] = dpi
return kws_self | [
"def",
"_init_kws",
"(",
"self",
",",
"*",
"*",
"kws_usr",
")",
":",
"kws_self",
"=",
"{",
"}",
"user_keys",
"=",
"set",
"(",
"kws_usr",
")",
"for",
"objname",
",",
"expset",
"in",
"self",
".",
"exp_keys",
".",
"items",
"(",
")",
":",
"usrkeys_curr",
"=",
"user_keys",
".",
"intersection",
"(",
"expset",
")",
"kws_self",
"[",
"objname",
"]",
"=",
"get_kwargs",
"(",
"kws_usr",
",",
"usrkeys_curr",
",",
"usrkeys_curr",
")",
"dpi",
"=",
"str",
"(",
"kws_self",
"[",
"'dag'",
"]",
".",
"get",
"(",
"'dpi'",
",",
"self",
".",
"dflts",
"[",
"'dpi'",
"]",
")",
")",
"kws_self",
"[",
"'dag'",
"]",
"[",
"'dpi'",
"]",
"=",
"dpi",
"return",
"kws_self"
] | Return a dict containing user-specified plotting options. | [
"Return",
"a",
"dict",
"containing",
"user",
"-",
"specified",
"plotting",
"options",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/gosubdag_plot.py#L132-L141 |
228,354 | tanghaibao/goatools | goatools/gosubdag/plot/gosubdag_plot.py | GoSubDagPlot._prt_edge | def _prt_edge(dag_edge, attr):
"""Print edge attribute"""
# sequence parent_graph points attributes type parent_edge_list
print("Edge {ATTR}: {VAL}".format(ATTR=attr, VAL=dag_edge.obj_dict[attr])) | python | def _prt_edge(dag_edge, attr):
"""Print edge attribute"""
# sequence parent_graph points attributes type parent_edge_list
print("Edge {ATTR}: {VAL}".format(ATTR=attr, VAL=dag_edge.obj_dict[attr])) | [
"def",
"_prt_edge",
"(",
"dag_edge",
",",
"attr",
")",
":",
"# sequence parent_graph points attributes type parent_edge_list",
"print",
"(",
"\"Edge {ATTR}: {VAL}\"",
".",
"format",
"(",
"ATTR",
"=",
"attr",
",",
"VAL",
"=",
"dag_edge",
".",
"obj_dict",
"[",
"attr",
"]",
")",
")"
] | Print edge attribute | [
"Print",
"edge",
"attribute"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/gosubdag_plot.py#L205-L208 |
228,355 | tanghaibao/goatools | goatools/gosubdag/gosubdag.py | GoSubDag.prt_goids | def prt_goids(self, goids=None, prtfmt=None, sortby=True, prt=sys.stdout):
"""Given GO IDs, print decriptive info about each GO Term."""
if goids is None:
goids = self.go_sources
nts = self.get_nts(goids, sortby)
if prtfmt is None:
prtfmt = self.prt_attr['fmta']
for ntgo in nts:
key2val = ntgo._asdict()
prt.write("{GO}\n".format(GO=prtfmt.format(**key2val)))
return nts | python | def prt_goids(self, goids=None, prtfmt=None, sortby=True, prt=sys.stdout):
"""Given GO IDs, print decriptive info about each GO Term."""
if goids is None:
goids = self.go_sources
nts = self.get_nts(goids, sortby)
if prtfmt is None:
prtfmt = self.prt_attr['fmta']
for ntgo in nts:
key2val = ntgo._asdict()
prt.write("{GO}\n".format(GO=prtfmt.format(**key2val)))
return nts | [
"def",
"prt_goids",
"(",
"self",
",",
"goids",
"=",
"None",
",",
"prtfmt",
"=",
"None",
",",
"sortby",
"=",
"True",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"if",
"goids",
"is",
"None",
":",
"goids",
"=",
"self",
".",
"go_sources",
"nts",
"=",
"self",
".",
"get_nts",
"(",
"goids",
",",
"sortby",
")",
"if",
"prtfmt",
"is",
"None",
":",
"prtfmt",
"=",
"self",
".",
"prt_attr",
"[",
"'fmta'",
"]",
"for",
"ntgo",
"in",
"nts",
":",
"key2val",
"=",
"ntgo",
".",
"_asdict",
"(",
")",
"prt",
".",
"write",
"(",
"\"{GO}\\n\"",
".",
"format",
"(",
"GO",
"=",
"prtfmt",
".",
"format",
"(",
"*",
"*",
"key2val",
")",
")",
")",
"return",
"nts"
] | Given GO IDs, print decriptive info about each GO Term. | [
"Given",
"GO",
"IDs",
"print",
"decriptive",
"info",
"about",
"each",
"GO",
"Term",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag.py#L42-L52 |
228,356 | tanghaibao/goatools | goatools/gosubdag/gosubdag.py | GoSubDag.get_nts | def get_nts(self, goids=None, sortby=None):
"""Given GO IDs, get a list of namedtuples."""
nts = []
# User GO IDs
if goids is None:
goids = self.go_sources
else:
chk_goids(goids, "GoSubDag::get_nts")
if goids:
ntobj = cx.namedtuple("NtGo", " ".join(self.prt_attr['flds']))
go2nt = self.get_go2nt(goids)
for goid, ntgo in self._get_sorted_go2nt(go2nt, sortby):
assert ntgo is not None, "{GO} NOT IN go2nt".format(GO=goid)
if goid == ntgo.GO:
nts.append(ntgo)
else:
fld2vals = ntgo._asdict()
fld2vals['GO'] = goid
nts.append(ntobj(**fld2vals))
return nts | python | def get_nts(self, goids=None, sortby=None):
"""Given GO IDs, get a list of namedtuples."""
nts = []
# User GO IDs
if goids is None:
goids = self.go_sources
else:
chk_goids(goids, "GoSubDag::get_nts")
if goids:
ntobj = cx.namedtuple("NtGo", " ".join(self.prt_attr['flds']))
go2nt = self.get_go2nt(goids)
for goid, ntgo in self._get_sorted_go2nt(go2nt, sortby):
assert ntgo is not None, "{GO} NOT IN go2nt".format(GO=goid)
if goid == ntgo.GO:
nts.append(ntgo)
else:
fld2vals = ntgo._asdict()
fld2vals['GO'] = goid
nts.append(ntobj(**fld2vals))
return nts | [
"def",
"get_nts",
"(",
"self",
",",
"goids",
"=",
"None",
",",
"sortby",
"=",
"None",
")",
":",
"nts",
"=",
"[",
"]",
"# User GO IDs",
"if",
"goids",
"is",
"None",
":",
"goids",
"=",
"self",
".",
"go_sources",
"else",
":",
"chk_goids",
"(",
"goids",
",",
"\"GoSubDag::get_nts\"",
")",
"if",
"goids",
":",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"\"NtGo\"",
",",
"\" \"",
".",
"join",
"(",
"self",
".",
"prt_attr",
"[",
"'flds'",
"]",
")",
")",
"go2nt",
"=",
"self",
".",
"get_go2nt",
"(",
"goids",
")",
"for",
"goid",
",",
"ntgo",
"in",
"self",
".",
"_get_sorted_go2nt",
"(",
"go2nt",
",",
"sortby",
")",
":",
"assert",
"ntgo",
"is",
"not",
"None",
",",
"\"{GO} NOT IN go2nt\"",
".",
"format",
"(",
"GO",
"=",
"goid",
")",
"if",
"goid",
"==",
"ntgo",
".",
"GO",
":",
"nts",
".",
"append",
"(",
"ntgo",
")",
"else",
":",
"fld2vals",
"=",
"ntgo",
".",
"_asdict",
"(",
")",
"fld2vals",
"[",
"'GO'",
"]",
"=",
"goid",
"nts",
".",
"append",
"(",
"ntobj",
"(",
"*",
"*",
"fld2vals",
")",
")",
"return",
"nts"
] | Given GO IDs, get a list of namedtuples. | [
"Given",
"GO",
"IDs",
"get",
"a",
"list",
"of",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag.py#L54-L73 |
228,357 | tanghaibao/goatools | goatools/gosubdag/gosubdag.py | GoSubDag.get_go2nt | def get_go2nt(self, goids):
"""Return dict of GO ID as key and GO object information in namedtuple."""
get_nt = self.go2nt
goids_present = set(goids).intersection(self.go2obj)
if len(goids_present) != len(goids):
print("GO IDs NOT FOUND IN DAG: {GOs}".format(
GOs=" ".join(set(goids).difference(goids_present))))
return {g:get_nt[g] for g in goids_present} | python | def get_go2nt(self, goids):
"""Return dict of GO ID as key and GO object information in namedtuple."""
get_nt = self.go2nt
goids_present = set(goids).intersection(self.go2obj)
if len(goids_present) != len(goids):
print("GO IDs NOT FOUND IN DAG: {GOs}".format(
GOs=" ".join(set(goids).difference(goids_present))))
return {g:get_nt[g] for g in goids_present} | [
"def",
"get_go2nt",
"(",
"self",
",",
"goids",
")",
":",
"get_nt",
"=",
"self",
".",
"go2nt",
"goids_present",
"=",
"set",
"(",
"goids",
")",
".",
"intersection",
"(",
"self",
".",
"go2obj",
")",
"if",
"len",
"(",
"goids_present",
")",
"!=",
"len",
"(",
"goids",
")",
":",
"print",
"(",
"\"GO IDs NOT FOUND IN DAG: {GOs}\"",
".",
"format",
"(",
"GOs",
"=",
"\" \"",
".",
"join",
"(",
"set",
"(",
"goids",
")",
".",
"difference",
"(",
"goids_present",
")",
")",
")",
")",
"return",
"{",
"g",
":",
"get_nt",
"[",
"g",
"]",
"for",
"g",
"in",
"goids_present",
"}"
] | Return dict of GO ID as key and GO object information in namedtuple. | [
"Return",
"dict",
"of",
"GO",
"ID",
"as",
"key",
"and",
"GO",
"object",
"information",
"in",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag.py#L94-L101 |
228,358 | tanghaibao/goatools | goatools/gosubdag/gosubdag.py | GoSubDag.get_key_goids | def get_key_goids(self, goids):
"""Given GO IDs, return key GO IDs."""
go2obj = self.go2obj
return set(go2obj[go].id for go in goids) | python | def get_key_goids(self, goids):
"""Given GO IDs, return key GO IDs."""
go2obj = self.go2obj
return set(go2obj[go].id for go in goids) | [
"def",
"get_key_goids",
"(",
"self",
",",
"goids",
")",
":",
"go2obj",
"=",
"self",
".",
"go2obj",
"return",
"set",
"(",
"go2obj",
"[",
"go",
"]",
".",
"id",
"for",
"go",
"in",
"goids",
")"
] | Given GO IDs, return key GO IDs. | [
"Given",
"GO",
"IDs",
"return",
"key",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag.py#L115-L118 |
228,359 | tanghaibao/goatools | goatools/gosubdag/gosubdag.py | GoSubDag.prt_objdesc | def prt_objdesc(self, prt):
"""Return description of this GoSubDag object."""
txt = "INITIALIZING GoSubDag: {N:3} sources in {M:3} GOs rcnt({R}). {A} alt GO IDs\n"
alt2obj = {go:o for go, o in self.go2obj.items() if go != o.id}
prt.write(txt.format(
N=len(self.go_sources),
M=len(self.go2obj),
R=self.rcntobj is not None,
A=len(alt2obj)))
prt.write(" GoSubDag: namedtuple fields: {FLDS}\n".format(
FLDS=" ".join(self.prt_attr['flds'])))
prt.write(" GoSubDag: relationships: {RELS}\n".format(RELS=self.relationships)) | python | def prt_objdesc(self, prt):
"""Return description of this GoSubDag object."""
txt = "INITIALIZING GoSubDag: {N:3} sources in {M:3} GOs rcnt({R}). {A} alt GO IDs\n"
alt2obj = {go:o for go, o in self.go2obj.items() if go != o.id}
prt.write(txt.format(
N=len(self.go_sources),
M=len(self.go2obj),
R=self.rcntobj is not None,
A=len(alt2obj)))
prt.write(" GoSubDag: namedtuple fields: {FLDS}\n".format(
FLDS=" ".join(self.prt_attr['flds'])))
prt.write(" GoSubDag: relationships: {RELS}\n".format(RELS=self.relationships)) | [
"def",
"prt_objdesc",
"(",
"self",
",",
"prt",
")",
":",
"txt",
"=",
"\"INITIALIZING GoSubDag: {N:3} sources in {M:3} GOs rcnt({R}). {A} alt GO IDs\\n\"",
"alt2obj",
"=",
"{",
"go",
":",
"o",
"for",
"go",
",",
"o",
"in",
"self",
".",
"go2obj",
".",
"items",
"(",
")",
"if",
"go",
"!=",
"o",
".",
"id",
"}",
"prt",
".",
"write",
"(",
"txt",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"self",
".",
"go_sources",
")",
",",
"M",
"=",
"len",
"(",
"self",
".",
"go2obj",
")",
",",
"R",
"=",
"self",
".",
"rcntobj",
"is",
"not",
"None",
",",
"A",
"=",
"len",
"(",
"alt2obj",
")",
")",
")",
"prt",
".",
"write",
"(",
"\" GoSubDag: namedtuple fields: {FLDS}\\n\"",
".",
"format",
"(",
"FLDS",
"=",
"\" \"",
".",
"join",
"(",
"self",
".",
"prt_attr",
"[",
"'flds'",
"]",
")",
")",
")",
"prt",
".",
"write",
"(",
"\" GoSubDag: relationships: {RELS}\\n\"",
".",
"format",
"(",
"RELS",
"=",
"self",
".",
"relationships",
")",
")"
] | Return description of this GoSubDag object. | [
"Return",
"description",
"of",
"this",
"GoSubDag",
"object",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag.py#L128-L139 |
228,360 | tanghaibao/goatools | goatools/anno/init/reader_genetogo.py | InitAssc._init_taxids | def _init_taxids(taxid, taxids):
"""Return taxid set"""
ret = set()
if taxids is not None:
if taxids is True:
return True
if isinstance(taxids, int):
ret.add(taxids)
else:
ret.update(taxids)
if taxid is not None:
ret.add(taxid)
if not ret:
ret.add(9606)
# pylint: disable=superfluous-parens
print('**NOTE: DEFAULT TAXID STORED FROM gene2go IS 9606 (human)\n')
return ret | python | def _init_taxids(taxid, taxids):
"""Return taxid set"""
ret = set()
if taxids is not None:
if taxids is True:
return True
if isinstance(taxids, int):
ret.add(taxids)
else:
ret.update(taxids)
if taxid is not None:
ret.add(taxid)
if not ret:
ret.add(9606)
# pylint: disable=superfluous-parens
print('**NOTE: DEFAULT TAXID STORED FROM gene2go IS 9606 (human)\n')
return ret | [
"def",
"_init_taxids",
"(",
"taxid",
",",
"taxids",
")",
":",
"ret",
"=",
"set",
"(",
")",
"if",
"taxids",
"is",
"not",
"None",
":",
"if",
"taxids",
"is",
"True",
":",
"return",
"True",
"if",
"isinstance",
"(",
"taxids",
",",
"int",
")",
":",
"ret",
".",
"add",
"(",
"taxids",
")",
"else",
":",
"ret",
".",
"update",
"(",
"taxids",
")",
"if",
"taxid",
"is",
"not",
"None",
":",
"ret",
".",
"add",
"(",
"taxid",
")",
"if",
"not",
"ret",
":",
"ret",
".",
"add",
"(",
"9606",
")",
"# pylint: disable=superfluous-parens",
"print",
"(",
"'**NOTE: DEFAULT TAXID STORED FROM gene2go IS 9606 (human)\\n'",
")",
"return",
"ret"
] | Return taxid set | [
"Return",
"taxid",
"set"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_genetogo.py#L34-L50 |
228,361 | tanghaibao/goatools | goatools/anno/init/reader_genetogo.py | InitAssc.init_associations | def init_associations(self, fin_anno, taxids=None):
"""Read annotation file. Store annotation data in a list of namedtuples."""
nts = []
if fin_anno is None:
return nts
tic = timeit.default_timer()
lnum = -1
line = "\t"*len(self.flds)
try:
with open(fin_anno) as ifstrm:
category2ns = {'Process':'BP', 'Function':'MF', 'Component':'CC'}
ntobj = cx.namedtuple('ntanno', self.flds)
# Get: 1) Specified taxids, default taxid(human), or all taxids
get_all = taxids is True
taxids = self.taxids
for lnum, line in enumerate(ifstrm, 1):
# Read data
if line[0] != '#':
vals = line.split('\t')
taxid = int(vals[0])
if get_all or taxid in taxids:
# assert len(vals) == 8
ntd = ntobj(
tax_id=taxid,
DB_ID=int(vals[1]),
GO_ID=vals[2],
Evidence_Code=vals[3],
Qualifier=self._get_qualifiers(vals[4]),
GO_term=vals[5],
DB_Reference=self._get_pmids(vals[6]),
NS=category2ns[vals[7].rstrip()])
#self._chk_qualifiers(qualifiers, lnum, ntd)
nts.append(ntd)
# Read header
elif line[0] == '#':
assert line[1:-1].split('\t') == self.hdrs
# pylint: disable=broad-except
except Exception as inst:
import traceback
traceback.print_exc()
sys.stderr.write("\n **FATAL: {MSG}\n\n".format(MSG=str(inst)))
sys.stderr.write("**FATAL: {FIN}[{LNUM}]:\n{L}".format(FIN=fin_anno, L=line, LNUM=lnum))
self._prt_line_detail(sys.stdout, line, lnum)
sys.exit(1)
print('HMS:{HMS} {N:7,} annotations READ: {ANNO}'.format(
N=len(nts), ANNO=fin_anno,
HMS=str(datetime.timedelta(seconds=(timeit.default_timer()-tic)))))
return nts | python | def init_associations(self, fin_anno, taxids=None):
"""Read annotation file. Store annotation data in a list of namedtuples."""
nts = []
if fin_anno is None:
return nts
tic = timeit.default_timer()
lnum = -1
line = "\t"*len(self.flds)
try:
with open(fin_anno) as ifstrm:
category2ns = {'Process':'BP', 'Function':'MF', 'Component':'CC'}
ntobj = cx.namedtuple('ntanno', self.flds)
# Get: 1) Specified taxids, default taxid(human), or all taxids
get_all = taxids is True
taxids = self.taxids
for lnum, line in enumerate(ifstrm, 1):
# Read data
if line[0] != '#':
vals = line.split('\t')
taxid = int(vals[0])
if get_all or taxid in taxids:
# assert len(vals) == 8
ntd = ntobj(
tax_id=taxid,
DB_ID=int(vals[1]),
GO_ID=vals[2],
Evidence_Code=vals[3],
Qualifier=self._get_qualifiers(vals[4]),
GO_term=vals[5],
DB_Reference=self._get_pmids(vals[6]),
NS=category2ns[vals[7].rstrip()])
#self._chk_qualifiers(qualifiers, lnum, ntd)
nts.append(ntd)
# Read header
elif line[0] == '#':
assert line[1:-1].split('\t') == self.hdrs
# pylint: disable=broad-except
except Exception as inst:
import traceback
traceback.print_exc()
sys.stderr.write("\n **FATAL: {MSG}\n\n".format(MSG=str(inst)))
sys.stderr.write("**FATAL: {FIN}[{LNUM}]:\n{L}".format(FIN=fin_anno, L=line, LNUM=lnum))
self._prt_line_detail(sys.stdout, line, lnum)
sys.exit(1)
print('HMS:{HMS} {N:7,} annotations READ: {ANNO}'.format(
N=len(nts), ANNO=fin_anno,
HMS=str(datetime.timedelta(seconds=(timeit.default_timer()-tic)))))
return nts | [
"def",
"init_associations",
"(",
"self",
",",
"fin_anno",
",",
"taxids",
"=",
"None",
")",
":",
"nts",
"=",
"[",
"]",
"if",
"fin_anno",
"is",
"None",
":",
"return",
"nts",
"tic",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"lnum",
"=",
"-",
"1",
"line",
"=",
"\"\\t\"",
"*",
"len",
"(",
"self",
".",
"flds",
")",
"try",
":",
"with",
"open",
"(",
"fin_anno",
")",
"as",
"ifstrm",
":",
"category2ns",
"=",
"{",
"'Process'",
":",
"'BP'",
",",
"'Function'",
":",
"'MF'",
",",
"'Component'",
":",
"'CC'",
"}",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"'ntanno'",
",",
"self",
".",
"flds",
")",
"# Get: 1) Specified taxids, default taxid(human), or all taxids",
"get_all",
"=",
"taxids",
"is",
"True",
"taxids",
"=",
"self",
".",
"taxids",
"for",
"lnum",
",",
"line",
"in",
"enumerate",
"(",
"ifstrm",
",",
"1",
")",
":",
"# Read data",
"if",
"line",
"[",
"0",
"]",
"!=",
"'#'",
":",
"vals",
"=",
"line",
".",
"split",
"(",
"'\\t'",
")",
"taxid",
"=",
"int",
"(",
"vals",
"[",
"0",
"]",
")",
"if",
"get_all",
"or",
"taxid",
"in",
"taxids",
":",
"# assert len(vals) == 8",
"ntd",
"=",
"ntobj",
"(",
"tax_id",
"=",
"taxid",
",",
"DB_ID",
"=",
"int",
"(",
"vals",
"[",
"1",
"]",
")",
",",
"GO_ID",
"=",
"vals",
"[",
"2",
"]",
",",
"Evidence_Code",
"=",
"vals",
"[",
"3",
"]",
",",
"Qualifier",
"=",
"self",
".",
"_get_qualifiers",
"(",
"vals",
"[",
"4",
"]",
")",
",",
"GO_term",
"=",
"vals",
"[",
"5",
"]",
",",
"DB_Reference",
"=",
"self",
".",
"_get_pmids",
"(",
"vals",
"[",
"6",
"]",
")",
",",
"NS",
"=",
"category2ns",
"[",
"vals",
"[",
"7",
"]",
".",
"rstrip",
"(",
")",
"]",
")",
"#self._chk_qualifiers(qualifiers, lnum, ntd)",
"nts",
".",
"append",
"(",
"ntd",
")",
"# Read header",
"elif",
"line",
"[",
"0",
"]",
"==",
"'#'",
":",
"assert",
"line",
"[",
"1",
":",
"-",
"1",
"]",
".",
"split",
"(",
"'\\t'",
")",
"==",
"self",
".",
"hdrs",
"# pylint: disable=broad-except",
"except",
"Exception",
"as",
"inst",
":",
"import",
"traceback",
"traceback",
".",
"print_exc",
"(",
")",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"\\n **FATAL: {MSG}\\n\\n\"",
".",
"format",
"(",
"MSG",
"=",
"str",
"(",
"inst",
")",
")",
")",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"**FATAL: {FIN}[{LNUM}]:\\n{L}\"",
".",
"format",
"(",
"FIN",
"=",
"fin_anno",
",",
"L",
"=",
"line",
",",
"LNUM",
"=",
"lnum",
")",
")",
"self",
".",
"_prt_line_detail",
"(",
"sys",
".",
"stdout",
",",
"line",
",",
"lnum",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"print",
"(",
"'HMS:{HMS} {N:7,} annotations READ: {ANNO}'",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"nts",
")",
",",
"ANNO",
"=",
"fin_anno",
",",
"HMS",
"=",
"str",
"(",
"datetime",
".",
"timedelta",
"(",
"seconds",
"=",
"(",
"timeit",
".",
"default_timer",
"(",
")",
"-",
"tic",
")",
")",
")",
")",
")",
"return",
"nts"
] | Read annotation file. Store annotation data in a list of namedtuples. | [
"Read",
"annotation",
"file",
".",
"Store",
"annotation",
"data",
"in",
"a",
"list",
"of",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_genetogo.py#L53-L100 |
228,362 | tanghaibao/goatools | goatools/anno/init/reader_genetogo.py | InitAssc._prt_line_detail | def _prt_line_detail(self, prt, line, lnum=""):
"""Print each field and its value."""
data = zip(self.flds, line.split('\t'))
txt = ["{:2}) {:13} {}".format(i, hdr, val) for i, (hdr, val) in enumerate(data)]
prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT='\n'.join(txt))) | python | def _prt_line_detail(self, prt, line, lnum=""):
"""Print each field and its value."""
data = zip(self.flds, line.split('\t'))
txt = ["{:2}) {:13} {}".format(i, hdr, val) for i, (hdr, val) in enumerate(data)]
prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT='\n'.join(txt))) | [
"def",
"_prt_line_detail",
"(",
"self",
",",
"prt",
",",
"line",
",",
"lnum",
"=",
"\"\"",
")",
":",
"data",
"=",
"zip",
"(",
"self",
".",
"flds",
",",
"line",
".",
"split",
"(",
"'\\t'",
")",
")",
"txt",
"=",
"[",
"\"{:2}) {:13} {}\"",
".",
"format",
"(",
"i",
",",
"hdr",
",",
"val",
")",
"for",
"i",
",",
"(",
"hdr",
",",
"val",
")",
"in",
"enumerate",
"(",
"data",
")",
"]",
"prt",
".",
"write",
"(",
"\"{LNUM}\\n{TXT}\\n\"",
".",
"format",
"(",
"LNUM",
"=",
"lnum",
",",
"TXT",
"=",
"'\\n'",
".",
"join",
"(",
"txt",
")",
")",
")"
] | Print each field and its value. | [
"Print",
"each",
"field",
"and",
"its",
"value",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_genetogo.py#L114-L118 |
228,363 | tanghaibao/goatools | goatools/anno/gaf_reader.py | GafReader.chk_associations | def chk_associations(self, fout_err="gaf.err"):
"""Check that fields are legal in GAF"""
obj = GafData("2.1")
return obj.chk(self.associations, fout_err) | python | def chk_associations(self, fout_err="gaf.err"):
"""Check that fields are legal in GAF"""
obj = GafData("2.1")
return obj.chk(self.associations, fout_err) | [
"def",
"chk_associations",
"(",
"self",
",",
"fout_err",
"=",
"\"gaf.err\"",
")",
":",
"obj",
"=",
"GafData",
"(",
"\"2.1\"",
")",
"return",
"obj",
".",
"chk",
"(",
"self",
".",
"associations",
",",
"fout_err",
")"
] | Check that fields are legal in GAF | [
"Check",
"that",
"fields",
"are",
"legal",
"in",
"GAF"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/gaf_reader.py#L33-L36 |
228,364 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | GetGOs._update_ret | def _update_ret(ret, goids, go2color):
"""Update 'GOs' and 'go2color' in dict with goids and go2color."""
if goids:
ret['GOs'].update(goids)
if go2color:
for goid, color in go2color.items():
ret['go2color'][goid] = color | python | def _update_ret(ret, goids, go2color):
"""Update 'GOs' and 'go2color' in dict with goids and go2color."""
if goids:
ret['GOs'].update(goids)
if go2color:
for goid, color in go2color.items():
ret['go2color'][goid] = color | [
"def",
"_update_ret",
"(",
"ret",
",",
"goids",
",",
"go2color",
")",
":",
"if",
"goids",
":",
"ret",
"[",
"'GOs'",
"]",
".",
"update",
"(",
"goids",
")",
"if",
"go2color",
":",
"for",
"goid",
",",
"color",
"in",
"go2color",
".",
"items",
"(",
")",
":",
"ret",
"[",
"'go2color'",
"]",
"[",
"goid",
"]",
"=",
"color"
] | Update 'GOs' and 'go2color' in dict with goids and go2color. | [
"Update",
"GOs",
"and",
"go2color",
"in",
"dict",
"with",
"goids",
"and",
"go2color",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L160-L166 |
228,365 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._plt_gogrouped | def _plt_gogrouped(self, goids, go2color_usr, **kws):
"""Plot grouped GO IDs."""
fout_img = self.get_outfile(kws['outfile'], goids)
sections = read_sections(kws['sections'], exclude_ungrouped=True)
# print ("KWWSSSSSSSS", kws)
# kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}
grprobj_cur = self._get_grprobj(goids, sections)
# GO: purple=hdr-only, green=hdr&usr, yellow=usr-only
# BORDER: Black=hdr Blu=hdr&usr
grpcolor = GrouperColors(grprobj_cur) # get_bordercolor get_go2color_users
grp_go2color = grpcolor.get_go2color_users()
grp_go2bordercolor = grpcolor.get_bordercolor()
for goid, color in go2color_usr.items():
grp_go2color[goid] = color
objcolor = Go2Color(self.gosubdag, objgoea=None,
go2color=grp_go2color, go2bordercolor=grp_go2bordercolor)
go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor)
objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, go2txt=go2txt, **kws)
objplt.prt_goids(sys.stdout)
objplt.plt_dag(fout_img)
sys.stdout.write("{N:>6} sections read\n".format(
N="NO" if sections is None else len(sections)))
return fout_img | python | def _plt_gogrouped(self, goids, go2color_usr, **kws):
"""Plot grouped GO IDs."""
fout_img = self.get_outfile(kws['outfile'], goids)
sections = read_sections(kws['sections'], exclude_ungrouped=True)
# print ("KWWSSSSSSSS", kws)
# kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}
grprobj_cur = self._get_grprobj(goids, sections)
# GO: purple=hdr-only, green=hdr&usr, yellow=usr-only
# BORDER: Black=hdr Blu=hdr&usr
grpcolor = GrouperColors(grprobj_cur) # get_bordercolor get_go2color_users
grp_go2color = grpcolor.get_go2color_users()
grp_go2bordercolor = grpcolor.get_bordercolor()
for goid, color in go2color_usr.items():
grp_go2color[goid] = color
objcolor = Go2Color(self.gosubdag, objgoea=None,
go2color=grp_go2color, go2bordercolor=grp_go2bordercolor)
go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor)
objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, go2txt=go2txt, **kws)
objplt.prt_goids(sys.stdout)
objplt.plt_dag(fout_img)
sys.stdout.write("{N:>6} sections read\n".format(
N="NO" if sections is None else len(sections)))
return fout_img | [
"def",
"_plt_gogrouped",
"(",
"self",
",",
"goids",
",",
"go2color_usr",
",",
"*",
"*",
"kws",
")",
":",
"fout_img",
"=",
"self",
".",
"get_outfile",
"(",
"kws",
"[",
"'outfile'",
"]",
",",
"goids",
")",
"sections",
"=",
"read_sections",
"(",
"kws",
"[",
"'sections'",
"]",
",",
"exclude_ungrouped",
"=",
"True",
")",
"# print (\"KWWSSSSSSSS\", kws)",
"# kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}",
"grprobj_cur",
"=",
"self",
".",
"_get_grprobj",
"(",
"goids",
",",
"sections",
")",
"# GO: purple=hdr-only, green=hdr&usr, yellow=usr-only",
"# BORDER: Black=hdr Blu=hdr&usr",
"grpcolor",
"=",
"GrouperColors",
"(",
"grprobj_cur",
")",
"# get_bordercolor get_go2color_users",
"grp_go2color",
"=",
"grpcolor",
".",
"get_go2color_users",
"(",
")",
"grp_go2bordercolor",
"=",
"grpcolor",
".",
"get_bordercolor",
"(",
")",
"for",
"goid",
",",
"color",
"in",
"go2color_usr",
".",
"items",
"(",
")",
":",
"grp_go2color",
"[",
"goid",
"]",
"=",
"color",
"objcolor",
"=",
"Go2Color",
"(",
"self",
".",
"gosubdag",
",",
"objgoea",
"=",
"None",
",",
"go2color",
"=",
"grp_go2color",
",",
"go2bordercolor",
"=",
"grp_go2bordercolor",
")",
"go2txt",
"=",
"GrouperPlot",
".",
"get_go2txt",
"(",
"grprobj_cur",
",",
"grp_go2color",
",",
"grp_go2bordercolor",
")",
"objplt",
"=",
"GoSubDagPlot",
"(",
"self",
".",
"gosubdag",
",",
"Go2Color",
"=",
"objcolor",
",",
"go2txt",
"=",
"go2txt",
",",
"*",
"*",
"kws",
")",
"objplt",
".",
"prt_goids",
"(",
"sys",
".",
"stdout",
")",
"objplt",
".",
"plt_dag",
"(",
"fout_img",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"\"{N:>6} sections read\\n\"",
".",
"format",
"(",
"N",
"=",
"\"NO\"",
"if",
"sections",
"is",
"None",
"else",
"len",
"(",
"sections",
")",
")",
")",
"return",
"fout_img"
] | Plot grouped GO IDs. | [
"Plot",
"grouped",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L205-L227 |
228,366 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._get_grprobj | def _get_grprobj(self, goids, sections):
"""Get Grouper, given GO IDs and sections."""
grprdflt = GrouperDflts(self.gosubdag, "goslim_generic.obo")
hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
return Grouper("sections", goids, hdrobj, self.gosubdag) | python | def _get_grprobj(self, goids, sections):
"""Get Grouper, given GO IDs and sections."""
grprdflt = GrouperDflts(self.gosubdag, "goslim_generic.obo")
hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
return Grouper("sections", goids, hdrobj, self.gosubdag) | [
"def",
"_get_grprobj",
"(",
"self",
",",
"goids",
",",
"sections",
")",
":",
"grprdflt",
"=",
"GrouperDflts",
"(",
"self",
".",
"gosubdag",
",",
"\"goslim_generic.obo\"",
")",
"hdrobj",
"=",
"HdrgosSections",
"(",
"self",
".",
"gosubdag",
",",
"grprdflt",
".",
"hdrgos_dflt",
",",
"sections",
")",
"return",
"Grouper",
"(",
"\"sections\"",
",",
"goids",
",",
"hdrobj",
",",
"self",
".",
"gosubdag",
")"
] | Get Grouper, given GO IDs and sections. | [
"Get",
"Grouper",
"given",
"GO",
"IDs",
"and",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L229-L233 |
228,367 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._get_kwsdag | def _get_kwsdag(self, goids, go2obj, **kws_all):
"""Get keyword args for a GoSubDag."""
kws_dag = {}
# Term Counts for GO Term information score
tcntobj = self._get_tcntobj(goids, go2obj, **kws_all) # TermCounts or None
if tcntobj is not None:
kws_dag['tcntobj'] = tcntobj
# GO letters specified by the user
if 'go_aliases' in kws_all:
fin_go_aliases = kws_all['go_aliases']
if os.path.exists(fin_go_aliases):
go2letter = read_d1_letter(fin_go_aliases)
if go2letter:
kws_dag['go2letter'] = go2letter
return kws_dag | python | def _get_kwsdag(self, goids, go2obj, **kws_all):
"""Get keyword args for a GoSubDag."""
kws_dag = {}
# Term Counts for GO Term information score
tcntobj = self._get_tcntobj(goids, go2obj, **kws_all) # TermCounts or None
if tcntobj is not None:
kws_dag['tcntobj'] = tcntobj
# GO letters specified by the user
if 'go_aliases' in kws_all:
fin_go_aliases = kws_all['go_aliases']
if os.path.exists(fin_go_aliases):
go2letter = read_d1_letter(fin_go_aliases)
if go2letter:
kws_dag['go2letter'] = go2letter
return kws_dag | [
"def",
"_get_kwsdag",
"(",
"self",
",",
"goids",
",",
"go2obj",
",",
"*",
"*",
"kws_all",
")",
":",
"kws_dag",
"=",
"{",
"}",
"# Term Counts for GO Term information score",
"tcntobj",
"=",
"self",
".",
"_get_tcntobj",
"(",
"goids",
",",
"go2obj",
",",
"*",
"*",
"kws_all",
")",
"# TermCounts or None",
"if",
"tcntobj",
"is",
"not",
"None",
":",
"kws_dag",
"[",
"'tcntobj'",
"]",
"=",
"tcntobj",
"# GO letters specified by the user",
"if",
"'go_aliases'",
"in",
"kws_all",
":",
"fin_go_aliases",
"=",
"kws_all",
"[",
"'go_aliases'",
"]",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"fin_go_aliases",
")",
":",
"go2letter",
"=",
"read_d1_letter",
"(",
"fin_go_aliases",
")",
"if",
"go2letter",
":",
"kws_dag",
"[",
"'go2letter'",
"]",
"=",
"go2letter",
"return",
"kws_dag"
] | Get keyword args for a GoSubDag. | [
"Get",
"keyword",
"args",
"for",
"a",
"GoSubDag",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L244-L258 |
228,368 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._chk_docopts | def _chk_docopts(self, kws):
"""Check for common user command-line errors."""
# outfile should contain .png, .png, etc.
outfile = kws['outfile']
if len(kws) == 2 and os.path.basename(kws['obo']) == "go-basic.obo" and \
kws['outfile'] == self.dflt_outfile:
self._err("NO GO IDS SPECFIED", err=False)
if 'obo' in outfile:
self._err("BAD outfile({O})".format(O=outfile))
if 'gaf' in kws and 'gene2go' in kws:
self._err("SPECIFY ANNOTAIONS FROM ONE FILE")
if 'gene2go' in kws:
if 'taxid' not in kws:
self._err("SPECIFIY taxid WHEN READ NCBI'S gene2go FILE") | python | def _chk_docopts(self, kws):
"""Check for common user command-line errors."""
# outfile should contain .png, .png, etc.
outfile = kws['outfile']
if len(kws) == 2 and os.path.basename(kws['obo']) == "go-basic.obo" and \
kws['outfile'] == self.dflt_outfile:
self._err("NO GO IDS SPECFIED", err=False)
if 'obo' in outfile:
self._err("BAD outfile({O})".format(O=outfile))
if 'gaf' in kws and 'gene2go' in kws:
self._err("SPECIFY ANNOTAIONS FROM ONE FILE")
if 'gene2go' in kws:
if 'taxid' not in kws:
self._err("SPECIFIY taxid WHEN READ NCBI'S gene2go FILE") | [
"def",
"_chk_docopts",
"(",
"self",
",",
"kws",
")",
":",
"# outfile should contain .png, .png, etc.",
"outfile",
"=",
"kws",
"[",
"'outfile'",
"]",
"if",
"len",
"(",
"kws",
")",
"==",
"2",
"and",
"os",
".",
"path",
".",
"basename",
"(",
"kws",
"[",
"'obo'",
"]",
")",
"==",
"\"go-basic.obo\"",
"and",
"kws",
"[",
"'outfile'",
"]",
"==",
"self",
".",
"dflt_outfile",
":",
"self",
".",
"_err",
"(",
"\"NO GO IDS SPECFIED\"",
",",
"err",
"=",
"False",
")",
"if",
"'obo'",
"in",
"outfile",
":",
"self",
".",
"_err",
"(",
"\"BAD outfile({O})\"",
".",
"format",
"(",
"O",
"=",
"outfile",
")",
")",
"if",
"'gaf'",
"in",
"kws",
"and",
"'gene2go'",
"in",
"kws",
":",
"self",
".",
"_err",
"(",
"\"SPECIFY ANNOTAIONS FROM ONE FILE\"",
")",
"if",
"'gene2go'",
"in",
"kws",
":",
"if",
"'taxid'",
"not",
"in",
"kws",
":",
"self",
".",
"_err",
"(",
"\"SPECIFIY taxid WHEN READ NCBI'S gene2go FILE\"",
")"
] | Check for common user command-line errors. | [
"Check",
"for",
"common",
"user",
"command",
"-",
"line",
"errors",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L277-L290 |
228,369 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._err | def _err(self, msg, err=True):
"""Print useage and error before exiting."""
severity = "FATAL" if err else "NOTE"
txt = "".join([self.objdoc.doc,
"User's command-line:\n\n",
" % go_plot.py {ARGS}\n\n".format(ARGS=" ".join(sys.argv[1:])),
"**{SEV}: {MSG}\n".format(SEV=severity, MSG=msg)])
if err:
raise RuntimeError(txt)
sys.stdout.write(txt)
sys.exit(0) | python | def _err(self, msg, err=True):
"""Print useage and error before exiting."""
severity = "FATAL" if err else "NOTE"
txt = "".join([self.objdoc.doc,
"User's command-line:\n\n",
" % go_plot.py {ARGS}\n\n".format(ARGS=" ".join(sys.argv[1:])),
"**{SEV}: {MSG}\n".format(SEV=severity, MSG=msg)])
if err:
raise RuntimeError(txt)
sys.stdout.write(txt)
sys.exit(0) | [
"def",
"_err",
"(",
"self",
",",
"msg",
",",
"err",
"=",
"True",
")",
":",
"severity",
"=",
"\"FATAL\"",
"if",
"err",
"else",
"\"NOTE\"",
"txt",
"=",
"\"\"",
".",
"join",
"(",
"[",
"self",
".",
"objdoc",
".",
"doc",
",",
"\"User's command-line:\\n\\n\"",
",",
"\" % go_plot.py {ARGS}\\n\\n\"",
".",
"format",
"(",
"ARGS",
"=",
"\" \"",
".",
"join",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
")",
",",
"\"**{SEV}: {MSG}\\n\"",
".",
"format",
"(",
"SEV",
"=",
"severity",
",",
"MSG",
"=",
"msg",
")",
"]",
")",
"if",
"err",
":",
"raise",
"RuntimeError",
"(",
"txt",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"txt",
")",
"sys",
".",
"exit",
"(",
"0",
")"
] | Print useage and error before exiting. | [
"Print",
"useage",
"and",
"error",
"before",
"exiting",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L292-L302 |
228,370 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli.get_outfile | def get_outfile(self, outfile, goids=None):
"""Return output file for GO Term plot."""
# 1. Use the user-specfied output filename for the GO Term plot
if outfile != self.dflt_outfile:
return outfile
# 2. If only plotting 1 GO term, use GO is in plot name
if goids is not None and len(goids) == 1:
goid = next(iter(goids))
goobj = self.gosubdag.go2obj[goid]
fout = "GO_{NN}_{NM}".format(NN=goid.replace("GO:", ""), NM=goobj.name)
return ".".join([re.sub(r"[\s#'()+,-./:<=>\[\]_}]", '_', fout), 'png'])
# 3. Return default name
return self.dflt_outfile | python | def get_outfile(self, outfile, goids=None):
"""Return output file for GO Term plot."""
# 1. Use the user-specfied output filename for the GO Term plot
if outfile != self.dflt_outfile:
return outfile
# 2. If only plotting 1 GO term, use GO is in plot name
if goids is not None and len(goids) == 1:
goid = next(iter(goids))
goobj = self.gosubdag.go2obj[goid]
fout = "GO_{NN}_{NM}".format(NN=goid.replace("GO:", ""), NM=goobj.name)
return ".".join([re.sub(r"[\s#'()+,-./:<=>\[\]_}]", '_', fout), 'png'])
# 3. Return default name
return self.dflt_outfile | [
"def",
"get_outfile",
"(",
"self",
",",
"outfile",
",",
"goids",
"=",
"None",
")",
":",
"# 1. Use the user-specfied output filename for the GO Term plot",
"if",
"outfile",
"!=",
"self",
".",
"dflt_outfile",
":",
"return",
"outfile",
"# 2. If only plotting 1 GO term, use GO is in plot name",
"if",
"goids",
"is",
"not",
"None",
"and",
"len",
"(",
"goids",
")",
"==",
"1",
":",
"goid",
"=",
"next",
"(",
"iter",
"(",
"goids",
")",
")",
"goobj",
"=",
"self",
".",
"gosubdag",
".",
"go2obj",
"[",
"goid",
"]",
"fout",
"=",
"\"GO_{NN}_{NM}\"",
".",
"format",
"(",
"NN",
"=",
"goid",
".",
"replace",
"(",
"\"GO:\"",
",",
"\"\"",
")",
",",
"NM",
"=",
"goobj",
".",
"name",
")",
"return",
"\".\"",
".",
"join",
"(",
"[",
"re",
".",
"sub",
"(",
"r\"[\\s#'()+,-./:<=>\\[\\]_}]\"",
",",
"'_'",
",",
"fout",
")",
",",
"'png'",
"]",
")",
"# 3. Return default name",
"return",
"self",
".",
"dflt_outfile"
] | Return output file for GO Term plot. | [
"Return",
"output",
"file",
"for",
"GO",
"Term",
"plot",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L304-L316 |
228,371 | tanghaibao/goatools | goatools/cli/gosubdag_plot.py | PlotCli._get_optional_attrs | def _get_optional_attrs(kws):
"""Given keyword args, return optional_attributes to be loaded into the GODag."""
vals = OboOptionalAttrs.attributes.intersection(kws.keys())
if 'sections' in kws:
vals.add('relationship')
if 'norel' in kws:
vals.discard('relationship')
return vals | python | def _get_optional_attrs(kws):
"""Given keyword args, return optional_attributes to be loaded into the GODag."""
vals = OboOptionalAttrs.attributes.intersection(kws.keys())
if 'sections' in kws:
vals.add('relationship')
if 'norel' in kws:
vals.discard('relationship')
return vals | [
"def",
"_get_optional_attrs",
"(",
"kws",
")",
":",
"vals",
"=",
"OboOptionalAttrs",
".",
"attributes",
".",
"intersection",
"(",
"kws",
".",
"keys",
"(",
")",
")",
"if",
"'sections'",
"in",
"kws",
":",
"vals",
".",
"add",
"(",
"'relationship'",
")",
"if",
"'norel'",
"in",
"kws",
":",
"vals",
".",
"discard",
"(",
"'relationship'",
")",
"return",
"vals"
] | Given keyword args, return optional_attributes to be loaded into the GODag. | [
"Given",
"keyword",
"args",
"return",
"optional_attributes",
"to",
"be",
"loaded",
"into",
"the",
"GODag",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gosubdag_plot.py#L319-L326 |
228,372 | tanghaibao/goatools | goatools/cli/wr_sections.py | WrSectionsCli._read_sections | def _read_sections(ifile):
"""Read sections_in.txt file, if it exists."""
if os.path.exists(ifile):
return read_sections(ifile, exclude_ungrouped=True, prt=None) | python | def _read_sections(ifile):
"""Read sections_in.txt file, if it exists."""
if os.path.exists(ifile):
return read_sections(ifile, exclude_ungrouped=True, prt=None) | [
"def",
"_read_sections",
"(",
"ifile",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"ifile",
")",
":",
"return",
"read_sections",
"(",
"ifile",
",",
"exclude_ungrouped",
"=",
"True",
",",
"prt",
"=",
"None",
")"
] | Read sections_in.txt file, if it exists. | [
"Read",
"sections_in",
".",
"txt",
"file",
"if",
"it",
"exists",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_sections.py#L96-L99 |
228,373 | tanghaibao/goatools | goatools/gosubdag/go_paths.py | GoPaths.get_paths_from_to | def get_paths_from_to(self, goobj_start, goid_end=None, dn0_up1=True):
"""Get a list of paths from goobj_start to either top or goid_end."""
paths = []
# Queue of terms to be examined (and storage for their paths)
working_q = cx.deque([[goobj_start]])
# Loop thru GO terms until we have examined all needed GO terms
adjfnc = self.adjdir[dn0_up1]
while working_q:
#print "WORKING QUEUE LEN({})".format(len(working_q))
path_curr = working_q.popleft()
goobj_curr = path_curr[-1]
go_adjlst = adjfnc(goobj_curr)
#print 'END', goid_end, goobj_curr
# If this GO term is the endpoint, Stop. Store path.
if (goid_end is not None and goobj_curr.id == goid_end) or \
(goid_end is None and not go_adjlst):
paths.append(path_curr)
# Else if this GO term is the not the end, add neighbors to path
else:
for go_neighbor in go_adjlst:
if go_neighbor not in path_curr:
#print "{}'s NEIGHBOR IS {}".format(goobj_curr.id, go_neighbor.id)
new_path = path_curr + [go_neighbor]
#sys.stdout.write(" {}'s {} {}\n".format(goobj_curr, up_dn, go_neighbor))
working_q.append(new_path)
#self.prt_paths(paths)
return paths | python | def get_paths_from_to(self, goobj_start, goid_end=None, dn0_up1=True):
"""Get a list of paths from goobj_start to either top or goid_end."""
paths = []
# Queue of terms to be examined (and storage for their paths)
working_q = cx.deque([[goobj_start]])
# Loop thru GO terms until we have examined all needed GO terms
adjfnc = self.adjdir[dn0_up1]
while working_q:
#print "WORKING QUEUE LEN({})".format(len(working_q))
path_curr = working_q.popleft()
goobj_curr = path_curr[-1]
go_adjlst = adjfnc(goobj_curr)
#print 'END', goid_end, goobj_curr
# If this GO term is the endpoint, Stop. Store path.
if (goid_end is not None and goobj_curr.id == goid_end) or \
(goid_end is None and not go_adjlst):
paths.append(path_curr)
# Else if this GO term is the not the end, add neighbors to path
else:
for go_neighbor in go_adjlst:
if go_neighbor not in path_curr:
#print "{}'s NEIGHBOR IS {}".format(goobj_curr.id, go_neighbor.id)
new_path = path_curr + [go_neighbor]
#sys.stdout.write(" {}'s {} {}\n".format(goobj_curr, up_dn, go_neighbor))
working_q.append(new_path)
#self.prt_paths(paths)
return paths | [
"def",
"get_paths_from_to",
"(",
"self",
",",
"goobj_start",
",",
"goid_end",
"=",
"None",
",",
"dn0_up1",
"=",
"True",
")",
":",
"paths",
"=",
"[",
"]",
"# Queue of terms to be examined (and storage for their paths)",
"working_q",
"=",
"cx",
".",
"deque",
"(",
"[",
"[",
"goobj_start",
"]",
"]",
")",
"# Loop thru GO terms until we have examined all needed GO terms",
"adjfnc",
"=",
"self",
".",
"adjdir",
"[",
"dn0_up1",
"]",
"while",
"working_q",
":",
"#print \"WORKING QUEUE LEN({})\".format(len(working_q))",
"path_curr",
"=",
"working_q",
".",
"popleft",
"(",
")",
"goobj_curr",
"=",
"path_curr",
"[",
"-",
"1",
"]",
"go_adjlst",
"=",
"adjfnc",
"(",
"goobj_curr",
")",
"#print 'END', goid_end, goobj_curr",
"# If this GO term is the endpoint, Stop. Store path.",
"if",
"(",
"goid_end",
"is",
"not",
"None",
"and",
"goobj_curr",
".",
"id",
"==",
"goid_end",
")",
"or",
"(",
"goid_end",
"is",
"None",
"and",
"not",
"go_adjlst",
")",
":",
"paths",
".",
"append",
"(",
"path_curr",
")",
"# Else if this GO term is the not the end, add neighbors to path",
"else",
":",
"for",
"go_neighbor",
"in",
"go_adjlst",
":",
"if",
"go_neighbor",
"not",
"in",
"path_curr",
":",
"#print \"{}'s NEIGHBOR IS {}\".format(goobj_curr.id, go_neighbor.id)",
"new_path",
"=",
"path_curr",
"+",
"[",
"go_neighbor",
"]",
"#sys.stdout.write(\" {}'s {} {}\\n\".format(goobj_curr, up_dn, go_neighbor))",
"working_q",
".",
"append",
"(",
"new_path",
")",
"#self.prt_paths(paths)",
"return",
"paths"
] | Get a list of paths from goobj_start to either top or goid_end. | [
"Get",
"a",
"list",
"of",
"paths",
"from",
"goobj_start",
"to",
"either",
"top",
"or",
"goid_end",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_paths.py#L19-L45 |
228,374 | tanghaibao/goatools | goatools/gosubdag/go_paths.py | GoPaths.prt_paths | def prt_paths(paths, prt=sys.stdout):
"""Print list of paths."""
pat = "PATHES: {GO} L{L:02} D{D:02}\n"
for path in paths:
for go_obj in path:
prt.write(pat.format(GO=go_obj.id, L=go_obj.level, D=go_obj.depth))
prt.write("\n") | python | def prt_paths(paths, prt=sys.stdout):
"""Print list of paths."""
pat = "PATHES: {GO} L{L:02} D{D:02}\n"
for path in paths:
for go_obj in path:
prt.write(pat.format(GO=go_obj.id, L=go_obj.level, D=go_obj.depth))
prt.write("\n") | [
"def",
"prt_paths",
"(",
"paths",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"pat",
"=",
"\"PATHES: {GO} L{L:02} D{D:02}\\n\"",
"for",
"path",
"in",
"paths",
":",
"for",
"go_obj",
"in",
"path",
":",
"prt",
".",
"write",
"(",
"pat",
".",
"format",
"(",
"GO",
"=",
"go_obj",
".",
"id",
",",
"L",
"=",
"go_obj",
".",
"level",
",",
"D",
"=",
"go_obj",
".",
"depth",
")",
")",
"prt",
".",
"write",
"(",
"\"\\n\"",
")"
] | Print list of paths. | [
"Print",
"list",
"of",
"paths",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_paths.py#L48-L54 |
228,375 | tanghaibao/goatools | goatools/godag/relationship_str.py | RelationshipStr.prt_keys | def prt_keys(self, prt, pre):
"""Print the alias for a relationship and its alias."""
prt.write('{PRE}Relationship to parent: {ABC}\n'.format(
PRE=pre, ABC=''.join(self.rel2chr.values())))
for rel, alias in self.rel2chr.items():
prt.write('{PRE} {A} {DESC}\n'.format(PRE=pre, A=alias, DESC=rel))
prt.write('\n{PRE}Relationship to child: {ABC}\n'.format(
PRE=pre, ABC=''.join(self.rev2chr.values())))
for rel, alias in self.rev2chr.items():
prt.write('{PRE} {A} {DESC}\n'.format(PRE=pre, A=alias, DESC=rel)) | python | def prt_keys(self, prt, pre):
"""Print the alias for a relationship and its alias."""
prt.write('{PRE}Relationship to parent: {ABC}\n'.format(
PRE=pre, ABC=''.join(self.rel2chr.values())))
for rel, alias in self.rel2chr.items():
prt.write('{PRE} {A} {DESC}\n'.format(PRE=pre, A=alias, DESC=rel))
prt.write('\n{PRE}Relationship to child: {ABC}\n'.format(
PRE=pre, ABC=''.join(self.rev2chr.values())))
for rel, alias in self.rev2chr.items():
prt.write('{PRE} {A} {DESC}\n'.format(PRE=pre, A=alias, DESC=rel)) | [
"def",
"prt_keys",
"(",
"self",
",",
"prt",
",",
"pre",
")",
":",
"prt",
".",
"write",
"(",
"'{PRE}Relationship to parent: {ABC}\\n'",
".",
"format",
"(",
"PRE",
"=",
"pre",
",",
"ABC",
"=",
"''",
".",
"join",
"(",
"self",
".",
"rel2chr",
".",
"values",
"(",
")",
")",
")",
")",
"for",
"rel",
",",
"alias",
"in",
"self",
".",
"rel2chr",
".",
"items",
"(",
")",
":",
"prt",
".",
"write",
"(",
"'{PRE} {A} {DESC}\\n'",
".",
"format",
"(",
"PRE",
"=",
"pre",
",",
"A",
"=",
"alias",
",",
"DESC",
"=",
"rel",
")",
")",
"prt",
".",
"write",
"(",
"'\\n{PRE}Relationship to child: {ABC}\\n'",
".",
"format",
"(",
"PRE",
"=",
"pre",
",",
"ABC",
"=",
"''",
".",
"join",
"(",
"self",
".",
"rev2chr",
".",
"values",
"(",
")",
")",
")",
")",
"for",
"rel",
",",
"alias",
"in",
"self",
".",
"rev2chr",
".",
"items",
"(",
")",
":",
"prt",
".",
"write",
"(",
"'{PRE} {A} {DESC}\\n'",
".",
"format",
"(",
"PRE",
"=",
"pre",
",",
"A",
"=",
"alias",
",",
"DESC",
"=",
"rel",
")",
")"
] | Print the alias for a relationship and its alias. | [
"Print",
"the",
"alias",
"for",
"a",
"relationship",
"and",
"its",
"alias",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/relationship_str.py#L79-L88 |
228,376 | tanghaibao/goatools | goatools/anno/annoreader_base.py | AnnoReaderBase._get_id2gos | def _get_id2gos(self, associations, **kws):
"""Return given associations in a dict, id2gos"""
options = AnnoOptions(self.evobj, **kws)
# Default reduction is to remove. For all options, see goatools/anno/opts.py:
# * Evidence_Code == ND -> No biological data No biological Data available
# * Qualifiers contain NOT
assc = self.reduce_annotations(associations, options)
return self._get_dbid2goids(assc) if options.b_geneid2gos else self._get_goid2dbids(assc) | python | def _get_id2gos(self, associations, **kws):
"""Return given associations in a dict, id2gos"""
options = AnnoOptions(self.evobj, **kws)
# Default reduction is to remove. For all options, see goatools/anno/opts.py:
# * Evidence_Code == ND -> No biological data No biological Data available
# * Qualifiers contain NOT
assc = self.reduce_annotations(associations, options)
return self._get_dbid2goids(assc) if options.b_geneid2gos else self._get_goid2dbids(assc) | [
"def",
"_get_id2gos",
"(",
"self",
",",
"associations",
",",
"*",
"*",
"kws",
")",
":",
"options",
"=",
"AnnoOptions",
"(",
"self",
".",
"evobj",
",",
"*",
"*",
"kws",
")",
"# Default reduction is to remove. For all options, see goatools/anno/opts.py:",
"# * Evidence_Code == ND -> No biological data No biological Data available",
"# * Qualifiers contain NOT",
"assc",
"=",
"self",
".",
"reduce_annotations",
"(",
"associations",
",",
"options",
")",
"return",
"self",
".",
"_get_dbid2goids",
"(",
"assc",
")",
"if",
"options",
".",
"b_geneid2gos",
"else",
"self",
".",
"_get_goid2dbids",
"(",
"assc",
")"
] | Return given associations in a dict, id2gos | [
"Return",
"given",
"associations",
"in",
"a",
"dict",
"id2gos"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L83-L90 |
228,377 | tanghaibao/goatools | goatools/anno/annoreader_base.py | AnnoReaderBase.get_date_yyyymmdd | def get_date_yyyymmdd(yyyymmdd):
"""Return datetime.date given string."""
return date(int(yyyymmdd[:4]), int(yyyymmdd[4:6], base=10), int(yyyymmdd[6:], base=10)) | python | def get_date_yyyymmdd(yyyymmdd):
"""Return datetime.date given string."""
return date(int(yyyymmdd[:4]), int(yyyymmdd[4:6], base=10), int(yyyymmdd[6:], base=10)) | [
"def",
"get_date_yyyymmdd",
"(",
"yyyymmdd",
")",
":",
"return",
"date",
"(",
"int",
"(",
"yyyymmdd",
"[",
":",
"4",
"]",
")",
",",
"int",
"(",
"yyyymmdd",
"[",
"4",
":",
"6",
"]",
",",
"base",
"=",
"10",
")",
",",
"int",
"(",
"yyyymmdd",
"[",
"6",
":",
"]",
",",
"base",
"=",
"10",
")",
")"
] | Return datetime.date given string. | [
"Return",
"datetime",
".",
"date",
"given",
"string",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L139-L141 |
228,378 | tanghaibao/goatools | goatools/anno/annoreader_base.py | AnnoReaderBase.hms | def hms(self, msg, tic=None, prt=sys.stdout):
"""Print elapsed time and message."""
if tic is None:
tic = self.tic
now = timeit.default_timer()
hms = str(datetime.timedelta(seconds=(now-tic)))
prt.write('{HMS}: {MSG}\n'.format(HMS=hms, MSG=msg))
return now | python | def hms(self, msg, tic=None, prt=sys.stdout):
"""Print elapsed time and message."""
if tic is None:
tic = self.tic
now = timeit.default_timer()
hms = str(datetime.timedelta(seconds=(now-tic)))
prt.write('{HMS}: {MSG}\n'.format(HMS=hms, MSG=msg))
return now | [
"def",
"hms",
"(",
"self",
",",
"msg",
",",
"tic",
"=",
"None",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"if",
"tic",
"is",
"None",
":",
"tic",
"=",
"self",
".",
"tic",
"now",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"hms",
"=",
"str",
"(",
"datetime",
".",
"timedelta",
"(",
"seconds",
"=",
"(",
"now",
"-",
"tic",
")",
")",
")",
"prt",
".",
"write",
"(",
"'{HMS}: {MSG}\\n'",
".",
"format",
"(",
"HMS",
"=",
"hms",
",",
"MSG",
"=",
"msg",
")",
")",
"return",
"now"
] | Print elapsed time and message. | [
"Print",
"elapsed",
"time",
"and",
"message",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L143-L150 |
228,379 | tanghaibao/goatools | goatools/anno/annoreader_base.py | AnnoReaderBase.chk_qualifiers | def chk_qualifiers(self):
"""Check format of qualifier"""
if self.name == 'id2gos':
return
for ntd in self.associations:
# print(ntd)
qual = ntd.Qualifier
assert isinstance(qual, set), '{NAME}: QUALIFIER MUST BE A LIST: {NT}'.format(
NAME=self.name, NT=ntd)
assert qual != set(['']), ntd
assert qual != set(['-']), ntd
assert 'always' not in qual, 'SPEC SAID IT WOULD BE THERE' | python | def chk_qualifiers(self):
"""Check format of qualifier"""
if self.name == 'id2gos':
return
for ntd in self.associations:
# print(ntd)
qual = ntd.Qualifier
assert isinstance(qual, set), '{NAME}: QUALIFIER MUST BE A LIST: {NT}'.format(
NAME=self.name, NT=ntd)
assert qual != set(['']), ntd
assert qual != set(['-']), ntd
assert 'always' not in qual, 'SPEC SAID IT WOULD BE THERE' | [
"def",
"chk_qualifiers",
"(",
"self",
")",
":",
"if",
"self",
".",
"name",
"==",
"'id2gos'",
":",
"return",
"for",
"ntd",
"in",
"self",
".",
"associations",
":",
"# print(ntd)",
"qual",
"=",
"ntd",
".",
"Qualifier",
"assert",
"isinstance",
"(",
"qual",
",",
"set",
")",
",",
"'{NAME}: QUALIFIER MUST BE A LIST: {NT}'",
".",
"format",
"(",
"NAME",
"=",
"self",
".",
"name",
",",
"NT",
"=",
"ntd",
")",
"assert",
"qual",
"!=",
"set",
"(",
"[",
"''",
"]",
")",
",",
"ntd",
"assert",
"qual",
"!=",
"set",
"(",
"[",
"'-'",
"]",
")",
",",
"ntd",
"assert",
"'always'",
"not",
"in",
"qual",
",",
"'SPEC SAID IT WOULD BE THERE'"
] | Check format of qualifier | [
"Check",
"format",
"of",
"qualifier"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L164-L175 |
228,380 | tanghaibao/goatools | goatools/anno/annoreader_base.py | AnnoReaderBase._has_not_qual | def _has_not_qual(ntd):
"""Return True if the qualifiers contain a 'NOT'"""
for qual in ntd.Qualifier:
if 'not' in qual:
return True
if 'NOT' in qual:
return True
return False | python | def _has_not_qual(ntd):
"""Return True if the qualifiers contain a 'NOT'"""
for qual in ntd.Qualifier:
if 'not' in qual:
return True
if 'NOT' in qual:
return True
return False | [
"def",
"_has_not_qual",
"(",
"ntd",
")",
":",
"for",
"qual",
"in",
"ntd",
".",
"Qualifier",
":",
"if",
"'not'",
"in",
"qual",
":",
"return",
"True",
"if",
"'NOT'",
"in",
"qual",
":",
"return",
"True",
"return",
"False"
] | Return True if the qualifiers contain a 'NOT | [
"Return",
"True",
"if",
"the",
"qualifiers",
"contain",
"a",
"NOT"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L178-L185 |
228,381 | tanghaibao/goatools | goatools/grouper/sorter_nts.py | SorterNts._get_sorted_section | def _get_sorted_section(self, nts_section):
"""Sort GO IDs in each section, if requested by user."""
#pylint: disable=unnecessary-lambda
if self.section_sortby is True:
return sorted(nts_section, key=lambda nt: self.sortgos.usrgo_sortby(nt))
if self.section_sortby is False or self.section_sortby is None:
return nts_section
# print('SORT GO IDS IN A SECTION')
return sorted(nts_section, key=lambda nt: self.section_sortby(nt)) | python | def _get_sorted_section(self, nts_section):
"""Sort GO IDs in each section, if requested by user."""
#pylint: disable=unnecessary-lambda
if self.section_sortby is True:
return sorted(nts_section, key=lambda nt: self.sortgos.usrgo_sortby(nt))
if self.section_sortby is False or self.section_sortby is None:
return nts_section
# print('SORT GO IDS IN A SECTION')
return sorted(nts_section, key=lambda nt: self.section_sortby(nt)) | [
"def",
"_get_sorted_section",
"(",
"self",
",",
"nts_section",
")",
":",
"#pylint: disable=unnecessary-lambda",
"if",
"self",
".",
"section_sortby",
"is",
"True",
":",
"return",
"sorted",
"(",
"nts_section",
",",
"key",
"=",
"lambda",
"nt",
":",
"self",
".",
"sortgos",
".",
"usrgo_sortby",
"(",
"nt",
")",
")",
"if",
"self",
".",
"section_sortby",
"is",
"False",
"or",
"self",
".",
"section_sortby",
"is",
"None",
":",
"return",
"nts_section",
"# print('SORT GO IDS IN A SECTION')",
"return",
"sorted",
"(",
"nts_section",
",",
"key",
"=",
"lambda",
"nt",
":",
"self",
".",
"section_sortby",
"(",
"nt",
")",
")"
] | Sort GO IDs in each section, if requested by user. | [
"Sort",
"GO",
"IDs",
"in",
"each",
"section",
"if",
"requested",
"by",
"user",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter_nts.py#L88-L96 |
228,382 | tanghaibao/goatools | goatools/godag/go_tasks.py | get_relationship_targets | def get_relationship_targets(item_ids, relationships, id2rec):
"""Get item ID set of item IDs in a relationship target set."""
# Requirements to use this function:
# 1) item Terms must have been loaded with 'relationships'
# 2) item IDs in 'item_ids' arguement must be present in id2rec
# 3) Arg, 'relationships' must be True or an iterable
reltgt_objs_all = set()
for goid in item_ids:
obj = id2rec[goid]
for reltype, reltgt_objs_cur in obj.relationship.items():
if relationships is True or reltype in relationships:
reltgt_objs_all.update(reltgt_objs_cur)
return reltgt_objs_all | python | def get_relationship_targets(item_ids, relationships, id2rec):
"""Get item ID set of item IDs in a relationship target set."""
# Requirements to use this function:
# 1) item Terms must have been loaded with 'relationships'
# 2) item IDs in 'item_ids' arguement must be present in id2rec
# 3) Arg, 'relationships' must be True or an iterable
reltgt_objs_all = set()
for goid in item_ids:
obj = id2rec[goid]
for reltype, reltgt_objs_cur in obj.relationship.items():
if relationships is True or reltype in relationships:
reltgt_objs_all.update(reltgt_objs_cur)
return reltgt_objs_all | [
"def",
"get_relationship_targets",
"(",
"item_ids",
",",
"relationships",
",",
"id2rec",
")",
":",
"# Requirements to use this function:",
"# 1) item Terms must have been loaded with 'relationships'",
"# 2) item IDs in 'item_ids' arguement must be present in id2rec",
"# 3) Arg, 'relationships' must be True or an iterable",
"reltgt_objs_all",
"=",
"set",
"(",
")",
"for",
"goid",
"in",
"item_ids",
":",
"obj",
"=",
"id2rec",
"[",
"goid",
"]",
"for",
"reltype",
",",
"reltgt_objs_cur",
"in",
"obj",
".",
"relationship",
".",
"items",
"(",
")",
":",
"if",
"relationships",
"is",
"True",
"or",
"reltype",
"in",
"relationships",
":",
"reltgt_objs_all",
".",
"update",
"(",
"reltgt_objs_cur",
")",
"return",
"reltgt_objs_all"
] | Get item ID set of item IDs in a relationship target set. | [
"Get",
"item",
"ID",
"set",
"of",
"item",
"IDs",
"in",
"a",
"relationship",
"target",
"set",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L35-L47 |
228,383 | tanghaibao/goatools | goatools/godag/go_tasks.py | _get_id2parents | def _get_id2parents(id2parents, item_id, item_obj):
"""Add the parent item IDs for one item object and their parents."""
if item_id in id2parents:
return id2parents[item_id]
parent_ids = set()
for parent_obj in item_obj.parents:
parent_id = parent_obj.item_id
parent_ids.add(parent_id)
parent_ids |= _get_id2parents(id2parents, parent_id, parent_obj)
id2parents[item_id] = parent_ids
return parent_ids | python | def _get_id2parents(id2parents, item_id, item_obj):
"""Add the parent item IDs for one item object and their parents."""
if item_id in id2parents:
return id2parents[item_id]
parent_ids = set()
for parent_obj in item_obj.parents:
parent_id = parent_obj.item_id
parent_ids.add(parent_id)
parent_ids |= _get_id2parents(id2parents, parent_id, parent_obj)
id2parents[item_id] = parent_ids
return parent_ids | [
"def",
"_get_id2parents",
"(",
"id2parents",
",",
"item_id",
",",
"item_obj",
")",
":",
"if",
"item_id",
"in",
"id2parents",
":",
"return",
"id2parents",
"[",
"item_id",
"]",
"parent_ids",
"=",
"set",
"(",
")",
"for",
"parent_obj",
"in",
"item_obj",
".",
"parents",
":",
"parent_id",
"=",
"parent_obj",
".",
"item_id",
"parent_ids",
".",
"add",
"(",
"parent_id",
")",
"parent_ids",
"|=",
"_get_id2parents",
"(",
"id2parents",
",",
"parent_id",
",",
"parent_obj",
")",
"id2parents",
"[",
"item_id",
"]",
"=",
"parent_ids",
"return",
"parent_ids"
] | Add the parent item IDs for one item object and their parents. | [
"Add",
"the",
"parent",
"item",
"IDs",
"for",
"one",
"item",
"object",
"and",
"their",
"parents",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L50-L60 |
228,384 | tanghaibao/goatools | goatools/godag/go_tasks.py | _get_id2children | def _get_id2children(id2children, item_id, item_obj):
"""Add the child item IDs for one item object and their children."""
if item_id in id2children:
return id2children[item_id]
child_ids = set()
for child_obj in item_obj.children:
child_id = child_obj.item_id
child_ids.add(child_id)
child_ids |= _get_id2children(id2children, child_id, child_obj)
id2children[item_id] = child_ids
return child_ids | python | def _get_id2children(id2children, item_id, item_obj):
"""Add the child item IDs for one item object and their children."""
if item_id in id2children:
return id2children[item_id]
child_ids = set()
for child_obj in item_obj.children:
child_id = child_obj.item_id
child_ids.add(child_id)
child_ids |= _get_id2children(id2children, child_id, child_obj)
id2children[item_id] = child_ids
return child_ids | [
"def",
"_get_id2children",
"(",
"id2children",
",",
"item_id",
",",
"item_obj",
")",
":",
"if",
"item_id",
"in",
"id2children",
":",
"return",
"id2children",
"[",
"item_id",
"]",
"child_ids",
"=",
"set",
"(",
")",
"for",
"child_obj",
"in",
"item_obj",
".",
"children",
":",
"child_id",
"=",
"child_obj",
".",
"item_id",
"child_ids",
".",
"add",
"(",
"child_id",
")",
"child_ids",
"|=",
"_get_id2children",
"(",
"id2children",
",",
"child_id",
",",
"child_obj",
")",
"id2children",
"[",
"item_id",
"]",
"=",
"child_ids",
"return",
"child_ids"
] | Add the child item IDs for one item object and their children. | [
"Add",
"the",
"child",
"item",
"IDs",
"for",
"one",
"item",
"object",
"and",
"their",
"children",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L62-L72 |
228,385 | tanghaibao/goatools | goatools/godag/go_tasks.py | _get_id2upper | def _get_id2upper(id2upper, item_id, item_obj):
"""Add the parent item IDs for one item object and their upper."""
if item_id in id2upper:
return id2upper[item_id]
upper_ids = set()
for upper_obj in item_obj.get_goterms_upper():
upper_id = upper_obj.item_id
upper_ids.add(upper_id)
upper_ids |= _get_id2upper(id2upper, upper_id, upper_obj)
id2upper[item_id] = upper_ids
return upper_ids | python | def _get_id2upper(id2upper, item_id, item_obj):
"""Add the parent item IDs for one item object and their upper."""
if item_id in id2upper:
return id2upper[item_id]
upper_ids = set()
for upper_obj in item_obj.get_goterms_upper():
upper_id = upper_obj.item_id
upper_ids.add(upper_id)
upper_ids |= _get_id2upper(id2upper, upper_id, upper_obj)
id2upper[item_id] = upper_ids
return upper_ids | [
"def",
"_get_id2upper",
"(",
"id2upper",
",",
"item_id",
",",
"item_obj",
")",
":",
"if",
"item_id",
"in",
"id2upper",
":",
"return",
"id2upper",
"[",
"item_id",
"]",
"upper_ids",
"=",
"set",
"(",
")",
"for",
"upper_obj",
"in",
"item_obj",
".",
"get_goterms_upper",
"(",
")",
":",
"upper_id",
"=",
"upper_obj",
".",
"item_id",
"upper_ids",
".",
"add",
"(",
"upper_id",
")",
"upper_ids",
"|=",
"_get_id2upper",
"(",
"id2upper",
",",
"upper_id",
",",
"upper_obj",
")",
"id2upper",
"[",
"item_id",
"]",
"=",
"upper_ids",
"return",
"upper_ids"
] | Add the parent item IDs for one item object and their upper. | [
"Add",
"the",
"parent",
"item",
"IDs",
"for",
"one",
"item",
"object",
"and",
"their",
"upper",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L74-L84 |
228,386 | tanghaibao/goatools | goatools/godag/go_tasks.py | _get_id2lower | def _get_id2lower(id2lower, item_id, item_obj):
"""Add the lower item IDs for one item object and the objects below them."""
if item_id in id2lower:
return id2lower[item_id]
lower_ids = set()
for lower_obj in item_obj.get_goterms_lower():
lower_id = lower_obj.item_id
lower_ids.add(lower_id)
lower_ids |= _get_id2lower(id2lower, lower_id, lower_obj)
id2lower[item_id] = lower_ids
return lower_ids | python | def _get_id2lower(id2lower, item_id, item_obj):
"""Add the lower item IDs for one item object and the objects below them."""
if item_id in id2lower:
return id2lower[item_id]
lower_ids = set()
for lower_obj in item_obj.get_goterms_lower():
lower_id = lower_obj.item_id
lower_ids.add(lower_id)
lower_ids |= _get_id2lower(id2lower, lower_id, lower_obj)
id2lower[item_id] = lower_ids
return lower_ids | [
"def",
"_get_id2lower",
"(",
"id2lower",
",",
"item_id",
",",
"item_obj",
")",
":",
"if",
"item_id",
"in",
"id2lower",
":",
"return",
"id2lower",
"[",
"item_id",
"]",
"lower_ids",
"=",
"set",
"(",
")",
"for",
"lower_obj",
"in",
"item_obj",
".",
"get_goterms_lower",
"(",
")",
":",
"lower_id",
"=",
"lower_obj",
".",
"item_id",
"lower_ids",
".",
"add",
"(",
"lower_id",
")",
"lower_ids",
"|=",
"_get_id2lower",
"(",
"id2lower",
",",
"lower_id",
",",
"lower_obj",
")",
"id2lower",
"[",
"item_id",
"]",
"=",
"lower_ids",
"return",
"lower_ids"
] | Add the lower item IDs for one item object and the objects below them. | [
"Add",
"the",
"lower",
"item",
"IDs",
"for",
"one",
"item",
"object",
"and",
"the",
"objects",
"below",
"them",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L86-L96 |
228,387 | tanghaibao/goatools | goatools/godag/go_tasks.py | CurNHigher.fill_parentidid2obj_r0 | def fill_parentidid2obj_r0(self, id2obj, child_obj):
"""Fill id2obj with all parent key item IDs and their objects."""
for parent_obj in child_obj.parents:
if parent_obj.item_id not in id2obj:
id2obj[parent_obj.item_id] = parent_obj
self.fill_parentidid2obj_r0(id2obj, parent_obj) | python | def fill_parentidid2obj_r0(self, id2obj, child_obj):
"""Fill id2obj with all parent key item IDs and their objects."""
for parent_obj in child_obj.parents:
if parent_obj.item_id not in id2obj:
id2obj[parent_obj.item_id] = parent_obj
self.fill_parentidid2obj_r0(id2obj, parent_obj) | [
"def",
"fill_parentidid2obj_r0",
"(",
"self",
",",
"id2obj",
",",
"child_obj",
")",
":",
"for",
"parent_obj",
"in",
"child_obj",
".",
"parents",
":",
"if",
"parent_obj",
".",
"item_id",
"not",
"in",
"id2obj",
":",
"id2obj",
"[",
"parent_obj",
".",
"item_id",
"]",
"=",
"parent_obj",
"self",
".",
"fill_parentidid2obj_r0",
"(",
"id2obj",
",",
"parent_obj",
")"
] | Fill id2obj with all parent key item IDs and their objects. | [
"Fill",
"id2obj",
"with",
"all",
"parent",
"key",
"item",
"IDs",
"and",
"their",
"objects",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L123-L128 |
228,388 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsBase.prt_ver | def prt_ver(self, prt):
"""Print version of GO-DAG for the GO and for GO slims."""
if self.ver_list is not None:
prt.write("# Versions:\n# {VER}\n\n".format(VER="\n# ".join(self.ver_list))) | python | def prt_ver(self, prt):
"""Print version of GO-DAG for the GO and for GO slims."""
if self.ver_list is not None:
prt.write("# Versions:\n# {VER}\n\n".format(VER="\n# ".join(self.ver_list))) | [
"def",
"prt_ver",
"(",
"self",
",",
"prt",
")",
":",
"if",
"self",
".",
"ver_list",
"is",
"not",
"None",
":",
"prt",
".",
"write",
"(",
"\"# Versions:\\n# {VER}\\n\\n\"",
".",
"format",
"(",
"VER",
"=",
"\"\\n# \"",
".",
"join",
"(",
"self",
".",
"ver_list",
")",
")",
")"
] | Print version of GO-DAG for the GO and for GO slims. | [
"Print",
"version",
"of",
"GO",
"-",
"DAG",
"for",
"the",
"GO",
"and",
"for",
"GO",
"slims",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L22-L25 |
228,389 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsBase.get_sections_2dnt | def get_sections_2dnt(self, sec2d_go):
"""Return a sections list containing sorted lists of namedtuples."""
return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go] | python | def get_sections_2dnt(self, sec2d_go):
"""Return a sections list containing sorted lists of namedtuples."""
return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go] | [
"def",
"get_sections_2dnt",
"(",
"self",
",",
"sec2d_go",
")",
":",
"return",
"[",
"(",
"nm",
",",
"self",
".",
"get_ntgos_sorted",
"(",
"gos",
")",
")",
"for",
"nm",
",",
"gos",
"in",
"sec2d_go",
"]"
] | Return a sections list containing sorted lists of namedtuples. | [
"Return",
"a",
"sections",
"list",
"containing",
"sorted",
"lists",
"of",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L27-L29 |
228,390 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsBase.get_ntgos_sorted | def get_ntgos_sorted(self, hdrgos):
"""Return sorted Grouper namedtuples if there are user GO IDs underneath."""
go2nt = self.grprobj.go2nt
return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt) | python | def get_ntgos_sorted(self, hdrgos):
"""Return sorted Grouper namedtuples if there are user GO IDs underneath."""
go2nt = self.grprobj.go2nt
return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt) | [
"def",
"get_ntgos_sorted",
"(",
"self",
",",
"hdrgos",
")",
":",
"go2nt",
"=",
"self",
".",
"grprobj",
".",
"go2nt",
"return",
"sorted",
"(",
"[",
"go2nt",
"[",
"go",
"]",
"for",
"go",
"in",
"hdrgos",
"if",
"go",
"in",
"go2nt",
"]",
",",
"key",
"=",
"self",
".",
"fncsortnt",
")"
] | Return sorted Grouper namedtuples if there are user GO IDs underneath. | [
"Return",
"sorted",
"Grouper",
"namedtuples",
"if",
"there",
"are",
"user",
"GO",
"IDs",
"underneath",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L31-L34 |
228,391 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsBase.prt_ntgos | def prt_ntgos(self, prt, ntgos):
"""Print the Grouper namedtuples."""
for ntgo in ntgos:
key2val = ntgo._asdict()
prt.write("{GO_LINE}\n".format(GO_LINE=self.prtfmt.format(**key2val))) | python | def prt_ntgos(self, prt, ntgos):
"""Print the Grouper namedtuples."""
for ntgo in ntgos:
key2val = ntgo._asdict()
prt.write("{GO_LINE}\n".format(GO_LINE=self.prtfmt.format(**key2val))) | [
"def",
"prt_ntgos",
"(",
"self",
",",
"prt",
",",
"ntgos",
")",
":",
"for",
"ntgo",
"in",
"ntgos",
":",
"key2val",
"=",
"ntgo",
".",
"_asdict",
"(",
")",
"prt",
".",
"write",
"(",
"\"{GO_LINE}\\n\"",
".",
"format",
"(",
"GO_LINE",
"=",
"self",
".",
"prtfmt",
".",
"format",
"(",
"*",
"*",
"key2val",
")",
")",
")"
] | Print the Grouper namedtuples. | [
"Print",
"the",
"Grouper",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L36-L40 |
228,392 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsPy.wr_py_sections_new | def wr_py_sections_new(self, fout_py, doc=None):
"""Write the first sections file."""
sections = self.grprobj.get_sections_2d()
return self.wr_py_sections(fout_py, sections, doc) | python | def wr_py_sections_new(self, fout_py, doc=None):
"""Write the first sections file."""
sections = self.grprobj.get_sections_2d()
return self.wr_py_sections(fout_py, sections, doc) | [
"def",
"wr_py_sections_new",
"(",
"self",
",",
"fout_py",
",",
"doc",
"=",
"None",
")",
":",
"sections",
"=",
"self",
".",
"grprobj",
".",
"get_sections_2d",
"(",
")",
"return",
"self",
".",
"wr_py_sections",
"(",
"fout_py",
",",
"sections",
",",
"doc",
")"
] | Write the first sections file. | [
"Write",
"the",
"first",
"sections",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L92-L95 |
228,393 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsPy.wr_py_sections | def wr_py_sections(self, fout_py, sections, doc=None):
"""Write sections 2-D list into a Python format list."""
if sections is None:
sections = self.grprobj.get_sections_2d()
sec2d_nt = self.get_sections_2dnt(sections) # lists of GO Grouper namedtuples
with open(fout_py, 'w') as prt:
self._prt_py_sections(sec2d_nt, prt, doc)
dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sections)
sys.stdout.write(self.grprobj.fmtsum.format(
GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
UNGRP=len(dat['U']), undesc="unused",
ACTION="WROTE:", FILE=fout_py)) | python | def wr_py_sections(self, fout_py, sections, doc=None):
"""Write sections 2-D list into a Python format list."""
if sections is None:
sections = self.grprobj.get_sections_2d()
sec2d_nt = self.get_sections_2dnt(sections) # lists of GO Grouper namedtuples
with open(fout_py, 'w') as prt:
self._prt_py_sections(sec2d_nt, prt, doc)
dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sections)
sys.stdout.write(self.grprobj.fmtsum.format(
GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
UNGRP=len(dat['U']), undesc="unused",
ACTION="WROTE:", FILE=fout_py)) | [
"def",
"wr_py_sections",
"(",
"self",
",",
"fout_py",
",",
"sections",
",",
"doc",
"=",
"None",
")",
":",
"if",
"sections",
"is",
"None",
":",
"sections",
"=",
"self",
".",
"grprobj",
".",
"get_sections_2d",
"(",
")",
"sec2d_nt",
"=",
"self",
".",
"get_sections_2dnt",
"(",
"sections",
")",
"# lists of GO Grouper namedtuples",
"with",
"open",
"(",
"fout_py",
",",
"'w'",
")",
"as",
"prt",
":",
"self",
".",
"_prt_py_sections",
"(",
"sec2d_nt",
",",
"prt",
",",
"doc",
")",
"dat",
"=",
"SummarySec2dHdrGos",
"(",
")",
".",
"summarize_sec2hdrgos",
"(",
"sections",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"self",
".",
"grprobj",
".",
"fmtsum",
".",
"format",
"(",
"GO_DESC",
"=",
"'hdr'",
",",
"SECs",
"=",
"len",
"(",
"dat",
"[",
"'S'",
"]",
")",
",",
"GOs",
"=",
"len",
"(",
"dat",
"[",
"'G'",
"]",
")",
",",
"UNGRP",
"=",
"len",
"(",
"dat",
"[",
"'U'",
"]",
")",
",",
"undesc",
"=",
"\"unused\"",
",",
"ACTION",
"=",
"\"WROTE:\"",
",",
"FILE",
"=",
"fout_py",
")",
")"
] | Write sections 2-D list into a Python format list. | [
"Write",
"sections",
"2",
"-",
"D",
"list",
"into",
"a",
"Python",
"format",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L97-L108 |
228,394 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsPy._prt_py_sections | def _prt_py_sections(self, sec2d_nt, prt=sys.stdout, doc=None):
"""Print sections 2-D list into a Python format list."""
if doc is None:
doc = 'Sections variable'
prt.write('"""{DOC}"""\n\n'.format(DOC=doc))
self.prt_ver(prt)
prt.write("# pylint: disable=line-too-long\n")
strcnt = self.get_summary_str(sec2d_nt)
prt.write("SECTIONS = [ # {CNTS}\n".format(CNTS=strcnt))
prt.write(' # ("New Section", [\n')
prt.write(' # ]),\n')
for section_name, nthdrgos in sec2d_nt:
self._prt_py_section(prt, section_name, nthdrgos)
prt.write("]\n") | python | def _prt_py_sections(self, sec2d_nt, prt=sys.stdout, doc=None):
"""Print sections 2-D list into a Python format list."""
if doc is None:
doc = 'Sections variable'
prt.write('"""{DOC}"""\n\n'.format(DOC=doc))
self.prt_ver(prt)
prt.write("# pylint: disable=line-too-long\n")
strcnt = self.get_summary_str(sec2d_nt)
prt.write("SECTIONS = [ # {CNTS}\n".format(CNTS=strcnt))
prt.write(' # ("New Section", [\n')
prt.write(' # ]),\n')
for section_name, nthdrgos in sec2d_nt:
self._prt_py_section(prt, section_name, nthdrgos)
prt.write("]\n") | [
"def",
"_prt_py_sections",
"(",
"self",
",",
"sec2d_nt",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"doc",
"=",
"None",
")",
":",
"if",
"doc",
"is",
"None",
":",
"doc",
"=",
"'Sections variable'",
"prt",
".",
"write",
"(",
"'\"\"\"{DOC}\"\"\"\\n\\n'",
".",
"format",
"(",
"DOC",
"=",
"doc",
")",
")",
"self",
".",
"prt_ver",
"(",
"prt",
")",
"prt",
".",
"write",
"(",
"\"# pylint: disable=line-too-long\\n\"",
")",
"strcnt",
"=",
"self",
".",
"get_summary_str",
"(",
"sec2d_nt",
")",
"prt",
".",
"write",
"(",
"\"SECTIONS = [ # {CNTS}\\n\"",
".",
"format",
"(",
"CNTS",
"=",
"strcnt",
")",
")",
"prt",
".",
"write",
"(",
"' # (\"New Section\", [\\n'",
")",
"prt",
".",
"write",
"(",
"' # ]),\\n'",
")",
"for",
"section_name",
",",
"nthdrgos",
"in",
"sec2d_nt",
":",
"self",
".",
"_prt_py_section",
"(",
"prt",
",",
"section_name",
",",
"nthdrgos",
")",
"prt",
".",
"write",
"(",
"\"]\\n\"",
")"
] | Print sections 2-D list into a Python format list. | [
"Print",
"sections",
"2",
"-",
"D",
"list",
"into",
"a",
"Python",
"format",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L110-L123 |
228,395 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsPy._prt_py_section | def _prt_py_section(self, prt, section_name, ntgos):
"""Print one section and its GO headers."""
prt.write(' ("{SEC}", [ # {N} GO-headers\n'.format(SEC=section_name, N=len(ntgos)))
self.prt_ntgos(prt, ntgos)
prt.write(" ]),\n") | python | def _prt_py_section(self, prt, section_name, ntgos):
"""Print one section and its GO headers."""
prt.write(' ("{SEC}", [ # {N} GO-headers\n'.format(SEC=section_name, N=len(ntgos)))
self.prt_ntgos(prt, ntgos)
prt.write(" ]),\n") | [
"def",
"_prt_py_section",
"(",
"self",
",",
"prt",
",",
"section_name",
",",
"ntgos",
")",
":",
"prt",
".",
"write",
"(",
"' (\"{SEC}\", [ # {N} GO-headers\\n'",
".",
"format",
"(",
"SEC",
"=",
"section_name",
",",
"N",
"=",
"len",
"(",
"ntgos",
")",
")",
")",
"self",
".",
"prt_ntgos",
"(",
"prt",
",",
"ntgos",
")",
"prt",
".",
"write",
"(",
"\" ]),\\n\"",
")"
] | Print one section and its GO headers. | [
"Print",
"one",
"section",
"and",
"its",
"GO",
"headers",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L125-L129 |
228,396 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsTxt.prt_goid_cnt | def prt_goid_cnt(self, prt=sys.stdout):
"""Get number of hdrgos and usrgos in each section."""
for section_name, hdrgos_sec in self.grprobj.get_sections_2d():
prt.write("{NAME} {Us:5,} {Hs:5,} {SEC}\n".format(
NAME=self.grprobj.grpname,
Us=len(self.grprobj.get_usrgos_g_hdrgos(hdrgos_sec)),
Hs=len(hdrgos_sec),
SEC=section_name)) | python | def prt_goid_cnt(self, prt=sys.stdout):
"""Get number of hdrgos and usrgos in each section."""
for section_name, hdrgos_sec in self.grprobj.get_sections_2d():
prt.write("{NAME} {Us:5,} {Hs:5,} {SEC}\n".format(
NAME=self.grprobj.grpname,
Us=len(self.grprobj.get_usrgos_g_hdrgos(hdrgos_sec)),
Hs=len(hdrgos_sec),
SEC=section_name)) | [
"def",
"prt_goid_cnt",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"for",
"section_name",
",",
"hdrgos_sec",
"in",
"self",
".",
"grprobj",
".",
"get_sections_2d",
"(",
")",
":",
"prt",
".",
"write",
"(",
"\"{NAME} {Us:5,} {Hs:5,} {SEC}\\n\"",
".",
"format",
"(",
"NAME",
"=",
"self",
".",
"grprobj",
".",
"grpname",
",",
"Us",
"=",
"len",
"(",
"self",
".",
"grprobj",
".",
"get_usrgos_g_hdrgos",
"(",
"hdrgos_sec",
")",
")",
",",
"Hs",
"=",
"len",
"(",
"hdrgos_sec",
")",
",",
"SEC",
"=",
"section_name",
")",
")"
] | Get number of hdrgos and usrgos in each section. | [
"Get",
"number",
"of",
"hdrgos",
"and",
"usrgos",
"in",
"each",
"section",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L162-L169 |
228,397 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsTxt.wr_txt_grouping_gos | def wr_txt_grouping_gos(self):
"""Write one file per GO group."""
prt_goids = self.grprobj.gosubdag.prt_goids
for hdrgo, usrgos in self.grprobj.hdrgo2usrgos.items():
keygos = usrgos.union([hdrgo])
fout_txt = "{BASE}.txt".format(BASE=self.grprobj.get_fout_base(hdrgo))
with open(fout_txt, 'w') as prt:
prt_goids(keygos, prt=prt)
sys.stdout.write(" {N:5,} GO IDs WROTE: {TXT}\n".format(
N=len(keygos), TXT=fout_txt)) | python | def wr_txt_grouping_gos(self):
"""Write one file per GO group."""
prt_goids = self.grprobj.gosubdag.prt_goids
for hdrgo, usrgos in self.grprobj.hdrgo2usrgos.items():
keygos = usrgos.union([hdrgo])
fout_txt = "{BASE}.txt".format(BASE=self.grprobj.get_fout_base(hdrgo))
with open(fout_txt, 'w') as prt:
prt_goids(keygos, prt=prt)
sys.stdout.write(" {N:5,} GO IDs WROTE: {TXT}\n".format(
N=len(keygos), TXT=fout_txt)) | [
"def",
"wr_txt_grouping_gos",
"(",
"self",
")",
":",
"prt_goids",
"=",
"self",
".",
"grprobj",
".",
"gosubdag",
".",
"prt_goids",
"for",
"hdrgo",
",",
"usrgos",
"in",
"self",
".",
"grprobj",
".",
"hdrgo2usrgos",
".",
"items",
"(",
")",
":",
"keygos",
"=",
"usrgos",
".",
"union",
"(",
"[",
"hdrgo",
"]",
")",
"fout_txt",
"=",
"\"{BASE}.txt\"",
".",
"format",
"(",
"BASE",
"=",
"self",
".",
"grprobj",
".",
"get_fout_base",
"(",
"hdrgo",
")",
")",
"with",
"open",
"(",
"fout_txt",
",",
"'w'",
")",
"as",
"prt",
":",
"prt_goids",
"(",
"keygos",
",",
"prt",
"=",
"prt",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" {N:5,} GO IDs WROTE: {TXT}\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"keygos",
")",
",",
"TXT",
"=",
"fout_txt",
")",
")"
] | Write one file per GO group. | [
"Write",
"one",
"file",
"per",
"GO",
"group",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L171-L180 |
228,398 | tanghaibao/goatools | goatools/grouper/wr_sections.py | WrSectionsTxt.wr_txt_section_hdrgos | def wr_txt_section_hdrgos(self, fout_txt, sortby=None, prt_section=True):
"""Write high GO IDs that are actually used to group current set of GO IDs."""
sec2d_go = self.grprobj.get_sections_2d() # lists of GO IDs
sec2d_nt = self.get_sections_2dnt(sec2d_go) # lists of GO Grouper namedtuples
if sortby is None:
sortby = self.fncsortnt
with open(fout_txt, 'w') as prt:
self.prt_ver(prt)
prt.write("# GROUP NAME: {NAME}\n".format(NAME=self.grprobj.grpname))
for section_name, nthdrgos_actual in sec2d_nt:
if prt_section:
prt.write("# SECTION: {SECTION}\n".format(SECTION=section_name))
self.prt_ntgos(prt, nthdrgos_actual)
if prt_section:
prt.write("\n")
dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sec2d_go)
sys.stdout.write(self.grprobj.fmtsum.format(
GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
UNGRP=len(dat['U']), undesc="unused",
ACTION="WROTE:", FILE=fout_txt))
return sec2d_nt | python | def wr_txt_section_hdrgos(self, fout_txt, sortby=None, prt_section=True):
"""Write high GO IDs that are actually used to group current set of GO IDs."""
sec2d_go = self.grprobj.get_sections_2d() # lists of GO IDs
sec2d_nt = self.get_sections_2dnt(sec2d_go) # lists of GO Grouper namedtuples
if sortby is None:
sortby = self.fncsortnt
with open(fout_txt, 'w') as prt:
self.prt_ver(prt)
prt.write("# GROUP NAME: {NAME}\n".format(NAME=self.grprobj.grpname))
for section_name, nthdrgos_actual in sec2d_nt:
if prt_section:
prt.write("# SECTION: {SECTION}\n".format(SECTION=section_name))
self.prt_ntgos(prt, nthdrgos_actual)
if prt_section:
prt.write("\n")
dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sec2d_go)
sys.stdout.write(self.grprobj.fmtsum.format(
GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
UNGRP=len(dat['U']), undesc="unused",
ACTION="WROTE:", FILE=fout_txt))
return sec2d_nt | [
"def",
"wr_txt_section_hdrgos",
"(",
"self",
",",
"fout_txt",
",",
"sortby",
"=",
"None",
",",
"prt_section",
"=",
"True",
")",
":",
"sec2d_go",
"=",
"self",
".",
"grprobj",
".",
"get_sections_2d",
"(",
")",
"# lists of GO IDs",
"sec2d_nt",
"=",
"self",
".",
"get_sections_2dnt",
"(",
"sec2d_go",
")",
"# lists of GO Grouper namedtuples",
"if",
"sortby",
"is",
"None",
":",
"sortby",
"=",
"self",
".",
"fncsortnt",
"with",
"open",
"(",
"fout_txt",
",",
"'w'",
")",
"as",
"prt",
":",
"self",
".",
"prt_ver",
"(",
"prt",
")",
"prt",
".",
"write",
"(",
"\"# GROUP NAME: {NAME}\\n\"",
".",
"format",
"(",
"NAME",
"=",
"self",
".",
"grprobj",
".",
"grpname",
")",
")",
"for",
"section_name",
",",
"nthdrgos_actual",
"in",
"sec2d_nt",
":",
"if",
"prt_section",
":",
"prt",
".",
"write",
"(",
"\"# SECTION: {SECTION}\\n\"",
".",
"format",
"(",
"SECTION",
"=",
"section_name",
")",
")",
"self",
".",
"prt_ntgos",
"(",
"prt",
",",
"nthdrgos_actual",
")",
"if",
"prt_section",
":",
"prt",
".",
"write",
"(",
"\"\\n\"",
")",
"dat",
"=",
"SummarySec2dHdrGos",
"(",
")",
".",
"summarize_sec2hdrgos",
"(",
"sec2d_go",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"self",
".",
"grprobj",
".",
"fmtsum",
".",
"format",
"(",
"GO_DESC",
"=",
"'hdr'",
",",
"SECs",
"=",
"len",
"(",
"dat",
"[",
"'S'",
"]",
")",
",",
"GOs",
"=",
"len",
"(",
"dat",
"[",
"'G'",
"]",
")",
",",
"UNGRP",
"=",
"len",
"(",
"dat",
"[",
"'U'",
"]",
")",
",",
"undesc",
"=",
"\"unused\"",
",",
"ACTION",
"=",
"\"WROTE:\"",
",",
"FILE",
"=",
"fout_txt",
")",
")",
"return",
"sec2d_nt"
] | Write high GO IDs that are actually used to group current set of GO IDs. | [
"Write",
"high",
"GO",
"IDs",
"that",
"are",
"actually",
"used",
"to",
"group",
"current",
"set",
"of",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L182-L202 |
228,399 | tanghaibao/goatools | goatools/parsers/david_chart.py | DavidChartReader.prt_num_sig | def prt_num_sig(self, prt=sys.stdout, alpha=0.05):
"""Print the number of significant GO terms."""
ctr = self.get_num_sig(alpha)
prt.write("{N:6,} TOTAL: {TXT}\n".format(N=len(self.nts), TXT=" ".join([
"FDR({FDR:4})".format(FDR=ctr['FDR']),
"Bonferroni({B:4})".format(B=ctr['Bonferroni']),
"Benjamini({B:4})".format(B=ctr['Benjamini']),
"PValue({P:4})".format(P=ctr['PValue']),
os.path.basename(self.fin_davidchart)]))) | python | def prt_num_sig(self, prt=sys.stdout, alpha=0.05):
"""Print the number of significant GO terms."""
ctr = self.get_num_sig(alpha)
prt.write("{N:6,} TOTAL: {TXT}\n".format(N=len(self.nts), TXT=" ".join([
"FDR({FDR:4})".format(FDR=ctr['FDR']),
"Bonferroni({B:4})".format(B=ctr['Bonferroni']),
"Benjamini({B:4})".format(B=ctr['Benjamini']),
"PValue({P:4})".format(P=ctr['PValue']),
os.path.basename(self.fin_davidchart)]))) | [
"def",
"prt_num_sig",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"alpha",
"=",
"0.05",
")",
":",
"ctr",
"=",
"self",
".",
"get_num_sig",
"(",
"alpha",
")",
"prt",
".",
"write",
"(",
"\"{N:6,} TOTAL: {TXT}\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"self",
".",
"nts",
")",
",",
"TXT",
"=",
"\" \"",
".",
"join",
"(",
"[",
"\"FDR({FDR:4})\"",
".",
"format",
"(",
"FDR",
"=",
"ctr",
"[",
"'FDR'",
"]",
")",
",",
"\"Bonferroni({B:4})\"",
".",
"format",
"(",
"B",
"=",
"ctr",
"[",
"'Bonferroni'",
"]",
")",
",",
"\"Benjamini({B:4})\"",
".",
"format",
"(",
"B",
"=",
"ctr",
"[",
"'Benjamini'",
"]",
")",
",",
"\"PValue({P:4})\"",
".",
"format",
"(",
"P",
"=",
"ctr",
"[",
"'PValue'",
"]",
")",
",",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"fin_davidchart",
")",
"]",
")",
")",
")"
] | Print the number of significant GO terms. | [
"Print",
"the",
"number",
"of",
"significant",
"GO",
"terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L81-L89 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.