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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._extract_rows | def _extract_rows(self, rows):
"""
Extract an array of rows from an input scalar or sequence
"""
if rows is not None:
rows = numpy.array(rows, ndmin=1, copy=False, dtype='i8')
# returns unique, sorted
rows = numpy.unique(rows)
maxrow = sel... | python | def _extract_rows(self, rows):
"""
Extract an array of rows from an input scalar or sequence
"""
if rows is not None:
rows = numpy.array(rows, ndmin=1, copy=False, dtype='i8')
# returns unique, sorted
rows = numpy.unique(rows)
maxrow = sel... | [
"def",
"_extract_rows",
"(",
"self",
",",
"rows",
")",
":",
"if",
"rows",
"is",
"not",
"None",
":",
"rows",
"=",
"numpy",
".",
"array",
"(",
"rows",
",",
"ndmin",
"=",
"1",
",",
"copy",
"=",
"False",
",",
"dtype",
"=",
"'i8'",
")",
"rows",
"=",
... | Extract an array of rows from an input scalar or sequence | [
"Extract",
"an",
"array",
"of",
"rows",
"from",
"an",
"input",
"scalar",
"or",
"sequence"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1190-L1202 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._process_slice | def _process_slice(self, arg):
"""
process the input slice for use calling the C code
"""
start = arg.start
stop = arg.stop
step = arg.step
nrows = self._info['nrows']
if step is None:
step = 1
if start is None:
start = 0
... | python | def _process_slice(self, arg):
"""
process the input slice for use calling the C code
"""
start = arg.start
stop = arg.stop
step = arg.step
nrows = self._info['nrows']
if step is None:
step = 1
if start is None:
start = 0
... | [
"def",
"_process_slice",
"(",
"self",
",",
"arg",
")",
":",
"start",
"=",
"arg",
".",
"start",
"stop",
"=",
"arg",
".",
"stop",
"step",
"=",
"arg",
".",
"step",
"nrows",
"=",
"self",
".",
"_info",
"[",
"'nrows'",
"]",
"if",
"step",
"is",
"None",
... | process the input slice for use calling the C code | [
"process",
"the",
"input",
"slice",
"for",
"use",
"calling",
"the",
"C",
"code"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1204-L1234 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._slice2rows | def _slice2rows(self, start, stop, step=None):
"""
Convert a slice to an explicit array of rows
"""
nrows = self._info['nrows']
if start is None:
start = 0
if stop is None:
stop = nrows
if step is None:
step = 1
tstart ... | python | def _slice2rows(self, start, stop, step=None):
"""
Convert a slice to an explicit array of rows
"""
nrows = self._info['nrows']
if start is None:
start = 0
if stop is None:
stop = nrows
if step is None:
step = 1
tstart ... | [
"def",
"_slice2rows",
"(",
"self",
",",
"start",
",",
"stop",
",",
"step",
"=",
"None",
")",
":",
"nrows",
"=",
"self",
".",
"_info",
"[",
"'nrows'",
"]",
"if",
"start",
"is",
"None",
":",
"start",
"=",
"0",
"if",
"stop",
"is",
"None",
":",
"stop... | Convert a slice to an explicit array of rows | [
"Convert",
"a",
"slice",
"to",
"an",
"explicit",
"array",
"of",
"rows"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1236-L1256 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._fix_range | def _fix_range(self, num, isslice=True):
"""
Ensure the input is within range.
If el=True, then don't treat as a slice element
"""
nrows = self._info['nrows']
if isslice:
# include the end
if num < 0:
num = nrows + (1+num)
... | python | def _fix_range(self, num, isslice=True):
"""
Ensure the input is within range.
If el=True, then don't treat as a slice element
"""
nrows = self._info['nrows']
if isslice:
# include the end
if num < 0:
num = nrows + (1+num)
... | [
"def",
"_fix_range",
"(",
"self",
",",
"num",
",",
"isslice",
"=",
"True",
")",
":",
"nrows",
"=",
"self",
".",
"_info",
"[",
"'nrows'",
"]",
"if",
"isslice",
":",
"if",
"num",
"<",
"0",
":",
"num",
"=",
"nrows",
"+",
"(",
"1",
"+",
"num",
")",... | Ensure the input is within range.
If el=True, then don't treat as a slice element | [
"Ensure",
"the",
"input",
"is",
"within",
"range",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1258-L1279 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._rescale_and_convert_field_inplace | def _rescale_and_convert_field_inplace(self, array, name, scale, zero):
"""
Apply fits scalings. Also, convert bool to proper
numpy boolean values
"""
self._rescale_array(array[name], scale, zero)
if array[name].dtype == numpy.bool:
array[name] = self._conver... | python | def _rescale_and_convert_field_inplace(self, array, name, scale, zero):
"""
Apply fits scalings. Also, convert bool to proper
numpy boolean values
"""
self._rescale_array(array[name], scale, zero)
if array[name].dtype == numpy.bool:
array[name] = self._conver... | [
"def",
"_rescale_and_convert_field_inplace",
"(",
"self",
",",
"array",
",",
"name",
",",
"scale",
",",
"zero",
")",
":",
"self",
".",
"_rescale_array",
"(",
"array",
"[",
"name",
"]",
",",
"scale",
",",
"zero",
")",
"if",
"array",
"[",
"name",
"]",
".... | Apply fits scalings. Also, convert bool to proper
numpy boolean values | [
"Apply",
"fits",
"scalings",
".",
"Also",
"convert",
"bool",
"to",
"proper",
"numpy",
"boolean",
"values"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1281-L1289 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._rescale_array | def _rescale_array(self, array, scale, zero):
"""
Scale the input array
"""
if scale != 1.0:
sval = numpy.array(scale, dtype=array.dtype)
array *= sval
if zero != 0.0:
zval = numpy.array(zero, dtype=array.dtype)
array += zval | python | def _rescale_array(self, array, scale, zero):
"""
Scale the input array
"""
if scale != 1.0:
sval = numpy.array(scale, dtype=array.dtype)
array *= sval
if zero != 0.0:
zval = numpy.array(zero, dtype=array.dtype)
array += zval | [
"def",
"_rescale_array",
"(",
"self",
",",
"array",
",",
"scale",
",",
"zero",
")",
":",
"if",
"scale",
"!=",
"1.0",
":",
"sval",
"=",
"numpy",
".",
"array",
"(",
"scale",
",",
"dtype",
"=",
"array",
".",
"dtype",
")",
"array",
"*=",
"sval",
"if",
... | Scale the input array | [
"Scale",
"the",
"input",
"array"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1302-L1311 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._maybe_trim_strings | def _maybe_trim_strings(self, array, **keys):
"""
if requested, trim trailing white space from
all string fields in the input array
"""
trim_strings = keys.get('trim_strings', False)
if self.trim_strings or trim_strings:
_trim_strings(array) | python | def _maybe_trim_strings(self, array, **keys):
"""
if requested, trim trailing white space from
all string fields in the input array
"""
trim_strings = keys.get('trim_strings', False)
if self.trim_strings or trim_strings:
_trim_strings(array) | [
"def",
"_maybe_trim_strings",
"(",
"self",
",",
"array",
",",
"**",
"keys",
")",
":",
"trim_strings",
"=",
"keys",
".",
"get",
"(",
"'trim_strings'",
",",
"False",
")",
"if",
"self",
".",
"trim_strings",
"or",
"trim_strings",
":",
"_trim_strings",
"(",
"ar... | if requested, trim trailing white space from
all string fields in the input array | [
"if",
"requested",
"trim",
"trailing",
"white",
"space",
"from",
"all",
"string",
"fields",
"in",
"the",
"input",
"array"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1313-L1320 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._get_tbl_numpy_dtype | def _get_tbl_numpy_dtype(self, colnum, include_endianness=True):
"""
Get numpy type for the input column
"""
table_type = self._info['hdutype']
table_type_string = _hdu_type_map[table_type]
try:
ftype = self._info['colinfo'][colnum]['eqtype']
if ta... | python | def _get_tbl_numpy_dtype(self, colnum, include_endianness=True):
"""
Get numpy type for the input column
"""
table_type = self._info['hdutype']
table_type_string = _hdu_type_map[table_type]
try:
ftype = self._info['colinfo'][colnum]['eqtype']
if ta... | [
"def",
"_get_tbl_numpy_dtype",
"(",
"self",
",",
"colnum",
",",
"include_endianness",
"=",
"True",
")",
":",
"table_type",
"=",
"self",
".",
"_info",
"[",
"'hdutype'",
"]",
"table_type_string",
"=",
"_hdu_type_map",
"[",
"table_type",
"]",
"try",
":",
"ftype",... | Get numpy type for the input column | [
"Get",
"numpy",
"type",
"for",
"the",
"input",
"column"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1353-L1393 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._process_args_as_rows_or_columns | def _process_args_as_rows_or_columns(self, arg, unpack=False):
"""
We must be able to interpret the args as as either a column name or
row number, or sequences thereof. Numpy arrays and slices are also
fine.
Examples:
'field'
35
[35,55,86]
... | python | def _process_args_as_rows_or_columns(self, arg, unpack=False):
"""
We must be able to interpret the args as as either a column name or
row number, or sequences thereof. Numpy arrays and slices are also
fine.
Examples:
'field'
35
[35,55,86]
... | [
"def",
"_process_args_as_rows_or_columns",
"(",
"self",
",",
"arg",
",",
"unpack",
"=",
"False",
")",
":",
"flags",
"=",
"set",
"(",
")",
"if",
"isinstance",
"(",
"arg",
",",
"(",
"tuple",
",",
"list",
",",
"numpy",
".",
"ndarray",
")",
")",
":",
"if... | We must be able to interpret the args as as either a column name or
row number, or sequences thereof. Numpy arrays and slices are also
fine.
Examples:
'field'
35
[35,55,86]
['f1',f2',...]
Can also be tuples or arrays. | [
"We",
"must",
"be",
"able",
"to",
"interpret",
"the",
"args",
"as",
"as",
"either",
"a",
"column",
"name",
"or",
"row",
"number",
"or",
"sequences",
"thereof",
".",
"Numpy",
"arrays",
"and",
"slices",
"are",
"also",
"fine",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1395-L1437 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._extract_colnums | def _extract_colnums(self, columns=None):
"""
Extract an array of columns from the input
"""
if columns is None:
return numpy.arange(self._ncol, dtype='i8')
if not isinstance(columns, (tuple, list, numpy.ndarray)):
# is a scalar
return self._e... | python | def _extract_colnums(self, columns=None):
"""
Extract an array of columns from the input
"""
if columns is None:
return numpy.arange(self._ncol, dtype='i8')
if not isinstance(columns, (tuple, list, numpy.ndarray)):
# is a scalar
return self._e... | [
"def",
"_extract_colnums",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"if",
"columns",
"is",
"None",
":",
"return",
"numpy",
".",
"arange",
"(",
"self",
".",
"_ncol",
",",
"dtype",
"=",
"'i8'",
")",
"if",
"not",
"isinstance",
"(",
"columns",
... | Extract an array of columns from the input | [
"Extract",
"an",
"array",
"of",
"columns",
"from",
"the",
"input"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1494-L1511 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._extract_colnum | def _extract_colnum(self, col):
"""
Get the column number for the input column
"""
if isinteger(col):
colnum = col
if (colnum < 0) or (colnum > (self._ncol-1)):
raise ValueError(
"column number should be in [0,%d]" % (0, self._... | python | def _extract_colnum(self, col):
"""
Get the column number for the input column
"""
if isinteger(col):
colnum = col
if (colnum < 0) or (colnum > (self._ncol-1)):
raise ValueError(
"column number should be in [0,%d]" % (0, self._... | [
"def",
"_extract_colnum",
"(",
"self",
",",
"col",
")",
":",
"if",
"isinteger",
"(",
"col",
")",
":",
"colnum",
"=",
"col",
"if",
"(",
"colnum",
"<",
"0",
")",
"or",
"(",
"colnum",
">",
"(",
"self",
".",
"_ncol",
"-",
"1",
")",
")",
":",
"raise... | Get the column number for the input column | [
"Get",
"the",
"column",
"number",
"for",
"the",
"input",
"column"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1513-L1535 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._update_info | def _update_info(self):
"""
Call parent method and make sure this is in fact a
table HDU. Set some convenience data.
"""
super(TableHDU, self)._update_info()
if self._info['hdutype'] == IMAGE_HDU:
mess = "Extension %s is not a Table HDU" % self.ext
... | python | def _update_info(self):
"""
Call parent method and make sure this is in fact a
table HDU. Set some convenience data.
"""
super(TableHDU, self)._update_info()
if self._info['hdutype'] == IMAGE_HDU:
mess = "Extension %s is not a Table HDU" % self.ext
... | [
"def",
"_update_info",
"(",
"self",
")",
":",
"super",
"(",
"TableHDU",
",",
"self",
")",
".",
"_update_info",
"(",
")",
"if",
"self",
".",
"_info",
"[",
"'hdutype'",
"]",
"==",
"IMAGE_HDU",
":",
"mess",
"=",
"\"Extension %s is not a Table HDU\"",
"%",
"se... | Call parent method and make sure this is in fact a
table HDU. Set some convenience data. | [
"Call",
"parent",
"method",
"and",
"make",
"sure",
"this",
"is",
"in",
"fact",
"a",
"table",
"HDU",
".",
"Set",
"some",
"convenience",
"data",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1537-L1550 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._get_next_buffered_row | def _get_next_buffered_row(self):
"""
Get the next row for iteration.
"""
if self._iter_row == self._iter_nrows:
raise StopIteration
if self._row_buffer_index >= self._iter_row_buffer:
self._buffer_iter_rows(self._iter_row)
data = self._row_buffe... | python | def _get_next_buffered_row(self):
"""
Get the next row for iteration.
"""
if self._iter_row == self._iter_nrows:
raise StopIteration
if self._row_buffer_index >= self._iter_row_buffer:
self._buffer_iter_rows(self._iter_row)
data = self._row_buffe... | [
"def",
"_get_next_buffered_row",
"(",
"self",
")",
":",
"if",
"self",
".",
"_iter_row",
"==",
"self",
".",
"_iter_nrows",
":",
"raise",
"StopIteration",
"if",
"self",
".",
"_row_buffer_index",
">=",
"self",
".",
"_iter_row_buffer",
":",
"self",
".",
"_buffer_i... | Get the next row for iteration. | [
"Get",
"the",
"next",
"row",
"for",
"iteration",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1640-L1653 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableHDU._buffer_iter_rows | def _buffer_iter_rows(self, start):
"""
Read in the buffer for iteration
"""
self._row_buffer = self[start:start+self._iter_row_buffer]
# start back at the front of the buffer
self._row_buffer_index = 0 | python | def _buffer_iter_rows(self, start):
"""
Read in the buffer for iteration
"""
self._row_buffer = self[start:start+self._iter_row_buffer]
# start back at the front of the buffer
self._row_buffer_index = 0 | [
"def",
"_buffer_iter_rows",
"(",
"self",
",",
"start",
")",
":",
"self",
".",
"_row_buffer",
"=",
"self",
"[",
"start",
":",
"start",
"+",
"self",
".",
"_iter_row_buffer",
"]",
"self",
".",
"_row_buffer_index",
"=",
"0"
] | Read in the buffer for iteration | [
"Read",
"in",
"the",
"buffer",
"for",
"iteration"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1655-L1662 | train |
esheldon/fitsio | fitsio/hdu/table.py | AsciiTableHDU.read | def read(self, **keys):
"""
read a data from an ascii table HDU
By default, all rows are read. Send rows= to select subsets of the
data. Table data are read into a recarray for multiple columns,
plain array for a single column.
parameters
----------
co... | python | def read(self, **keys):
"""
read a data from an ascii table HDU
By default, all rows are read. Send rows= to select subsets of the
data. Table data are read into a recarray for multiple columns,
plain array for a single column.
parameters
----------
co... | [
"def",
"read",
"(",
"self",
",",
"**",
"keys",
")",
":",
"rows",
"=",
"keys",
".",
"get",
"(",
"'rows'",
",",
"None",
")",
"columns",
"=",
"keys",
".",
"get",
"(",
"'columns'",
",",
"None",
")",
"colnums",
"=",
"self",
".",
"_extract_colnums",
"(",... | read a data from an ascii table HDU
By default, all rows are read. Send rows= to select subsets of the
data. Table data are read into a recarray for multiple columns,
plain array for a single column.
parameters
----------
columns: list/array
An optional se... | [
"read",
"a",
"data",
"from",
"an",
"ascii",
"table",
"HDU"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1713-L1816 | train |
esheldon/fitsio | fitsio/hdu/table.py | TableColumnSubset.read | def read(self, **keys):
"""
Read the data from disk and return as a numpy array
"""
if self.is_scalar:
data = self.fitshdu.read_column(self.columns, **keys)
else:
c = keys.get('columns', None)
if c is None:
keys['columns'] = se... | python | def read(self, **keys):
"""
Read the data from disk and return as a numpy array
"""
if self.is_scalar:
data = self.fitshdu.read_column(self.columns, **keys)
else:
c = keys.get('columns', None)
if c is None:
keys['columns'] = se... | [
"def",
"read",
"(",
"self",
",",
"**",
"keys",
")",
":",
"if",
"self",
".",
"is_scalar",
":",
"data",
"=",
"self",
".",
"fitshdu",
".",
"read_column",
"(",
"self",
".",
"columns",
",",
"**",
"keys",
")",
"else",
":",
"c",
"=",
"keys",
".",
"get",... | Read the data from disk and return as a numpy array | [
"Read",
"the",
"data",
"from",
"disk",
"and",
"return",
"as",
"a",
"numpy",
"array"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/table.py#L1868-L1881 | train |
esheldon/fitsio | fitsio/fitslib.py | read | def read(filename, ext=None, extver=None, **keys):
"""
Convenience function to read data from the specified FITS HDU
By default, all data are read. For tables, send columns= and rows= to
select subsets of the data. Table data are read into a recarray; use a
FITS object and read_column() to get a ... | python | def read(filename, ext=None, extver=None, **keys):
"""
Convenience function to read data from the specified FITS HDU
By default, all data are read. For tables, send columns= and rows= to
select subsets of the data. Table data are read into a recarray; use a
FITS object and read_column() to get a ... | [
"def",
"read",
"(",
"filename",
",",
"ext",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"**",
"keys",
")",
":",
"with",
"FITS",
"(",
"filename",
",",
"**",
"keys",
")",
"as",
"fits",
":",
"header",
"=",
"keys",
".",
"pop",
"(",
"'header'",
",",... | Convenience function to read data from the specified FITS HDU
By default, all data are read. For tables, send columns= and rows= to
select subsets of the data. Table data are read into a recarray; use a
FITS object and read_column() to get a single column as an ordinary array.
For images, create a FI... | [
"Convenience",
"function",
"to",
"read",
"data",
"from",
"the",
"specified",
"FITS",
"HDU"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L51-L117 | train |
esheldon/fitsio | fitsio/fitslib.py | read_header | def read_header(filename, ext=0, extver=None, case_sensitive=False, **keys):
"""
Convenience function to read the header from the specified FITS HDU
The FITSHDR allows access to the values and comments by name and
number.
parameters
----------
filename: string
A filename.
ext: ... | python | def read_header(filename, ext=0, extver=None, case_sensitive=False, **keys):
"""
Convenience function to read the header from the specified FITS HDU
The FITSHDR allows access to the values and comments by name and
number.
parameters
----------
filename: string
A filename.
ext: ... | [
"def",
"read_header",
"(",
"filename",
",",
"ext",
"=",
"0",
",",
"extver",
"=",
"None",
",",
"case_sensitive",
"=",
"False",
",",
"**",
"keys",
")",
":",
"dont_create",
"=",
"0",
"try",
":",
"hdunum",
"=",
"ext",
"+",
"1",
"except",
"TypeError",
":"... | Convenience function to read the header from the specified FITS HDU
The FITSHDR allows access to the values and comments by name and
number.
parameters
----------
filename: string
A filename.
ext: number or string, optional
The extension. Either the numerical extension from ze... | [
"Convenience",
"function",
"to",
"read",
"the",
"header",
"from",
"the",
"specified",
"FITS",
"HDU"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L120-L190 | train |
esheldon/fitsio | fitsio/fitslib.py | read_scamp_head | def read_scamp_head(fname, header=None):
"""
read a SCAMP .head file as a fits header FITSHDR object
parameters
----------
fname: string
The path to the SCAMP .head file
header: FITSHDR, optional
Optionally combine the header with the input one. The input can
be any obj... | python | def read_scamp_head(fname, header=None):
"""
read a SCAMP .head file as a fits header FITSHDR object
parameters
----------
fname: string
The path to the SCAMP .head file
header: FITSHDR, optional
Optionally combine the header with the input one. The input can
be any obj... | [
"def",
"read_scamp_head",
"(",
"fname",
",",
"header",
"=",
"None",
")",
":",
"with",
"open",
"(",
"fname",
")",
"as",
"fobj",
":",
"lines",
"=",
"fobj",
".",
"readlines",
"(",
")",
"lines",
"=",
"[",
"l",
".",
"strip",
"(",
")",
"for",
"l",
"in"... | read a SCAMP .head file as a fits header FITSHDR object
parameters
----------
fname: string
The path to the SCAMP .head file
header: FITSHDR, optional
Optionally combine the header with the input one. The input can
be any object convertable to a FITSHDR object
returns
... | [
"read",
"a",
"SCAMP",
".",
"head",
"file",
"as",
"a",
"fits",
"header",
"FITSHDR",
"object"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L193-L223 | train |
esheldon/fitsio | fitsio/fitslib.py | write | def write(filename, data, extname=None, extver=None, units=None,
compress=None, table_type='binary', header=None,
clobber=False, **keys):
"""
Convenience function to create a new HDU and write the data.
Under the hood, a FITS object is constructed. If you want to append rows
to an ... | python | def write(filename, data, extname=None, extver=None, units=None,
compress=None, table_type='binary', header=None,
clobber=False, **keys):
"""
Convenience function to create a new HDU and write the data.
Under the hood, a FITS object is constructed. If you want to append rows
to an ... | [
"def",
"write",
"(",
"filename",
",",
"data",
",",
"extname",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"units",
"=",
"None",
",",
"compress",
"=",
"None",
",",
"table_type",
"=",
"'binary'",
",",
"header",
"=",
"None",
",",
"clobber",
"=",
"Fals... | Convenience function to create a new HDU and write the data.
Under the hood, a FITS object is constructed. If you want to append rows
to an existing HDU, or modify data in an HDU, please construct a FITS
object.
parameters
----------
filename: string
A filename.
data:
Eith... | [
"Convenience",
"function",
"to",
"create",
"a",
"new",
"HDU",
"and",
"write",
"the",
"data",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L236-L317 | train |
esheldon/fitsio | fitsio/fitslib.py | array2tabledef | def array2tabledef(data, table_type='binary', write_bitcols=False):
"""
Similar to descr2tabledef but if there are object columns a type
and max length will be extracted and used for the tabledef
"""
is_ascii = (table_type == 'ascii')
if data.dtype.fields is None:
raise ValueError("data... | python | def array2tabledef(data, table_type='binary', write_bitcols=False):
"""
Similar to descr2tabledef but if there are object columns a type
and max length will be extracted and used for the tabledef
"""
is_ascii = (table_type == 'ascii')
if data.dtype.fields is None:
raise ValueError("data... | [
"def",
"array2tabledef",
"(",
"data",
",",
"table_type",
"=",
"'binary'",
",",
"write_bitcols",
"=",
"False",
")",
":",
"is_ascii",
"=",
"(",
"table_type",
"==",
"'ascii'",
")",
"if",
"data",
".",
"dtype",
".",
"fields",
"is",
"None",
":",
"raise",
"Valu... | Similar to descr2tabledef but if there are object columns a type
and max length will be extracted and used for the tabledef | [
"Similar",
"to",
"descr2tabledef",
"but",
"if",
"there",
"are",
"object",
"columns",
"a",
"type",
"and",
"max",
"length",
"will",
"be",
"extracted",
"and",
"used",
"for",
"the",
"tabledef"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1237-L1298 | train |
esheldon/fitsio | fitsio/fitslib.py | descr2tabledef | def descr2tabledef(descr, table_type='binary', write_bitcols=False):
"""
Create a FITS table def from the input numpy descriptor.
parameters
----------
descr: list
A numpy recarray type descriptor array.dtype.descr
returns
-------
names, formats, dims: tuple of lists
T... | python | def descr2tabledef(descr, table_type='binary', write_bitcols=False):
"""
Create a FITS table def from the input numpy descriptor.
parameters
----------
descr: list
A numpy recarray type descriptor array.dtype.descr
returns
-------
names, formats, dims: tuple of lists
T... | [
"def",
"descr2tabledef",
"(",
"descr",
",",
"table_type",
"=",
"'binary'",
",",
"write_bitcols",
"=",
"False",
")",
":",
"names",
"=",
"[",
"]",
"formats",
"=",
"[",
"]",
"dims",
"=",
"[",
"]",
"for",
"d",
"in",
"descr",
":",
"if",
"d",
"[",
"1",
... | Create a FITS table def from the input numpy descriptor.
parameters
----------
descr: list
A numpy recarray type descriptor array.dtype.descr
returns
-------
names, formats, dims: tuple of lists
These are the ttyp, tform and tdim header entries
for each field. dim ent... | [
"Create",
"a",
"FITS",
"table",
"def",
"from",
"the",
"input",
"numpy",
"descriptor",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1356-L1406 | train |
esheldon/fitsio | fitsio/fitslib.py | get_tile_dims | def get_tile_dims(tile_dims, imshape):
"""
Just make sure the tile dims has the appropriate number of dimensions
"""
if tile_dims is None:
td = None
else:
td = numpy.array(tile_dims, dtype='i8')
nd = len(imshape)
if td.size != nd:
msg = "expected tile_dim... | python | def get_tile_dims(tile_dims, imshape):
"""
Just make sure the tile dims has the appropriate number of dimensions
"""
if tile_dims is None:
td = None
else:
td = numpy.array(tile_dims, dtype='i8')
nd = len(imshape)
if td.size != nd:
msg = "expected tile_dim... | [
"def",
"get_tile_dims",
"(",
"tile_dims",
",",
"imshape",
")",
":",
"if",
"tile_dims",
"is",
"None",
":",
"td",
"=",
"None",
"else",
":",
"td",
"=",
"numpy",
".",
"array",
"(",
"tile_dims",
",",
"dtype",
"=",
"'i8'",
")",
"nd",
"=",
"len",
"(",
"im... | Just make sure the tile dims has the appropriate number of dimensions | [
"Just",
"make",
"sure",
"the",
"tile",
"dims",
"has",
"the",
"appropriate",
"number",
"of",
"dimensions"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1452-L1466 | train |
esheldon/fitsio | fitsio/fitslib.py | _extract_table_type | def _extract_table_type(type):
"""
Get the numerical table type
"""
if isinstance(type, str):
type = type.lower()
if type[0:7] == 'binary':
table_type = BINARY_TBL
elif type[0:6] == 'ascii':
table_type = ASCII_TBL
else:
raise ValueError... | python | def _extract_table_type(type):
"""
Get the numerical table type
"""
if isinstance(type, str):
type = type.lower()
if type[0:7] == 'binary':
table_type = BINARY_TBL
elif type[0:6] == 'ascii':
table_type = ASCII_TBL
else:
raise ValueError... | [
"def",
"_extract_table_type",
"(",
"type",
")",
":",
"if",
"isinstance",
"(",
"type",
",",
"str",
")",
":",
"type",
"=",
"type",
".",
"lower",
"(",
")",
"if",
"type",
"[",
"0",
":",
"7",
"]",
"==",
"'binary'",
":",
"table_type",
"=",
"BINARY_TBL",
... | Get the numerical table type | [
"Get",
"the",
"numerical",
"table",
"type"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1496-L1518 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.close | def close(self):
"""
Close the fits file and set relevant metadata to None
"""
if hasattr(self, '_FITS'):
if self._FITS is not None:
self._FITS.close()
self._FITS = None
self._filename = None
self.mode = None
self.charmo... | python | def close(self):
"""
Close the fits file and set relevant metadata to None
"""
if hasattr(self, '_FITS'):
if self._FITS is not None:
self._FITS.close()
self._FITS = None
self._filename = None
self.mode = None
self.charmo... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_FITS'",
")",
":",
"if",
"self",
".",
"_FITS",
"is",
"not",
"None",
":",
"self",
".",
"_FITS",
".",
"close",
"(",
")",
"self",
".",
"_FITS",
"=",
"None",
"self",
".",
"... | Close the fits file and set relevant metadata to None | [
"Close",
"the",
"fits",
"file",
"and",
"set",
"relevant",
"metadata",
"to",
"None"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L409-L422 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.movnam_hdu | def movnam_hdu(self, extname, hdutype=ANY_HDU, extver=0):
"""
Move to the indicated HDU by name
In general, it is not necessary to use this method explicitly.
returns the one-offset extension number
"""
extname = mks(extname)
hdu = self._FITS.movnam_hdu(hdutype,... | python | def movnam_hdu(self, extname, hdutype=ANY_HDU, extver=0):
"""
Move to the indicated HDU by name
In general, it is not necessary to use this method explicitly.
returns the one-offset extension number
"""
extname = mks(extname)
hdu = self._FITS.movnam_hdu(hdutype,... | [
"def",
"movnam_hdu",
"(",
"self",
",",
"extname",
",",
"hdutype",
"=",
"ANY_HDU",
",",
"extver",
"=",
"0",
")",
":",
"extname",
"=",
"mks",
"(",
"extname",
")",
"hdu",
"=",
"self",
".",
"_FITS",
".",
"movnam_hdu",
"(",
"hdutype",
",",
"extname",
",",... | Move to the indicated HDU by name
In general, it is not necessary to use this method explicitly.
returns the one-offset extension number | [
"Move",
"to",
"the",
"indicated",
"HDU",
"by",
"name"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L452-L462 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.reopen | def reopen(self):
"""
close and reopen the fits file with the same mode
"""
self._FITS.close()
del self._FITS
self._FITS = _fitsio_wrap.FITS(self._filename, self.intmode, 0)
self.update_hdu_list() | python | def reopen(self):
"""
close and reopen the fits file with the same mode
"""
self._FITS.close()
del self._FITS
self._FITS = _fitsio_wrap.FITS(self._filename, self.intmode, 0)
self.update_hdu_list() | [
"def",
"reopen",
"(",
"self",
")",
":",
"self",
".",
"_FITS",
".",
"close",
"(",
")",
"del",
"self",
".",
"_FITS",
"self",
".",
"_FITS",
"=",
"_fitsio_wrap",
".",
"FITS",
"(",
"self",
".",
"_filename",
",",
"self",
".",
"intmode",
",",
"0",
")",
... | close and reopen the fits file with the same mode | [
"close",
"and",
"reopen",
"the",
"fits",
"file",
"with",
"the",
"same",
"mode"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L464-L471 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.write | def write(self, data, units=None, extname=None, extver=None,
compress=None, tile_dims=None,
header=None,
names=None,
table_type='binary', write_bitcols=False, **keys):
"""
Write the data to a new HDU.
This method is a wrapper. If this is ... | python | def write(self, data, units=None, extname=None, extver=None,
compress=None, tile_dims=None,
header=None,
names=None,
table_type='binary', write_bitcols=False, **keys):
"""
Write the data to a new HDU.
This method is a wrapper. If this is ... | [
"def",
"write",
"(",
"self",
",",
"data",
",",
"units",
"=",
"None",
",",
"extname",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"compress",
"=",
"None",
",",
"tile_dims",
"=",
"None",
",",
"header",
"=",
"None",
",",
"names",
"=",
"None",
",",
... | Write the data to a new HDU.
This method is a wrapper. If this is an IMAGE_HDU, write_image is
called, otherwise write_table is called.
parameters
----------
data: ndarray
An n-dimensional image or an array with fields.
extname: string, optional
... | [
"Write",
"the",
"data",
"to",
"a",
"new",
"HDU",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L473-L549 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.write_image | def write_image(self, img, extname=None, extver=None,
compress=None, tile_dims=None, header=None):
"""
Create a new image extension and write the data.
parameters
----------
img: ndarray
An n-dimensional image.
extname: string, optional
... | python | def write_image(self, img, extname=None, extver=None,
compress=None, tile_dims=None, header=None):
"""
Create a new image extension and write the data.
parameters
----------
img: ndarray
An n-dimensional image.
extname: string, optional
... | [
"def",
"write_image",
"(",
"self",
",",
"img",
",",
"extname",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"compress",
"=",
"None",
",",
"tile_dims",
"=",
"None",
",",
"header",
"=",
"None",
")",
":",
"self",
".",
"create_image_hdu",
"(",
"img",
",... | Create a new image extension and write the data.
parameters
----------
img: ndarray
An n-dimensional image.
extname: string, optional
An optional extension name.
extver: integer, optional
FITS allows multiple extensions to have the same name (... | [
"Create",
"a",
"new",
"image",
"extension",
"and",
"write",
"the",
"data",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L551-L601 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.create_image_hdu | def create_image_hdu(self,
img=None,
dims=None,
dtype=None,
extname=None,
extver=None,
compress=None,
tile_dims=None,
he... | python | def create_image_hdu(self,
img=None,
dims=None,
dtype=None,
extname=None,
extver=None,
compress=None,
tile_dims=None,
he... | [
"def",
"create_image_hdu",
"(",
"self",
",",
"img",
"=",
"None",
",",
"dims",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"extname",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"compress",
"=",
"None",
",",
"tile_dims",
"=",
"None",
",",
"header",... | Create a new, empty image HDU and reload the hdu list. Either
create from an input image or from input dims and dtype
fits.create_image_hdu(image, ...)
fits.create_image_hdu(dims=dims, dtype=dtype)
If an image is sent, the data are also written.
You can write data int... | [
"Create",
"a",
"new",
"empty",
"image",
"HDU",
"and",
"reload",
"the",
"hdu",
"list",
".",
"Either",
"create",
"from",
"an",
"input",
"image",
"or",
"from",
"input",
"dims",
"and",
"dtype"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L606-L765 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS._ensure_empty_image_ok | def _ensure_empty_image_ok(self):
"""
If ignore_empty was not set to True, we only allow empty HDU for first
HDU and if there is no data there already
"""
if self.ignore_empty:
return
if len(self) > 1:
raise RuntimeError(
"Cannot w... | python | def _ensure_empty_image_ok(self):
"""
If ignore_empty was not set to True, we only allow empty HDU for first
HDU and if there is no data there already
"""
if self.ignore_empty:
return
if len(self) > 1:
raise RuntimeError(
"Cannot w... | [
"def",
"_ensure_empty_image_ok",
"(",
"self",
")",
":",
"if",
"self",
".",
"ignore_empty",
":",
"return",
"if",
"len",
"(",
"self",
")",
">",
"1",
":",
"raise",
"RuntimeError",
"(",
"\"Cannot write None image at extension %d\"",
"%",
"len",
"(",
"self",
")",
... | If ignore_empty was not set to True, we only allow empty HDU for first
HDU and if there is no data there already | [
"If",
"ignore_empty",
"was",
"not",
"set",
"to",
"True",
"we",
"only",
"allow",
"empty",
"HDU",
"for",
"first",
"HDU",
"and",
"if",
"there",
"is",
"no",
"data",
"there",
"already"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L767-L780 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.write_table | def write_table(self, data, table_type='binary',
names=None, formats=None, units=None,
extname=None, extver=None, header=None,
write_bitcols=False):
"""
Create a new table extension and write the data.
The table definition is taken fro... | python | def write_table(self, data, table_type='binary',
names=None, formats=None, units=None,
extname=None, extver=None, header=None,
write_bitcols=False):
"""
Create a new table extension and write the data.
The table definition is taken fro... | [
"def",
"write_table",
"(",
"self",
",",
"data",
",",
"table_type",
"=",
"'binary'",
",",
"names",
"=",
"None",
",",
"formats",
"=",
"None",
",",
"units",
"=",
"None",
",",
"extname",
"=",
"None",
",",
"extver",
"=",
"None",
",",
"header",
"=",
"None"... | Create a new table extension and write the data.
The table definition is taken from the fields in the input array. If
you want to append new rows to the table, access the HDU directly and
use the write() function, e.g.
fits[extension].append(data)
parameters
-----... | [
"Create",
"a",
"new",
"table",
"extension",
"and",
"write",
"the",
"data",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L782-L853 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.create_table_hdu | def create_table_hdu(self, data=None, dtype=None,
header=None,
names=None, formats=None,
units=None, dims=None, extname=None, extver=None,
table_type='binary', write_bitcols=False):
"""
Create a new, empt... | python | def create_table_hdu(self, data=None, dtype=None,
header=None,
names=None, formats=None,
units=None, dims=None, extname=None, extver=None,
table_type='binary', write_bitcols=False):
"""
Create a new, empt... | [
"def",
"create_table_hdu",
"(",
"self",
",",
"data",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"header",
"=",
"None",
",",
"names",
"=",
"None",
",",
"formats",
"=",
"None",
",",
"units",
"=",
"None",
",",
"dims",
"=",
"None",
",",
"extname",
"=... | Create a new, empty table extension and reload the hdu list.
There are three ways to do it:
1) send a numpy dtype, from which the formats in the fits file will
be determined.
2) Send an array in data= keyword. this is required if you have
object fields fo... | [
"Create",
"a",
"new",
"empty",
"table",
"extension",
"and",
"reload",
"the",
"hdu",
"list",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L861-L1017 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.update_hdu_list | def update_hdu_list(self, rebuild=True):
"""
Force an update of the entire HDU list
Normally you don't need to call this method directly
if rebuild is false or the hdu_list is not yet set, the list is
rebuilt from scratch
"""
if not hasattr(self, 'hdu_list'):
... | python | def update_hdu_list(self, rebuild=True):
"""
Force an update of the entire HDU list
Normally you don't need to call this method directly
if rebuild is false or the hdu_list is not yet set, the list is
rebuilt from scratch
"""
if not hasattr(self, 'hdu_list'):
... | [
"def",
"update_hdu_list",
"(",
"self",
",",
"rebuild",
"=",
"True",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'hdu_list'",
")",
":",
"rebuild",
"=",
"True",
"if",
"rebuild",
":",
"self",
".",
"hdu_list",
"=",
"[",
"]",
"self",
".",
"hdu_ma... | Force an update of the entire HDU list
Normally you don't need to call this method directly
if rebuild is false or the hdu_list is not yet set, the list is
rebuilt from scratch | [
"Force",
"an",
"update",
"of",
"the",
"entire",
"HDU",
"list"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1019-L1051 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS.next | def next(self):
"""
Move to the next iteration
"""
if self._iter_index == len(self.hdu_list):
raise StopIteration
hdu = self.hdu_list[self._iter_index]
self._iter_index += 1
return hdu | python | def next(self):
"""
Move to the next iteration
"""
if self._iter_index == len(self.hdu_list):
raise StopIteration
hdu = self.hdu_list[self._iter_index]
self._iter_index += 1
return hdu | [
"def",
"next",
"(",
"self",
")",
":",
"if",
"self",
".",
"_iter_index",
"==",
"len",
"(",
"self",
".",
"hdu_list",
")",
":",
"raise",
"StopIteration",
"hdu",
"=",
"self",
".",
"hdu_list",
"[",
"self",
".",
"_iter_index",
"]",
"self",
".",
"_iter_index"... | Move to the next iteration | [
"Move",
"to",
"the",
"next",
"iteration"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1101-L1109 | train |
esheldon/fitsio | fitsio/fitslib.py | FITS._extract_item | def _extract_item(self, item):
"""
utility function to extract an "item", meaning
a extension number,name plus version.
"""
ver = 0
if isinstance(item, tuple):
ver_sent = True
nitem = len(item)
if nitem == 1:
ext = item[... | python | def _extract_item(self, item):
"""
utility function to extract an "item", meaning
a extension number,name plus version.
"""
ver = 0
if isinstance(item, tuple):
ver_sent = True
nitem = len(item)
if nitem == 1:
ext = item[... | [
"def",
"_extract_item",
"(",
"self",
",",
"item",
")",
":",
"ver",
"=",
"0",
"if",
"isinstance",
"(",
"item",
",",
"tuple",
")",
":",
"ver_sent",
"=",
"True",
"nitem",
"=",
"len",
"(",
"item",
")",
"if",
"nitem",
"==",
"1",
":",
"ext",
"=",
"item... | utility function to extract an "item", meaning
a extension number,name plus version. | [
"utility",
"function",
"to",
"extract",
"an",
"item",
"meaning",
"a",
"extension",
"number",
"name",
"plus",
"version",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/fitslib.py#L1121-L1137 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU._update_info | def _update_info(self):
"""
Call parent method and make sure this is in fact a
image HDU. Set dims in C order
"""
super(ImageHDU, self)._update_info()
if self._info['hdutype'] != IMAGE_HDU:
mess = "Extension %s is not a Image HDU" % self.ext
rais... | python | def _update_info(self):
"""
Call parent method and make sure this is in fact a
image HDU. Set dims in C order
"""
super(ImageHDU, self)._update_info()
if self._info['hdutype'] != IMAGE_HDU:
mess = "Extension %s is not a Image HDU" % self.ext
rais... | [
"def",
"_update_info",
"(",
"self",
")",
":",
"super",
"(",
"ImageHDU",
",",
"self",
")",
".",
"_update_info",
"(",
")",
"if",
"self",
".",
"_info",
"[",
"'hdutype'",
"]",
"!=",
"IMAGE_HDU",
":",
"mess",
"=",
"\"Extension %s is not a Image HDU\"",
"%",
"se... | Call parent method and make sure this is in fact a
image HDU. Set dims in C order | [
"Call",
"parent",
"method",
"and",
"make",
"sure",
"this",
"is",
"in",
"fact",
"a",
"image",
"HDU",
".",
"Set",
"dims",
"in",
"C",
"order"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L37-L50 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU.reshape | def reshape(self, dims):
"""
reshape an existing image to the requested dimensions
parameters
----------
dims: sequence
Any sequence convertible to i8
"""
adims = numpy.array(dims, ndmin=1, dtype='i8')
self._FITS.reshape_image(self._ext+1, ad... | python | def reshape(self, dims):
"""
reshape an existing image to the requested dimensions
parameters
----------
dims: sequence
Any sequence convertible to i8
"""
adims = numpy.array(dims, ndmin=1, dtype='i8')
self._FITS.reshape_image(self._ext+1, ad... | [
"def",
"reshape",
"(",
"self",
",",
"dims",
")",
":",
"adims",
"=",
"numpy",
".",
"array",
"(",
"dims",
",",
"ndmin",
"=",
"1",
",",
"dtype",
"=",
"'i8'",
")",
"self",
".",
"_FITS",
".",
"reshape_image",
"(",
"self",
".",
"_ext",
"+",
"1",
",",
... | reshape an existing image to the requested dimensions
parameters
----------
dims: sequence
Any sequence convertible to i8 | [
"reshape",
"an",
"existing",
"image",
"to",
"the",
"requested",
"dimensions"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L91-L102 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU.write | def write(self, img, start=0, **keys):
"""
Write the image into this HDU
If data already exist in this HDU, they will be overwritten. If the
image to write is larger than the image on disk, or if the start
position is such that the write would extend beyond the existing
... | python | def write(self, img, start=0, **keys):
"""
Write the image into this HDU
If data already exist in this HDU, they will be overwritten. If the
image to write is larger than the image on disk, or if the start
position is such that the write would extend beyond the existing
... | [
"def",
"write",
"(",
"self",
",",
"img",
",",
"start",
"=",
"0",
",",
"**",
"keys",
")",
":",
"dims",
"=",
"self",
".",
"get_dims",
"(",
")",
"if",
"img",
".",
"dtype",
".",
"fields",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"got r... | Write the image into this HDU
If data already exist in this HDU, they will be overwritten. If the
image to write is larger than the image on disk, or if the start
position is such that the write would extend beyond the existing
dimensions, the on-disk image is expanded.
parame... | [
"Write",
"the",
"image",
"into",
"this",
"HDU"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L104-L156 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU.read | def read(self, **keys):
"""
Read the image.
If the HDU is an IMAGE_HDU, read the corresponding image. Compression
and scaling are dealt with properly.
"""
if not self.has_data():
return None
dtype, shape = self._get_dtype_and_shape()
array =... | python | def read(self, **keys):
"""
Read the image.
If the HDU is an IMAGE_HDU, read the corresponding image. Compression
and scaling are dealt with properly.
"""
if not self.has_data():
return None
dtype, shape = self._get_dtype_and_shape()
array =... | [
"def",
"read",
"(",
"self",
",",
"**",
"keys",
")",
":",
"if",
"not",
"self",
".",
"has_data",
"(",
")",
":",
"return",
"None",
"dtype",
",",
"shape",
"=",
"self",
".",
"_get_dtype_and_shape",
"(",
")",
"array",
"=",
"numpy",
".",
"zeros",
"(",
"sh... | Read the image.
If the HDU is an IMAGE_HDU, read the corresponding image. Compression
and scaling are dealt with properly. | [
"Read",
"the",
"image",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L158-L171 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU._get_dtype_and_shape | def _get_dtype_and_shape(self):
"""
Get the numpy dtype and shape for image
"""
npy_dtype = self._get_image_numpy_dtype()
if self._info['ndims'] != 0:
shape = self._info['dims']
else:
raise IOError("no image present in HDU")
return npy_dt... | python | def _get_dtype_and_shape(self):
"""
Get the numpy dtype and shape for image
"""
npy_dtype = self._get_image_numpy_dtype()
if self._info['ndims'] != 0:
shape = self._info['dims']
else:
raise IOError("no image present in HDU")
return npy_dt... | [
"def",
"_get_dtype_and_shape",
"(",
"self",
")",
":",
"npy_dtype",
"=",
"self",
".",
"_get_image_numpy_dtype",
"(",
")",
"if",
"self",
".",
"_info",
"[",
"'ndims'",
"]",
"!=",
"0",
":",
"shape",
"=",
"self",
".",
"_info",
"[",
"'dims'",
"]",
"else",
":... | Get the numpy dtype and shape for image | [
"Get",
"the",
"numpy",
"dtype",
"and",
"shape",
"for",
"image"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L173-L184 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU._get_image_numpy_dtype | def _get_image_numpy_dtype(self):
"""
Get the numpy dtype for the image
"""
try:
ftype = self._info['img_equiv_type']
npy_type = _image_bitpix2npy[ftype]
except KeyError:
raise KeyError("unsupported fits data type: %d" % ftype)
return ... | python | def _get_image_numpy_dtype(self):
"""
Get the numpy dtype for the image
"""
try:
ftype = self._info['img_equiv_type']
npy_type = _image_bitpix2npy[ftype]
except KeyError:
raise KeyError("unsupported fits data type: %d" % ftype)
return ... | [
"def",
"_get_image_numpy_dtype",
"(",
"self",
")",
":",
"try",
":",
"ftype",
"=",
"self",
".",
"_info",
"[",
"'img_equiv_type'",
"]",
"npy_type",
"=",
"_image_bitpix2npy",
"[",
"ftype",
"]",
"except",
"KeyError",
":",
"raise",
"KeyError",
"(",
"\"unsupported f... | Get the numpy dtype for the image | [
"Get",
"the",
"numpy",
"dtype",
"for",
"the",
"image"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L186-L196 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU._read_image_slice | def _read_image_slice(self, arg):
"""
workhorse to read a slice
"""
if 'ndims' not in self._info:
raise ValueError("Attempt to slice empty extension")
if isinstance(arg, slice):
# one-dimensional, e.g. 2:20
return self._read_image_slice((arg,)... | python | def _read_image_slice(self, arg):
"""
workhorse to read a slice
"""
if 'ndims' not in self._info:
raise ValueError("Attempt to slice empty extension")
if isinstance(arg, slice):
# one-dimensional, e.g. 2:20
return self._read_image_slice((arg,)... | [
"def",
"_read_image_slice",
"(",
"self",
",",
"arg",
")",
":",
"if",
"'ndims'",
"not",
"in",
"self",
".",
"_info",
":",
"raise",
"ValueError",
"(",
"\"Attempt to slice empty extension\"",
")",
"if",
"isinstance",
"(",
"arg",
",",
"slice",
")",
":",
"return",... | workhorse to read a slice | [
"workhorse",
"to",
"read",
"a",
"slice"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L206-L295 | train |
esheldon/fitsio | fitsio/hdu/image.py | ImageHDU._expand_if_needed | def _expand_if_needed(self, dims, write_dims, start, offset):
"""
expand the on-disk image if the indended write will extend
beyond the existing dimensions
"""
from operator import mul
if numpy.isscalar(start):
start_is_scalar = True
else:
... | python | def _expand_if_needed(self, dims, write_dims, start, offset):
"""
expand the on-disk image if the indended write will extend
beyond the existing dimensions
"""
from operator import mul
if numpy.isscalar(start):
start_is_scalar = True
else:
... | [
"def",
"_expand_if_needed",
"(",
"self",
",",
"dims",
",",
"write_dims",
",",
"start",
",",
"offset",
")",
":",
"from",
"operator",
"import",
"mul",
"if",
"numpy",
".",
"isscalar",
"(",
"start",
")",
":",
"start_is_scalar",
"=",
"True",
"else",
":",
"sta... | expand the on-disk image if the indended write will extend
beyond the existing dimensions | [
"expand",
"the",
"on",
"-",
"disk",
"image",
"if",
"the",
"indended",
"write",
"will",
"extend",
"beyond",
"the",
"existing",
"dimensions"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/image.py#L297-L350 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.get_extname | def get_extname(self):
"""
Get the name for this extension, can be an empty string
"""
name = self._info['extname']
if name.strip() == '':
name = self._info['hduname']
return name.strip() | python | def get_extname(self):
"""
Get the name for this extension, can be an empty string
"""
name = self._info['extname']
if name.strip() == '':
name = self._info['hduname']
return name.strip() | [
"def",
"get_extname",
"(",
"self",
")",
":",
"name",
"=",
"self",
".",
"_info",
"[",
"'extname'",
"]",
"if",
"name",
".",
"strip",
"(",
")",
"==",
"''",
":",
"name",
"=",
"self",
".",
"_info",
"[",
"'hduname'",
"]",
"return",
"name",
".",
"strip",
... | Get the name for this extension, can be an empty string | [
"Get",
"the",
"name",
"for",
"this",
"extension",
"can",
"be",
"an",
"empty",
"string"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L59-L66 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.get_extver | def get_extver(self):
"""
Get the version for this extension.
Used when a name is given to multiple extensions
"""
ver = self._info['extver']
if ver == 0:
ver = self._info['hduver']
return ver | python | def get_extver(self):
"""
Get the version for this extension.
Used when a name is given to multiple extensions
"""
ver = self._info['extver']
if ver == 0:
ver = self._info['hduver']
return ver | [
"def",
"get_extver",
"(",
"self",
")",
":",
"ver",
"=",
"self",
".",
"_info",
"[",
"'extver'",
"]",
"if",
"ver",
"==",
"0",
":",
"ver",
"=",
"self",
".",
"_info",
"[",
"'hduver'",
"]",
"return",
"ver"
] | Get the version for this extension.
Used when a name is given to multiple extensions | [
"Get",
"the",
"version",
"for",
"this",
"extension",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L68-L77 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.get_exttype | def get_exttype(self, num=False):
"""
Get the extension type
By default the result is a string that mirrors
the enumerated type names in cfitsio
'IMAGE_HDU', 'ASCII_TBL', 'BINARY_TBL'
which have numeric values
0 1 2
send num=True to get the number... | python | def get_exttype(self, num=False):
"""
Get the extension type
By default the result is a string that mirrors
the enumerated type names in cfitsio
'IMAGE_HDU', 'ASCII_TBL', 'BINARY_TBL'
which have numeric values
0 1 2
send num=True to get the number... | [
"def",
"get_exttype",
"(",
"self",
",",
"num",
"=",
"False",
")",
":",
"if",
"num",
":",
"return",
"self",
".",
"_info",
"[",
"'hdutype'",
"]",
"else",
":",
"name",
"=",
"_hdu_type_map",
"[",
"self",
".",
"_info",
"[",
"'hdutype'",
"]",
"]",
"return"... | Get the extension type
By default the result is a string that mirrors
the enumerated type names in cfitsio
'IMAGE_HDU', 'ASCII_TBL', 'BINARY_TBL'
which have numeric values
0 1 2
send num=True to get the numbers. The values
fitsio.IMAGE_HDU .ASCII_TBL... | [
"Get",
"the",
"extension",
"type"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L79-L101 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.verify_checksum | def verify_checksum(self):
"""
Verify the checksum in the header for this HDU.
"""
res = self._FITS.verify_checksum(self._ext+1)
if res['dataok'] != 1:
raise ValueError("data checksum failed")
if res['hduok'] != 1:
raise ValueError("hdu checksum fa... | python | def verify_checksum(self):
"""
Verify the checksum in the header for this HDU.
"""
res = self._FITS.verify_checksum(self._ext+1)
if res['dataok'] != 1:
raise ValueError("data checksum failed")
if res['hduok'] != 1:
raise ValueError("hdu checksum fa... | [
"def",
"verify_checksum",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"_FITS",
".",
"verify_checksum",
"(",
"self",
".",
"_ext",
"+",
"1",
")",
"if",
"res",
"[",
"'dataok'",
"]",
"!=",
"1",
":",
"raise",
"ValueError",
"(",
"\"data checksum failed\"",... | Verify the checksum in the header for this HDU. | [
"Verify",
"the",
"checksum",
"in",
"the",
"header",
"for",
"this",
"HDU",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L153-L161 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.write_comment | def write_comment(self, comment):
"""
Write a comment into the header
"""
self._FITS.write_comment(self._ext+1, str(comment)) | python | def write_comment(self, comment):
"""
Write a comment into the header
"""
self._FITS.write_comment(self._ext+1, str(comment)) | [
"def",
"write_comment",
"(",
"self",
",",
"comment",
")",
":",
"self",
".",
"_FITS",
".",
"write_comment",
"(",
"self",
".",
"_ext",
"+",
"1",
",",
"str",
"(",
"comment",
")",
")"
] | Write a comment into the header | [
"Write",
"a",
"comment",
"into",
"the",
"header"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L163-L167 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.write_key | def write_key(self, name, value, comment=""):
"""
Write the input value to the header
parameters
----------
name: string
Name of keyword to write/update
value: scalar
Value to write, can be string float or integer type,
including numpy... | python | def write_key(self, name, value, comment=""):
"""
Write the input value to the header
parameters
----------
name: string
Name of keyword to write/update
value: scalar
Value to write, can be string float or integer type,
including numpy... | [
"def",
"write_key",
"(",
"self",
",",
"name",
",",
"value",
",",
"comment",
"=",
"\"\"",
")",
":",
"if",
"value",
"is",
"None",
":",
"self",
".",
"_FITS",
".",
"write_undefined_key",
"(",
"self",
".",
"_ext",
"+",
"1",
",",
"str",
"(",
"name",
")",... | Write the input value to the header
parameters
----------
name: string
Name of keyword to write/update
value: scalar
Value to write, can be string float or integer type,
including numpy scalar types.
comment: string, optional
An op... | [
"Write",
"the",
"input",
"value",
"to",
"the",
"header"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L181-L247 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase.write_keys | def write_keys(self, records_in, clean=True):
"""
Write the keywords to the header.
parameters
----------
records: FITSHDR or list or dict
Can be one of these:
- FITSHDR object
- list of dictionaries containing 'name','value' and optio... | python | def write_keys(self, records_in, clean=True):
"""
Write the keywords to the header.
parameters
----------
records: FITSHDR or list or dict
Can be one of these:
- FITSHDR object
- list of dictionaries containing 'name','value' and optio... | [
"def",
"write_keys",
"(",
"self",
",",
"records_in",
",",
"clean",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"records_in",
",",
"FITSHDR",
")",
":",
"hdr",
"=",
"records_in",
"else",
":",
"hdr",
"=",
"FITSHDR",
"(",
"records_in",
")",
"if",
"clea... | Write the keywords to the header.
parameters
----------
records: FITSHDR or list or dict
Can be one of these:
- FITSHDR object
- list of dictionaries containing 'name','value' and optionally
a 'comment' field; the order is preserved.... | [
"Write",
"the",
"keywords",
"to",
"the",
"header",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L249-L295 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase._update_info | def _update_info(self):
"""
Update metadata for this HDU
"""
try:
self._FITS.movabs_hdu(self._ext+1)
except IOError:
raise RuntimeError("no such hdu")
self._info = self._FITS.get_hdu_info(self._ext+1) | python | def _update_info(self):
"""
Update metadata for this HDU
"""
try:
self._FITS.movabs_hdu(self._ext+1)
except IOError:
raise RuntimeError("no such hdu")
self._info = self._FITS.get_hdu_info(self._ext+1) | [
"def",
"_update_info",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_FITS",
".",
"movabs_hdu",
"(",
"self",
".",
"_ext",
"+",
"1",
")",
"except",
"IOError",
":",
"raise",
"RuntimeError",
"(",
"\"no such hdu\"",
")",
"self",
".",
"_info",
"=",
"self... | Update metadata for this HDU | [
"Update",
"metadata",
"for",
"this",
"HDU"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L322-L331 | train |
esheldon/fitsio | fitsio/hdu/base.py | HDUBase._get_repr_list | def _get_repr_list(self):
"""
Get some representation data common to all HDU types
"""
spacing = ' '*2
text = ['']
text.append("%sfile: %s" % (spacing, self._filename))
text.append("%sextension: %d" % (spacing, self._info['hdunum']-1))
text.append(
... | python | def _get_repr_list(self):
"""
Get some representation data common to all HDU types
"""
spacing = ' '*2
text = ['']
text.append("%sfile: %s" % (spacing, self._filename))
text.append("%sextension: %d" % (spacing, self._info['hdunum']-1))
text.append(
... | [
"def",
"_get_repr_list",
"(",
"self",
")",
":",
"spacing",
"=",
"' '",
"*",
"2",
"text",
"=",
"[",
"''",
"]",
"text",
".",
"append",
"(",
"\"%sfile: %s\"",
"%",
"(",
"spacing",
",",
"self",
".",
"_filename",
")",
")",
"text",
".",
"append",
"(",
"\... | Get some representation data common to all HDU types | [
"Get",
"some",
"representation",
"data",
"common",
"to",
"all",
"HDU",
"types"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/hdu/base.py#L333-L351 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.add_record | def add_record(self, record_in):
"""
Add a new record. Strip quotes from around strings.
This will over-write if the key already exists, except
for COMMENT and HISTORY fields
parameters
-----------
record:
The record, either a dict or a header card ... | python | def add_record(self, record_in):
"""
Add a new record. Strip quotes from around strings.
This will over-write if the key already exists, except
for COMMENT and HISTORY fields
parameters
-----------
record:
The record, either a dict or a header card ... | [
"def",
"add_record",
"(",
"self",
",",
"record_in",
")",
":",
"if",
"(",
"isinstance",
"(",
"record_in",
",",
"dict",
")",
"and",
"'name'",
"in",
"record_in",
"and",
"'value'",
"in",
"record_in",
")",
":",
"record",
"=",
"{",
"}",
"record",
".",
"updat... | Add a new record. Strip quotes from around strings.
This will over-write if the key already exists, except
for COMMENT and HISTORY fields
parameters
-----------
record:
The record, either a dict or a header card string
or a FITSRecord or FITSCard
... | [
"Add",
"a",
"new",
"record",
".",
"Strip",
"quotes",
"from",
"around",
"strings",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L133-L174 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.get_comment | def get_comment(self, item):
"""
Get the comment for the requested entry
"""
key = item.upper()
if key not in self._record_map:
raise KeyError("unknown record: %s" % key)
if 'comment' not in self._record_map[key]:
return None
else:
... | python | def get_comment(self, item):
"""
Get the comment for the requested entry
"""
key = item.upper()
if key not in self._record_map:
raise KeyError("unknown record: %s" % key)
if 'comment' not in self._record_map[key]:
return None
else:
... | [
"def",
"get_comment",
"(",
"self",
",",
"item",
")",
":",
"key",
"=",
"item",
".",
"upper",
"(",
")",
"if",
"key",
"not",
"in",
"self",
".",
"_record_map",
":",
"raise",
"KeyError",
"(",
"\"unknown record: %s\"",
"%",
"key",
")",
"if",
"'comment'",
"no... | Get the comment for the requested entry | [
"Get",
"the",
"comment",
"for",
"the",
"requested",
"entry"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L180-L191 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.delete | def delete(self, name):
"""
Delete the specified entry if it exists.
"""
if isinstance(name, (list, tuple)):
for xx in name:
self.delete(xx)
else:
if name in self._record_map:
del self._record_map[name]
self.... | python | def delete(self, name):
"""
Delete the specified entry if it exists.
"""
if isinstance(name, (list, tuple)):
for xx in name:
self.delete(xx)
else:
if name in self._record_map:
del self._record_map[name]
self.... | [
"def",
"delete",
"(",
"self",
",",
"name",
")",
":",
"if",
"isinstance",
"(",
"name",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"for",
"xx",
"in",
"name",
":",
"self",
".",
"delete",
"(",
"xx",
")",
"else",
":",
"if",
"name",
"in",
"self",... | Delete the specified entry if it exists. | [
"Delete",
"the",
"specified",
"entry",
"if",
"it",
"exists",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L205-L216 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.clean | def clean(self, is_table=False):
"""
Remove reserved keywords from the header.
These are keywords that the fits writer must write in order
to maintain consistency between header and data.
keywords
--------
is_table: bool, optional
Set True if this is... | python | def clean(self, is_table=False):
"""
Remove reserved keywords from the header.
These are keywords that the fits writer must write in order
to maintain consistency between header and data.
keywords
--------
is_table: bool, optional
Set True if this is... | [
"def",
"clean",
"(",
"self",
",",
"is_table",
"=",
"False",
")",
":",
"rmnames",
"=",
"[",
"'SIMPLE'",
",",
"'EXTEND'",
",",
"'XTENSION'",
",",
"'BITPIX'",
",",
"'PCOUNT'",
",",
"'GCOUNT'",
",",
"'THEAP'",
",",
"'EXTNAME'",
",",
"'BLANK'",
",",
"'ZQUANTI... | Remove reserved keywords from the header.
These are keywords that the fits writer must write in order
to maintain consistency between header and data.
keywords
--------
is_table: bool, optional
Set True if this is a table, so extra keywords will be cleaned | [
"Remove",
"reserved",
"keywords",
"from",
"the",
"header",
"."
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L218-L288 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.get | def get(self, item, default_value=None):
"""
Get the requested header entry by keyword name
"""
found, name = self._contains_and_name(item)
if found:
return self._record_map[name]['value']
else:
return default_value | python | def get(self, item, default_value=None):
"""
Get the requested header entry by keyword name
"""
found, name = self._contains_and_name(item)
if found:
return self._record_map[name]['value']
else:
return default_value | [
"def",
"get",
"(",
"self",
",",
"item",
",",
"default_value",
"=",
"None",
")",
":",
"found",
",",
"name",
"=",
"self",
".",
"_contains_and_name",
"(",
"item",
")",
"if",
"found",
":",
"return",
"self",
".",
"_record_map",
"[",
"name",
"]",
"[",
"'va... | Get the requested header entry by keyword name | [
"Get",
"the",
"requested",
"header",
"entry",
"by",
"keyword",
"name"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L290-L299 | train |
esheldon/fitsio | fitsio/header.py | FITSHDR.next | def next(self):
"""
for iteration over the header entries
"""
if self._current < len(self._record_list):
rec = self._record_list[self._current]
key = rec['name']
self._current += 1
return key
else:
raise StopIteration | python | def next(self):
"""
for iteration over the header entries
"""
if self._current < len(self._record_list):
rec = self._record_list[self._current]
key = rec['name']
self._current += 1
return key
else:
raise StopIteration | [
"def",
"next",
"(",
"self",
")",
":",
"if",
"self",
".",
"_current",
"<",
"len",
"(",
"self",
".",
"_record_list",
")",
":",
"rec",
"=",
"self",
".",
"_record_list",
"[",
"self",
".",
"_current",
"]",
"key",
"=",
"rec",
"[",
"'name'",
"]",
"self",
... | for iteration over the header entries | [
"for",
"iteration",
"over",
"the",
"header",
"entries"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L359-L369 | train |
esheldon/fitsio | fitsio/header.py | FITSRecord.set_record | def set_record(self, record, **kw):
"""
check the record is valid and set keys in the dict
parameters
----------
record: string
Dict representing a record or a string representing a FITS header
card
"""
if isstring(record):
ca... | python | def set_record(self, record, **kw):
"""
check the record is valid and set keys in the dict
parameters
----------
record: string
Dict representing a record or a string representing a FITS header
card
"""
if isstring(record):
ca... | [
"def",
"set_record",
"(",
"self",
",",
"record",
",",
"**",
"kw",
")",
":",
"if",
"isstring",
"(",
"record",
")",
":",
"card",
"=",
"FITSCard",
"(",
"record",
")",
"self",
".",
"update",
"(",
"card",
")",
"self",
".",
"verify",
"(",
")",
"else",
... | check the record is valid and set keys in the dict
parameters
----------
record: string
Dict representing a record or a string representing a FITS header
card | [
"check",
"the",
"record",
"is",
"valid",
"and",
"set",
"keys",
"in",
"the",
"dict"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L477-L510 | train |
esheldon/fitsio | fitsio/header.py | FITSCard._check_equals | def _check_equals(self):
"""
check for = in position 8, set attribute _has_equals
"""
card_string = self['card_string']
if len(card_string) < 9:
self._has_equals = False
elif card_string[8] == '=':
self._has_equals = True
else:
... | python | def _check_equals(self):
"""
check for = in position 8, set attribute _has_equals
"""
card_string = self['card_string']
if len(card_string) < 9:
self._has_equals = False
elif card_string[8] == '=':
self._has_equals = True
else:
... | [
"def",
"_check_equals",
"(",
"self",
")",
":",
"card_string",
"=",
"self",
"[",
"'card_string'",
"]",
"if",
"len",
"(",
"card_string",
")",
"<",
"9",
":",
"self",
".",
"_has_equals",
"=",
"False",
"elif",
"card_string",
"[",
"8",
"]",
"==",
"'='",
":",... | check for = in position 8, set attribute _has_equals | [
"check",
"for",
"=",
"in",
"position",
"8",
"set",
"attribute",
"_has_equals"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L588-L598 | train |
esheldon/fitsio | fitsio/header.py | FITSCard._convert_value | def _convert_value(self, value_orig):
"""
things like 6 and 1.25 are converted with ast.literal_value
Things like 'hello' are stripped of quotes
"""
import ast
if value_orig is None:
return value_orig
if value_orig.startswith("'") and value_orig.ends... | python | def _convert_value(self, value_orig):
"""
things like 6 and 1.25 are converted with ast.literal_value
Things like 'hello' are stripped of quotes
"""
import ast
if value_orig is None:
return value_orig
if value_orig.startswith("'") and value_orig.ends... | [
"def",
"_convert_value",
"(",
"self",
",",
"value_orig",
")",
":",
"import",
"ast",
"if",
"value_orig",
"is",
"None",
":",
"return",
"value_orig",
"if",
"value_orig",
".",
"startswith",
"(",
"\"'\"",
")",
"and",
"value_orig",
".",
"endswith",
"(",
"\"'\"",
... | things like 6 and 1.25 are converted with ast.literal_value
Things like 'hello' are stripped of quotes | [
"things",
"like",
"6",
"and",
"1",
".",
"25",
"are",
"converted",
"with",
"ast",
".",
"literal_value"
] | a6f07919f457a282fe240adad9d2c30906b71a15 | https://github.com/esheldon/fitsio/blob/a6f07919f457a282fe240adad9d2c30906b71a15/fitsio/header.py#L641-L669 | train |
sanger-pathogens/ariba | ariba/cluster.py | Cluster._make_reads_for_assembly | def _make_reads_for_assembly(number_of_wanted_reads, total_reads, reads_in1, reads_in2, reads_out1, reads_out2, random_seed=None):
'''Makes fastq files that are random subset of input files. Returns total number of reads in output files.
If the number of wanted reads is >= total reads, then just make... | python | def _make_reads_for_assembly(number_of_wanted_reads, total_reads, reads_in1, reads_in2, reads_out1, reads_out2, random_seed=None):
'''Makes fastq files that are random subset of input files. Returns total number of reads in output files.
If the number of wanted reads is >= total reads, then just make... | [
"def",
"_make_reads_for_assembly",
"(",
"number_of_wanted_reads",
",",
"total_reads",
",",
"reads_in1",
",",
"reads_in2",
",",
"reads_out1",
",",
"reads_out2",
",",
"random_seed",
"=",
"None",
")",
":",
"random",
".",
"seed",
"(",
"random_seed",
")",
"if",
"numb... | Makes fastq files that are random subset of input files. Returns total number of reads in output files.
If the number of wanted reads is >= total reads, then just makes symlinks instead of making
new copies of the input files. | [
"Makes",
"fastq",
"files",
"that",
"are",
"random",
"subset",
"of",
"input",
"files",
".",
"Returns",
"total",
"number",
"of",
"reads",
"in",
"output",
"files",
".",
"If",
"the",
"number",
"of",
"wanted",
"reads",
"is",
">",
"=",
"total",
"reads",
"then"... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/cluster.py#L262-L295 | train |
sanger-pathogens/ariba | ariba/tb.py | load_mutations | def load_mutations(gene_coords, mutation_to_drug_json, variants_txt, upstream_before=100):
'''Load mutations from "mykrobe-style" files. mutation_to_drug_json is json file
of mutation -> list of drugs. variants_txt is text file of variants used my mykrobe's
make probes. gene_coords should be dict of gene co... | python | def load_mutations(gene_coords, mutation_to_drug_json, variants_txt, upstream_before=100):
'''Load mutations from "mykrobe-style" files. mutation_to_drug_json is json file
of mutation -> list of drugs. variants_txt is text file of variants used my mykrobe's
make probes. gene_coords should be dict of gene co... | [
"def",
"load_mutations",
"(",
"gene_coords",
",",
"mutation_to_drug_json",
",",
"variants_txt",
",",
"upstream_before",
"=",
"100",
")",
":",
"with",
"open",
"(",
"mutation_to_drug_json",
")",
"as",
"f",
":",
"drug_data",
"=",
"json",
".",
"load",
"(",
"f",
... | Load mutations from "mykrobe-style" files. mutation_to_drug_json is json file
of mutation -> list of drugs. variants_txt is text file of variants used my mykrobe's
make probes. gene_coords should be dict of gene coords made by the function
genbank_to_gene_coords | [
"Load",
"mutations",
"from",
"mykrobe",
"-",
"style",
"files",
".",
"mutation_to_drug_json",
"is",
"json",
"file",
"of",
"mutation",
"-",
">",
"list",
"of",
"drugs",
".",
"variants_txt",
"is",
"text",
"file",
"of",
"variants",
"used",
"my",
"mykrobe",
"s",
... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/tb.py#L80-L142 | train |
sanger-pathogens/ariba | ariba/tb.py | write_prepareref_fasta_file | def write_prepareref_fasta_file(outfile, gene_coords, genes_need_upstream, genes_non_upstream, upstream_before=100, upstream_after=100):
'''Writes fasta file to be used with -f option of prepareref'''
tmp_dict = {}
fasta_in = os.path.join(data_dir, 'NC_000962.3.fa.gz')
pyfastaq.tasks.file_to_dict(fasta_... | python | def write_prepareref_fasta_file(outfile, gene_coords, genes_need_upstream, genes_non_upstream, upstream_before=100, upstream_after=100):
'''Writes fasta file to be used with -f option of prepareref'''
tmp_dict = {}
fasta_in = os.path.join(data_dir, 'NC_000962.3.fa.gz')
pyfastaq.tasks.file_to_dict(fasta_... | [
"def",
"write_prepareref_fasta_file",
"(",
"outfile",
",",
"gene_coords",
",",
"genes_need_upstream",
",",
"genes_non_upstream",
",",
"upstream_before",
"=",
"100",
",",
"upstream_after",
"=",
"100",
")",
":",
"tmp_dict",
"=",
"{",
"}",
"fasta_in",
"=",
"os",
".... | Writes fasta file to be used with -f option of prepareref | [
"Writes",
"fasta",
"file",
"to",
"be",
"used",
"with",
"-",
"f",
"option",
"of",
"prepareref"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/tb.py#L145-L174 | train |
sanger-pathogens/ariba | ariba/summary_cluster.py | SummaryCluster._get_known_noncoding_het_snp | def _get_known_noncoding_het_snp(data_dict):
'''If ref is coding, return None. If the data dict has a known snp, and
samtools made a call, then return the string ref_name_change and the
% of reads supporting the variant type. If noncoding, but no
samtools call, then return None'... | python | def _get_known_noncoding_het_snp(data_dict):
'''If ref is coding, return None. If the data dict has a known snp, and
samtools made a call, then return the string ref_name_change and the
% of reads supporting the variant type. If noncoding, but no
samtools call, then return None'... | [
"def",
"_get_known_noncoding_het_snp",
"(",
"data_dict",
")",
":",
"if",
"data_dict",
"[",
"'gene'",
"]",
"==",
"'1'",
":",
"return",
"None",
"if",
"data_dict",
"[",
"'known_var'",
"]",
"==",
"'1'",
"and",
"data_dict",
"[",
"'ref_ctg_effect'",
"]",
"==",
"'S... | If ref is coding, return None. If the data dict has a known snp, and
samtools made a call, then return the string ref_name_change and the
% of reads supporting the variant type. If noncoding, but no
samtools call, then return None | [
"If",
"ref",
"is",
"coding",
"return",
"None",
".",
"If",
"the",
"data",
"dict",
"has",
"a",
"known",
"snp",
"and",
"samtools",
"made",
"a",
"call",
"then",
"return",
"the",
"string",
"ref_name_change",
"and",
"the",
"%",
"of",
"reads",
"supporting",
"th... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary_cluster.py#L236-L264 | train |
sanger-pathogens/ariba | ariba/summary_cluster.py | SummaryCluster._has_match | def _has_match(self, assembled_summary):
'''assembled_summary should be output of _to_cluster_summary_assembled'''
if assembled_summary.startswith('yes'):
if self.data[0]['var_only'] == '0' or self._to_cluster_summary_has_known_nonsynonymous(assembled_summary) == 'yes':
retur... | python | def _has_match(self, assembled_summary):
'''assembled_summary should be output of _to_cluster_summary_assembled'''
if assembled_summary.startswith('yes'):
if self.data[0]['var_only'] == '0' or self._to_cluster_summary_has_known_nonsynonymous(assembled_summary) == 'yes':
retur... | [
"def",
"_has_match",
"(",
"self",
",",
"assembled_summary",
")",
":",
"if",
"assembled_summary",
".",
"startswith",
"(",
"'yes'",
")",
":",
"if",
"self",
".",
"data",
"[",
"0",
"]",
"[",
"'var_only'",
"]",
"==",
"'0'",
"or",
"self",
".",
"_to_cluster_sum... | assembled_summary should be output of _to_cluster_summary_assembled | [
"assembled_summary",
"should",
"be",
"output",
"of",
"_to_cluster_summary_assembled"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary_cluster.py#L298-L306 | train |
sanger-pathogens/ariba | ariba/summary_cluster.py | SummaryCluster.has_var_groups | def has_var_groups(self):
'''Returns a set of the variant group ids that this cluster has'''
ids = set()
for d in self.data:
if self._has_known_variant(d) != 'no' and d['var_group'] != '.':
ids.add(d['var_group'])
return ids | python | def has_var_groups(self):
'''Returns a set of the variant group ids that this cluster has'''
ids = set()
for d in self.data:
if self._has_known_variant(d) != 'no' and d['var_group'] != '.':
ids.add(d['var_group'])
return ids | [
"def",
"has_var_groups",
"(",
"self",
")",
":",
"ids",
"=",
"set",
"(",
")",
"for",
"d",
"in",
"self",
".",
"data",
":",
"if",
"self",
".",
"_has_known_variant",
"(",
"d",
")",
"!=",
"'no'",
"and",
"d",
"[",
"'var_group'",
"]",
"!=",
"'.'",
":",
... | Returns a set of the variant group ids that this cluster has | [
"Returns",
"a",
"set",
"of",
"the",
"variant",
"group",
"ids",
"that",
"this",
"cluster",
"has"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary_cluster.py#L309-L315 | train |
sanger-pathogens/ariba | ariba/summary_cluster.py | SummaryCluster.column_summary_data | def column_summary_data(self):
'''Returns a dictionary of column name -> value, for cluster-level results'''
assembled_summary = self._to_cluster_summary_assembled()
pct_id, read_depth = self._pc_id_and_read_depth_of_longest()
columns = {
'assembled': self._to_cluster_summar... | python | def column_summary_data(self):
'''Returns a dictionary of column name -> value, for cluster-level results'''
assembled_summary = self._to_cluster_summary_assembled()
pct_id, read_depth = self._pc_id_and_read_depth_of_longest()
columns = {
'assembled': self._to_cluster_summar... | [
"def",
"column_summary_data",
"(",
"self",
")",
":",
"assembled_summary",
"=",
"self",
".",
"_to_cluster_summary_assembled",
"(",
")",
"pct_id",
",",
"read_depth",
"=",
"self",
".",
"_pc_id_and_read_depth_of_longest",
"(",
")",
"columns",
"=",
"{",
"'assembled'",
... | Returns a dictionary of column name -> value, for cluster-level results | [
"Returns",
"a",
"dictionary",
"of",
"column",
"name",
"-",
">",
"value",
"for",
"cluster",
"-",
"level",
"results"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary_cluster.py#L318-L333 | train |
sanger-pathogens/ariba | ariba/common.py | cat_files | def cat_files(infiles, outfile):
'''Cats all files in list infiles into outfile'''
f_out = pyfastaq.utils.open_file_write(outfile)
for filename in infiles:
if os.path.exists(filename):
f_in = pyfastaq.utils.open_file_read(filename)
for line in f_in:
print(lin... | python | def cat_files(infiles, outfile):
'''Cats all files in list infiles into outfile'''
f_out = pyfastaq.utils.open_file_write(outfile)
for filename in infiles:
if os.path.exists(filename):
f_in = pyfastaq.utils.open_file_read(filename)
for line in f_in:
print(lin... | [
"def",
"cat_files",
"(",
"infiles",
",",
"outfile",
")",
":",
"f_out",
"=",
"pyfastaq",
".",
"utils",
".",
"open_file_write",
"(",
"outfile",
")",
"for",
"filename",
"in",
"infiles",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"filename",
")",
":... | Cats all files in list infiles into outfile | [
"Cats",
"all",
"files",
"in",
"list",
"infiles",
"into",
"outfile"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/common.py#L45-L56 | train |
sanger-pathogens/ariba | ariba/assembly.py | Assembly._check_spades_log_file | def _check_spades_log_file(logfile):
'''SPAdes can fail with a strange error. Stop everything if this happens'''
f = pyfastaq.utils.open_file_read(logfile)
for line in f:
if line.startswith('== Error == system call for:') and line.rstrip().endswith('finished abnormally, err code: -... | python | def _check_spades_log_file(logfile):
'''SPAdes can fail with a strange error. Stop everything if this happens'''
f = pyfastaq.utils.open_file_read(logfile)
for line in f:
if line.startswith('== Error == system call for:') and line.rstrip().endswith('finished abnormally, err code: -... | [
"def",
"_check_spades_log_file",
"(",
"logfile",
")",
":",
"f",
"=",
"pyfastaq",
".",
"utils",
".",
"open_file_read",
"(",
"logfile",
")",
"for",
"line",
"in",
"f",
":",
"if",
"line",
".",
"startswith",
"(",
"'== Error == system call for:'",
")",
"and",
"li... | SPAdes can fail with a strange error. Stop everything if this happens | [
"SPAdes",
"can",
"fail",
"with",
"a",
"strange",
"error",
".",
"Stop",
"everything",
"if",
"this",
"happens"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly.py#L104-L116 | train |
sanger-pathogens/ariba | ariba/assembly.py | Assembly._fix_contig_orientation | def _fix_contig_orientation(contigs_fa, ref_fa, outfile, min_id=90, min_length=20, breaklen=200):
'''Changes orientation of each contig to match the reference, when possible.
Returns a set of names of contigs that had hits in both orientations to the reference'''
if not os.path.exists(contigs... | python | def _fix_contig_orientation(contigs_fa, ref_fa, outfile, min_id=90, min_length=20, breaklen=200):
'''Changes orientation of each contig to match the reference, when possible.
Returns a set of names of contigs that had hits in both orientations to the reference'''
if not os.path.exists(contigs... | [
"def",
"_fix_contig_orientation",
"(",
"contigs_fa",
",",
"ref_fa",
",",
"outfile",
",",
"min_id",
"=",
"90",
",",
"min_length",
"=",
"20",
",",
"breaklen",
"=",
"200",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"contigs_fa",
")",
":... | Changes orientation of each contig to match the reference, when possible.
Returns a set of names of contigs that had hits in both orientations to the reference | [
"Changes",
"orientation",
"of",
"each",
"contig",
"to",
"match",
"the",
"reference",
"when",
"possible",
".",
"Returns",
"a",
"set",
"of",
"names",
"of",
"contigs",
"that",
"had",
"hits",
"in",
"both",
"orientations",
"to",
"the",
"reference"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly.py#L205-L242 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare._parse_nucmer_coords_file | def _parse_nucmer_coords_file(coords_file, ref_name):
'''Input is coords file made by self._run_nucmer. Reference should have one sequence only.
ref_name is name fo the reference sequence, to sanity check the coords file.
Returns dictionary. Key = assembly contig name. Value = list of nucm... | python | def _parse_nucmer_coords_file(coords_file, ref_name):
'''Input is coords file made by self._run_nucmer. Reference should have one sequence only.
ref_name is name fo the reference sequence, to sanity check the coords file.
Returns dictionary. Key = assembly contig name. Value = list of nucm... | [
"def",
"_parse_nucmer_coords_file",
"(",
"coords_file",
",",
"ref_name",
")",
":",
"file_reader",
"=",
"pymummer",
".",
"coords_file",
".",
"reader",
"(",
"coords_file",
")",
"nucmer_hits",
"=",
"{",
"}",
"for",
"hit",
"in",
"file_reader",
":",
"assert",
"hit"... | Input is coords file made by self._run_nucmer. Reference should have one sequence only.
ref_name is name fo the reference sequence, to sanity check the coords file.
Returns dictionary. Key = assembly contig name. Value = list of nucmer hits to that contig | [
"Input",
"is",
"coords",
"file",
"made",
"by",
"self",
".",
"_run_nucmer",
".",
"Reference",
"should",
"have",
"one",
"sequence",
"only",
".",
"ref_name",
"is",
"name",
"fo",
"the",
"reference",
"sequence",
"to",
"sanity",
"check",
"the",
"coords",
"file",
... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L61-L74 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare._nucmer_hits_to_percent_identity | def _nucmer_hits_to_percent_identity(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = percent identity of hits to that contig'''
percent_identities = {}
max_lengths = {}
for contig in nucmer_hits:
... | python | def _nucmer_hits_to_percent_identity(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = percent identity of hits to that contig'''
percent_identities = {}
max_lengths = {}
for contig in nucmer_hits:
... | [
"def",
"_nucmer_hits_to_percent_identity",
"(",
"nucmer_hits",
")",
":",
"percent_identities",
"=",
"{",
"}",
"max_lengths",
"=",
"{",
"}",
"for",
"contig",
"in",
"nucmer_hits",
":",
"max_length",
"=",
"-",
"1",
"percent_identity",
"=",
"0",
"for",
"hit",
"in"... | Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = percent identity of hits to that contig | [
"Input",
"is",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
".",
"Returns",
"dictionary",
".",
"key",
"=",
"contig",
"name",
".",
"Value",
"=",
"percent",
"identity",
"of",
"hits",
"to",
"that",
"contig"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L78-L93 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare._nucmer_hits_to_assembly_coords | def _nucmer_hits_to_assembly_coords(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = list of coords that match
to the reference gene'''
coords = {}
for l in nucmer_hits.values():
for hit in l:
... | python | def _nucmer_hits_to_assembly_coords(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = list of coords that match
to the reference gene'''
coords = {}
for l in nucmer_hits.values():
for hit in l:
... | [
"def",
"_nucmer_hits_to_assembly_coords",
"(",
"nucmer_hits",
")",
":",
"coords",
"=",
"{",
"}",
"for",
"l",
"in",
"nucmer_hits",
".",
"values",
"(",
")",
":",
"for",
"hit",
"in",
"l",
":",
"if",
"hit",
".",
"qry_name",
"not",
"in",
"coords",
":",
"coo... | Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = list of coords that match
to the reference gene | [
"Input",
"is",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
".",
"Returns",
"dictionary",
".",
"key",
"=",
"contig",
"name",
".",
"Value",
"=",
"list",
"of",
"coords",
"that",
"match",
"to",
"the",
"reference",
"gene"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L97-L111 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare.nucmer_hits_to_ref_coords | def nucmer_hits_to_ref_coords(cls, nucmer_hits, contig=None):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. Key = contig name. Value = list of coords in the
reference sequence for that contig.
if contig=contig_name, then just gets the ref coords fr... | python | def nucmer_hits_to_ref_coords(cls, nucmer_hits, contig=None):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. Key = contig name. Value = list of coords in the
reference sequence for that contig.
if contig=contig_name, then just gets the ref coords fr... | [
"def",
"nucmer_hits_to_ref_coords",
"(",
"cls",
",",
"nucmer_hits",
",",
"contig",
"=",
"None",
")",
":",
"coords",
"=",
"[",
"]",
"if",
"contig",
"is",
"None",
":",
"coords",
"=",
"{",
"key",
":",
"[",
"]",
"for",
"key",
"in",
"nucmer_hits",
".",
"k... | Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. Key = contig name. Value = list of coords in the
reference sequence for that contig.
if contig=contig_name, then just gets the ref coords from that contig,
instead of using all the contigs | [
"Input",
"is",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
".",
"Returns",
"dictionary",
".",
"Key",
"=",
"contig",
"name",
".",
"Value",
"=",
"list",
"of",
"coords",
"in",
"the",
"reference",
"sequence",
"for",
"that",
"contig",
".",
"... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L119-L135 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare.nucmer_hits_to_ref_and_qry_coords | def nucmer_hits_to_ref_and_qry_coords(cls, nucmer_hits, contig=None):
'''Same as nucmer_hits_to_ref_coords, except removes containing hits first,
and returns ref and qry coords lists'''
if contig is None:
ctg_coords = {key: [] for key in nucmer_hits.keys()}
else:
... | python | def nucmer_hits_to_ref_and_qry_coords(cls, nucmer_hits, contig=None):
'''Same as nucmer_hits_to_ref_coords, except removes containing hits first,
and returns ref and qry coords lists'''
if contig is None:
ctg_coords = {key: [] for key in nucmer_hits.keys()}
else:
... | [
"def",
"nucmer_hits_to_ref_and_qry_coords",
"(",
"cls",
",",
"nucmer_hits",
",",
"contig",
"=",
"None",
")",
":",
"if",
"contig",
"is",
"None",
":",
"ctg_coords",
"=",
"{",
"key",
":",
"[",
"]",
"for",
"key",
"in",
"nucmer_hits",
".",
"keys",
"(",
")",
... | Same as nucmer_hits_to_ref_coords, except removes containing hits first,
and returns ref and qry coords lists | [
"Same",
"as",
"nucmer_hits_to_ref_coords",
"except",
"removes",
"containing",
"hits",
"first",
"and",
"returns",
"ref",
"and",
"qry",
"coords",
"lists"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L139-L168 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare.ref_cov_per_contig | def ref_cov_per_contig(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = number of bases that
match to the reference sequence.'''
coords = AssemblyCompare.nucmer_hits_to_ref_coords(nucmer_hits)
return {x: p... | python | def ref_cov_per_contig(nucmer_hits):
'''Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = number of bases that
match to the reference sequence.'''
coords = AssemblyCompare.nucmer_hits_to_ref_coords(nucmer_hits)
return {x: p... | [
"def",
"ref_cov_per_contig",
"(",
"nucmer_hits",
")",
":",
"coords",
"=",
"AssemblyCompare",
".",
"nucmer_hits_to_ref_coords",
"(",
"nucmer_hits",
")",
"return",
"{",
"x",
":",
"pyfastaq",
".",
"intervals",
".",
"length_sum_from_list",
"(",
"coords",
"[",
"x",
"... | Input is hits made by self._parse_nucmer_coords_file.
Returns dictionary. key = contig name. Value = number of bases that
match to the reference sequence. | [
"Input",
"is",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
".",
"Returns",
"dictionary",
".",
"key",
"=",
"contig",
"name",
".",
"Value",
"=",
"number",
"of",
"bases",
"that",
"match",
"to",
"the",
"reference",
"sequence",
"."
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L172-L177 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare._ref_covered_by_at_least_one_full_length_contig | def _ref_covered_by_at_least_one_full_length_contig(nucmer_hits, percent_threshold, max_nt_extend):
'''Returns true iff there exists a contig that completely
covers the reference sequence
nucmer_hits = hits made by self._parse_nucmer_coords_file.'''
for l in nucmer_hits.values():
... | python | def _ref_covered_by_at_least_one_full_length_contig(nucmer_hits, percent_threshold, max_nt_extend):
'''Returns true iff there exists a contig that completely
covers the reference sequence
nucmer_hits = hits made by self._parse_nucmer_coords_file.'''
for l in nucmer_hits.values():
... | [
"def",
"_ref_covered_by_at_least_one_full_length_contig",
"(",
"nucmer_hits",
",",
"percent_threshold",
",",
"max_nt_extend",
")",
":",
"for",
"l",
"in",
"nucmer_hits",
".",
"values",
"(",
")",
":",
"for",
"hit",
"in",
"l",
":",
"if",
"(",
"(",
"2",
"*",
"ma... | Returns true iff there exists a contig that completely
covers the reference sequence
nucmer_hits = hits made by self._parse_nucmer_coords_file. | [
"Returns",
"true",
"iff",
"there",
"exists",
"a",
"contig",
"that",
"completely",
"covers",
"the",
"reference",
"sequence",
"nucmer_hits",
"=",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
"."
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L352-L360 | train |
sanger-pathogens/ariba | ariba/assembly_compare.py | AssemblyCompare.nucmer_hit_containing_reference_position | def nucmer_hit_containing_reference_position(nucmer_hits, ref_name, ref_position, qry_name=None):
'''Returns the first nucmer match found that contains the given
reference location. nucmer_hits = hits made by self._parse_nucmer_coords_file.
Returns None if no matching hit found'''
... | python | def nucmer_hit_containing_reference_position(nucmer_hits, ref_name, ref_position, qry_name=None):
'''Returns the first nucmer match found that contains the given
reference location. nucmer_hits = hits made by self._parse_nucmer_coords_file.
Returns None if no matching hit found'''
... | [
"def",
"nucmer_hit_containing_reference_position",
"(",
"nucmer_hits",
",",
"ref_name",
",",
"ref_position",
",",
"qry_name",
"=",
"None",
")",
":",
"for",
"contig_name",
"in",
"nucmer_hits",
":",
"for",
"hit",
"in",
"nucmer_hits",
"[",
"contig_name",
"]",
":",
... | Returns the first nucmer match found that contains the given
reference location. nucmer_hits = hits made by self._parse_nucmer_coords_file.
Returns None if no matching hit found | [
"Returns",
"the",
"first",
"nucmer",
"match",
"found",
"that",
"contains",
"the",
"given",
"reference",
"location",
".",
"nucmer_hits",
"=",
"hits",
"made",
"by",
"self",
".",
"_parse_nucmer_coords_file",
".",
"Returns",
"None",
"if",
"no",
"matching",
"hit",
... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_compare.py#L384-L393 | train |
sanger-pathogens/ariba | ariba/external_progs.py | ExternalProgs._get_exe | def _get_exe(prog):
'''Given a program name, return what we expect its exectuable to be called'''
if prog in prog_to_env_var:
env_var = prog_to_env_var[prog]
if env_var in os.environ:
return os.environ[env_var]
return prog_to_default[prog] | python | def _get_exe(prog):
'''Given a program name, return what we expect its exectuable to be called'''
if prog in prog_to_env_var:
env_var = prog_to_env_var[prog]
if env_var in os.environ:
return os.environ[env_var]
return prog_to_default[prog] | [
"def",
"_get_exe",
"(",
"prog",
")",
":",
"if",
"prog",
"in",
"prog_to_env_var",
":",
"env_var",
"=",
"prog_to_env_var",
"[",
"prog",
"]",
"if",
"env_var",
"in",
"os",
".",
"environ",
":",
"return",
"os",
".",
"environ",
"[",
"env_var",
"]",
"return",
... | Given a program name, return what we expect its exectuable to be called | [
"Given",
"a",
"program",
"name",
"return",
"what",
"we",
"expect",
"its",
"exectuable",
"to",
"be",
"called"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/external_progs.py#L131-L138 | train |
sanger-pathogens/ariba | ariba/cdhit.py | Runner.fake_run | def fake_run(self):
'''Doesn't actually run cd-hit. Instead, puts each input sequence into its own cluster. So it's as if cdhit was run, but didn't cluster anything'''
clusters = {}
used_names = set()
seq_reader = pyfastaq.sequences.file_reader(self.infile)
for seq in seq_reader... | python | def fake_run(self):
'''Doesn't actually run cd-hit. Instead, puts each input sequence into its own cluster. So it's as if cdhit was run, but didn't cluster anything'''
clusters = {}
used_names = set()
seq_reader = pyfastaq.sequences.file_reader(self.infile)
for seq in seq_reader... | [
"def",
"fake_run",
"(",
"self",
")",
":",
"clusters",
"=",
"{",
"}",
"used_names",
"=",
"set",
"(",
")",
"seq_reader",
"=",
"pyfastaq",
".",
"sequences",
".",
"file_reader",
"(",
"self",
".",
"infile",
")",
"for",
"seq",
"in",
"seq_reader",
":",
"if",
... | Doesn't actually run cd-hit. Instead, puts each input sequence into its own cluster. So it's as if cdhit was run, but didn't cluster anything | [
"Doesn",
"t",
"actually",
"run",
"cd",
"-",
"hit",
".",
"Instead",
"puts",
"each",
"input",
"sequence",
"into",
"its",
"own",
"cluster",
".",
"So",
"it",
"s",
"as",
"if",
"cdhit",
"was",
"run",
"but",
"didn",
"t",
"cluster",
"anything"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/cdhit.py#L38-L51 | train |
sanger-pathogens/ariba | ariba/cdhit.py | Runner.run_get_clusters_from_file | def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
'''Instead of running cdhit, gets the clusters info from the input file.'''
if rename_dict is None:
rename_dict = {}
# check that every sequence in the clusters file can be
# found in the ... | python | def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
'''Instead of running cdhit, gets the clusters info from the input file.'''
if rename_dict is None:
rename_dict = {}
# check that every sequence in the clusters file can be
# found in the ... | [
"def",
"run_get_clusters_from_file",
"(",
"self",
",",
"clusters_infile",
",",
"all_ref_seqs",
",",
"rename_dict",
"=",
"None",
")",
":",
"if",
"rename_dict",
"is",
"None",
":",
"rename_dict",
"=",
"{",
"}",
"seq_reader",
"=",
"pyfastaq",
".",
"sequences",
"."... | Instead of running cdhit, gets the clusters info from the input file. | [
"Instead",
"of",
"running",
"cdhit",
"gets",
"the",
"clusters",
"info",
"from",
"the",
"input",
"file",
"."
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/cdhit.py#L86-L109 | train |
sanger-pathogens/ariba | ariba/mapping.py | sam_pair_to_insert | def sam_pair_to_insert(s1, s2):
'''Returns insert size from pair of sam records, as long as their orientation is "innies".
Otherwise returns None.'''
if s1.is_unmapped or s2.is_unmapped or (s1.tid != s2.tid) or (s1.is_reverse == s2.is_reverse):
return None
# If here, reads are both mapped to... | python | def sam_pair_to_insert(s1, s2):
'''Returns insert size from pair of sam records, as long as their orientation is "innies".
Otherwise returns None.'''
if s1.is_unmapped or s2.is_unmapped or (s1.tid != s2.tid) or (s1.is_reverse == s2.is_reverse):
return None
# If here, reads are both mapped to... | [
"def",
"sam_pair_to_insert",
"(",
"s1",
",",
"s2",
")",
":",
"if",
"s1",
".",
"is_unmapped",
"or",
"s2",
".",
"is_unmapped",
"or",
"(",
"s1",
".",
"tid",
"!=",
"s2",
".",
"tid",
")",
"or",
"(",
"s1",
".",
"is_reverse",
"==",
"s2",
".",
"is_reverse"... | Returns insert size from pair of sam records, as long as their orientation is "innies".
Otherwise returns None. | [
"Returns",
"insert",
"size",
"from",
"pair",
"of",
"sam",
"records",
"as",
"long",
"as",
"their",
"orientation",
"is",
"innies",
".",
"Otherwise",
"returns",
"None",
"."
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/mapping.py#L153-L170 | train |
sanger-pathogens/ariba | ariba/scaffold_graph.py | Graph.update_from_sam | def update_from_sam(self, sam, sam_reader):
'''Updates graph info from a pysam.AlignedSegment object'''
if sam.is_unmapped \
or sam.mate_is_unmapped \
or (sam.reference_id == sam.next_reference_id):
return
new_link = link.Link(sam, sam_reader, self.ref_lengths)
... | python | def update_from_sam(self, sam, sam_reader):
'''Updates graph info from a pysam.AlignedSegment object'''
if sam.is_unmapped \
or sam.mate_is_unmapped \
or (sam.reference_id == sam.next_reference_id):
return
new_link = link.Link(sam, sam_reader, self.ref_lengths)
... | [
"def",
"update_from_sam",
"(",
"self",
",",
"sam",
",",
"sam_reader",
")",
":",
"if",
"sam",
".",
"is_unmapped",
"or",
"sam",
".",
"mate_is_unmapped",
"or",
"(",
"sam",
".",
"reference_id",
"==",
"sam",
".",
"next_reference_id",
")",
":",
"return",
"new_li... | Updates graph info from a pysam.AlignedSegment object | [
"Updates",
"graph",
"info",
"from",
"a",
"pysam",
".",
"AlignedSegment",
"object"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/scaffold_graph.py#L13-L32 | train |
sanger-pathogens/ariba | ariba/scaffold_graph.py | Graph._make_graph | def _make_graph(self, max_insert):
'''helper function to construct graph from current state of object'''
if len(self.partial_links) != 0:
raise Error('Error in _make_graph(). Cannot continue because there are partial links')
self.contig_links = {}
for key in self.lin... | python | def _make_graph(self, max_insert):
'''helper function to construct graph from current state of object'''
if len(self.partial_links) != 0:
raise Error('Error in _make_graph(). Cannot continue because there are partial links')
self.contig_links = {}
for key in self.lin... | [
"def",
"_make_graph",
"(",
"self",
",",
"max_insert",
")",
":",
"if",
"len",
"(",
"self",
".",
"partial_links",
")",
"!=",
"0",
":",
"raise",
"Error",
"(",
"'Error in _make_graph(). Cannot continue because there are partial links'",
")",
"self",
".",
"contig_links",... | helper function to construct graph from current state of object | [
"helper",
"function",
"to",
"construct",
"graph",
"from",
"current",
"state",
"of",
"object"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/scaffold_graph.py#L35-L48 | train |
sanger-pathogens/ariba | ariba/bam_parse.py | Parser._sam_to_soft_clipped | def _sam_to_soft_clipped(self, sam):
'''Returns tuple of whether or not the left and right end of the mapped read in the sam record is soft-clipped'''
if sam.is_unmapped:
raise Error('Cannot get soft clip info from an unmapped read')
if sam.cigar is None or len(sam.cigar) == 0:
... | python | def _sam_to_soft_clipped(self, sam):
'''Returns tuple of whether or not the left and right end of the mapped read in the sam record is soft-clipped'''
if sam.is_unmapped:
raise Error('Cannot get soft clip info from an unmapped read')
if sam.cigar is None or len(sam.cigar) == 0:
... | [
"def",
"_sam_to_soft_clipped",
"(",
"self",
",",
"sam",
")",
":",
"if",
"sam",
".",
"is_unmapped",
":",
"raise",
"Error",
"(",
"'Cannot get soft clip info from an unmapped read'",
")",
"if",
"sam",
".",
"cigar",
"is",
"None",
"or",
"len",
"(",
"sam",
".",
"c... | Returns tuple of whether or not the left and right end of the mapped read in the sam record is soft-clipped | [
"Returns",
"tuple",
"of",
"whether",
"or",
"not",
"the",
"left",
"and",
"right",
"end",
"of",
"the",
"mapped",
"read",
"in",
"the",
"sam",
"record",
"is",
"soft",
"-",
"clipped"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/bam_parse.py#L21-L28 | train |
sanger-pathogens/ariba | ariba/report_filter.py | ReportFilter._report_line_to_dict | def _report_line_to_dict(cls, line):
'''Takes report line string as input. Returns a dict of column name -> value in line'''
data = line.split('\t')
if len(data) != len(report.columns):
return None
d = dict(zip(report.columns, data))
for key in report.int_columns:
... | python | def _report_line_to_dict(cls, line):
'''Takes report line string as input. Returns a dict of column name -> value in line'''
data = line.split('\t')
if len(data) != len(report.columns):
return None
d = dict(zip(report.columns, data))
for key in report.int_columns:
... | [
"def",
"_report_line_to_dict",
"(",
"cls",
",",
"line",
")",
":",
"data",
"=",
"line",
".",
"split",
"(",
"'\\t'",
")",
"if",
"len",
"(",
"data",
")",
"!=",
"len",
"(",
"report",
".",
"columns",
")",
":",
"return",
"None",
"d",
"=",
"dict",
"(",
... | Takes report line string as input. Returns a dict of column name -> value in line | [
"Takes",
"report",
"line",
"string",
"as",
"input",
".",
"Returns",
"a",
"dict",
"of",
"column",
"name",
"-",
">",
"value",
"in",
"line"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/report_filter.py#L33-L53 | train |
sanger-pathogens/ariba | ariba/report_filter.py | ReportFilter._dict_to_report_line | def _dict_to_report_line(cls, report_dict):
'''Takes a report_dict as input and returns a report line'''
return '\t'.join([str(report_dict[x]) for x in report.columns]) | python | def _dict_to_report_line(cls, report_dict):
'''Takes a report_dict as input and returns a report line'''
return '\t'.join([str(report_dict[x]) for x in report.columns]) | [
"def",
"_dict_to_report_line",
"(",
"cls",
",",
"report_dict",
")",
":",
"return",
"'\\t'",
".",
"join",
"(",
"[",
"str",
"(",
"report_dict",
"[",
"x",
"]",
")",
"for",
"x",
"in",
"report",
".",
"columns",
"]",
")"
] | Takes a report_dict as input and returns a report line | [
"Takes",
"a",
"report_dict",
"as",
"input",
"and",
"returns",
"a",
"report",
"line"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/report_filter.py#L57-L59 | train |
sanger-pathogens/ariba | ariba/report_filter.py | ReportFilter._load_report | def _load_report(infile):
'''Loads report file into a dictionary. Key=reference name.
Value = list of report lines for that reference'''
report_dict = {}
f = pyfastaq.utils.open_file_read(infile)
first_line = True
for line in f:
line = line.rstrip()
... | python | def _load_report(infile):
'''Loads report file into a dictionary. Key=reference name.
Value = list of report lines for that reference'''
report_dict = {}
f = pyfastaq.utils.open_file_read(infile)
first_line = True
for line in f:
line = line.rstrip()
... | [
"def",
"_load_report",
"(",
"infile",
")",
":",
"report_dict",
"=",
"{",
"}",
"f",
"=",
"pyfastaq",
".",
"utils",
".",
"open_file_read",
"(",
"infile",
")",
"first_line",
"=",
"True",
"for",
"line",
"in",
"f",
":",
"line",
"=",
"line",
".",
"rstrip",
... | Loads report file into a dictionary. Key=reference name.
Value = list of report lines for that reference | [
"Loads",
"report",
"file",
"into",
"a",
"dictionary",
".",
"Key",
"=",
"reference",
"name",
".",
"Value",
"=",
"list",
"of",
"report",
"lines",
"for",
"that",
"reference"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/report_filter.py#L63-L94 | train |
sanger-pathogens/ariba | ariba/report_filter.py | ReportFilter._filter_dicts | def _filter_dicts(self):
'''Filters out all the report_dicts that do not pass the cutoffs. If any ref sequence
loses all of its report_dicts, then it is completely removed.'''
keys_to_remove = set()
for ref_name in self.report:
for ctg_name in self.report[ref_name]:
... | python | def _filter_dicts(self):
'''Filters out all the report_dicts that do not pass the cutoffs. If any ref sequence
loses all of its report_dicts, then it is completely removed.'''
keys_to_remove = set()
for ref_name in self.report:
for ctg_name in self.report[ref_name]:
... | [
"def",
"_filter_dicts",
"(",
"self",
")",
":",
"keys_to_remove",
"=",
"set",
"(",
")",
"for",
"ref_name",
"in",
"self",
".",
"report",
":",
"for",
"ctg_name",
"in",
"self",
".",
"report",
"[",
"ref_name",
"]",
":",
"self",
".",
"report",
"[",
"ref_name... | Filters out all the report_dicts that do not pass the cutoffs. If any ref sequence
loses all of its report_dicts, then it is completely removed. | [
"Filters",
"out",
"all",
"the",
"report_dicts",
"that",
"do",
"not",
"pass",
"the",
"cutoffs",
".",
"If",
"any",
"ref",
"sequence",
"loses",
"all",
"of",
"its",
"report_dicts",
"then",
"it",
"is",
"completely",
"removed",
"."
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/report_filter.py#L167-L186 | train |
sanger-pathogens/ariba | ariba/link.py | Link.merge | def merge(self, other):
'''Merge another link into this one. Expected that each link was created from each mate from a pair. We only know both distances to contig ends when we have read info from both mappings in a BAM file. All other info should be the same.'''
assert self.refnames == other.refnames
... | python | def merge(self, other):
'''Merge another link into this one. Expected that each link was created from each mate from a pair. We only know both distances to contig ends when we have read info from both mappings in a BAM file. All other info should be the same.'''
assert self.refnames == other.refnames
... | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"assert",
"self",
".",
"refnames",
"==",
"other",
".",
"refnames",
"assert",
"self",
".",
"dirs",
"==",
"other",
".",
"dirs",
"assert",
"self",
".",
"lengths",
"==",
"other",
".",
"lengths",
"for",
... | Merge another link into this one. Expected that each link was created from each mate from a pair. We only know both distances to contig ends when we have read info from both mappings in a BAM file. All other info should be the same. | [
"Merge",
"another",
"link",
"into",
"this",
"one",
".",
"Expected",
"that",
"each",
"link",
"was",
"created",
"from",
"each",
"mate",
"from",
"a",
"pair",
".",
"We",
"only",
"know",
"both",
"distances",
"to",
"contig",
"ends",
"when",
"we",
"have",
"read... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/link.py#L80-L93 | train |
sanger-pathogens/ariba | ariba/summary.py | Summary._load_fofn | def _load_fofn(cls, fofn):
'''Returns dictionary of filename -> short name. Value is None
whenever short name is not provided'''
filenames = {}
f = pyfastaq.utils.open_file_read(fofn)
for line in f:
fields = line.rstrip().split()
if len(fields) == 1:
... | python | def _load_fofn(cls, fofn):
'''Returns dictionary of filename -> short name. Value is None
whenever short name is not provided'''
filenames = {}
f = pyfastaq.utils.open_file_read(fofn)
for line in f:
fields = line.rstrip().split()
if len(fields) == 1:
... | [
"def",
"_load_fofn",
"(",
"cls",
",",
"fofn",
")",
":",
"filenames",
"=",
"{",
"}",
"f",
"=",
"pyfastaq",
".",
"utils",
".",
"open_file_read",
"(",
"fofn",
")",
"for",
"line",
"in",
"f",
":",
"fields",
"=",
"line",
".",
"rstrip",
"(",
")",
".",
"... | Returns dictionary of filename -> short name. Value is None
whenever short name is not provided | [
"Returns",
"dictionary",
"of",
"filename",
"-",
">",
"short",
"name",
".",
"Value",
"is",
"None",
"whenever",
"short",
"name",
"is",
"not",
"provided"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary.py#L70-L85 | train |
sanger-pathogens/ariba | ariba/summary.py | Summary._filter_matrix_rows | def _filter_matrix_rows(cls, matrix):
'''matrix = output from _to_matrix'''
indexes_to_keep = []
for i in range(len(matrix)):
keep_row = False
for element in matrix[i]:
if element not in {'NA', 'no'}:
keep_row = True
... | python | def _filter_matrix_rows(cls, matrix):
'''matrix = output from _to_matrix'''
indexes_to_keep = []
for i in range(len(matrix)):
keep_row = False
for element in matrix[i]:
if element not in {'NA', 'no'}:
keep_row = True
... | [
"def",
"_filter_matrix_rows",
"(",
"cls",
",",
"matrix",
")",
":",
"indexes_to_keep",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"matrix",
")",
")",
":",
"keep_row",
"=",
"False",
"for",
"element",
"in",
"matrix",
"[",
"i",
"]",
":",
... | matrix = output from _to_matrix | [
"matrix",
"=",
"output",
"from",
"_to_matrix"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary.py#L223-L236 | train |
sanger-pathogens/ariba | ariba/summary.py | Summary._filter_matrix_columns | def _filter_matrix_columns(cls, matrix, phandango_header, csv_header):
'''phandango_header, csv_header, matrix = output from _to_matrix'''
indexes_to_keep = set()
for row in matrix:
for i in range(len(row)):
if row[i] not in {'NA', 'no'}:
indexes_... | python | def _filter_matrix_columns(cls, matrix, phandango_header, csv_header):
'''phandango_header, csv_header, matrix = output from _to_matrix'''
indexes_to_keep = set()
for row in matrix:
for i in range(len(row)):
if row[i] not in {'NA', 'no'}:
indexes_... | [
"def",
"_filter_matrix_columns",
"(",
"cls",
",",
"matrix",
",",
"phandango_header",
",",
"csv_header",
")",
":",
"indexes_to_keep",
"=",
"set",
"(",
")",
"for",
"row",
"in",
"matrix",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"row",
")",
")",
"... | phandango_header, csv_header, matrix = output from _to_matrix | [
"phandango_header",
"csv_header",
"matrix",
"=",
"output",
"from",
"_to_matrix"
] | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/summary.py#L240-L256 | train |
sanger-pathogens/ariba | ariba/assembly_variants.py | AssemblyVariants._get_remaining_known_ref_variants | def _get_remaining_known_ref_variants(known_ref_variants, used_ref_variants, nucmer_coords):
'''Finds variants where ref has the variant and so does the contig. Which means
that there was no mummer call to flag it up so need to look through the known
ref variants. Also need to check that t... | python | def _get_remaining_known_ref_variants(known_ref_variants, used_ref_variants, nucmer_coords):
'''Finds variants where ref has the variant and so does the contig. Which means
that there was no mummer call to flag it up so need to look through the known
ref variants. Also need to check that t... | [
"def",
"_get_remaining_known_ref_variants",
"(",
"known_ref_variants",
",",
"used_ref_variants",
",",
"nucmer_coords",
")",
":",
"variants",
"=",
"[",
"]",
"for",
"ref_variant_pos",
",",
"ref_variants_set",
"in",
"sorted",
"(",
"known_ref_variants",
".",
"items",
"(",... | Finds variants where ref has the variant and so does the contig. Which means
that there was no mummer call to flag it up so need to look through the known
ref variants. Also need to check that the variant is in a nucmer match to an
assembly contig. | [
"Finds",
"variants",
"where",
"ref",
"has",
"the",
"variant",
"and",
"so",
"does",
"the",
"contig",
".",
"Which",
"means",
"that",
"there",
"was",
"no",
"mummer",
"call",
"to",
"flag",
"it",
"up",
"so",
"need",
"to",
"look",
"through",
"the",
"known",
... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/assembly_variants.py#L232-L260 | train |
sanger-pathogens/ariba | ariba/report.py | _samtools_depths_at_known_snps_all_wild | def _samtools_depths_at_known_snps_all_wild(sequence_meta, contig_name, cluster, variant_list):
'''Input is a known variants, as sequence_metadata object. The
assumption is that both the reference and the assembly have the
variant type, not wild type. The list variant_list should be a list
of p... | python | def _samtools_depths_at_known_snps_all_wild(sequence_meta, contig_name, cluster, variant_list):
'''Input is a known variants, as sequence_metadata object. The
assumption is that both the reference and the assembly have the
variant type, not wild type. The list variant_list should be a list
of p... | [
"def",
"_samtools_depths_at_known_snps_all_wild",
"(",
"sequence_meta",
",",
"contig_name",
",",
"cluster",
",",
"variant_list",
")",
":",
"ref_nuc_range",
"=",
"sequence_meta",
".",
"variant",
".",
"nucleotide_range",
"(",
")",
"if",
"ref_nuc_range",
"is",
"None",
... | Input is a known variants, as sequence_metadata object. The
assumption is that both the reference and the assembly have the
variant type, not wild type. The list variant_list should be a list
of pymummer.variant.Variant objects, only contaning variants to the
relevant query contig | [
"Input",
"is",
"a",
"known",
"variants",
"as",
"sequence_metadata",
"object",
".",
"The",
"assumption",
"is",
"that",
"both",
"the",
"reference",
"and",
"the",
"assembly",
"have",
"the",
"variant",
"type",
"not",
"wild",
"type",
".",
"The",
"list",
"variant_... | 16a0b1916ce0e886bd22550ba2d648542977001b | https://github.com/sanger-pathogens/ariba/blob/16a0b1916ce0e886bd22550ba2d648542977001b/ariba/report.py#L85-L136 | train |
ethereum/eth-abi | eth_abi/utils/string.py | abbr | def abbr(value: Any, limit: int=20) -> str:
"""
Converts a value into its string representation and abbreviates that
representation based on the given length `limit` if necessary.
"""
rep = repr(value)
if len(rep) > limit:
if limit < 3:
raise ValueError('Abbreviation limit m... | python | def abbr(value: Any, limit: int=20) -> str:
"""
Converts a value into its string representation and abbreviates that
representation based on the given length `limit` if necessary.
"""
rep = repr(value)
if len(rep) > limit:
if limit < 3:
raise ValueError('Abbreviation limit m... | [
"def",
"abbr",
"(",
"value",
":",
"Any",
",",
"limit",
":",
"int",
"=",
"20",
")",
"->",
"str",
":",
"rep",
"=",
"repr",
"(",
"value",
")",
"if",
"len",
"(",
"rep",
")",
">",
"limit",
":",
"if",
"limit",
"<",
"3",
":",
"raise",
"ValueError",
... | Converts a value into its string representation and abbreviates that
representation based on the given length `limit` if necessary. | [
"Converts",
"a",
"value",
"into",
"its",
"string",
"representation",
"and",
"abbreviates",
"that",
"representation",
"based",
"on",
"the",
"given",
"length",
"limit",
"if",
"necessary",
"."
] | 0a5cab0bdeae30b77efa667379427581784f1707 | https://github.com/ethereum/eth-abi/blob/0a5cab0bdeae30b77efa667379427581784f1707/eth_abi/utils/string.py#L6-L19 | train |
ethereum/eth-abi | eth_abi/encoding.py | BaseEncoder.invalidate_value | def invalidate_value(
cls,
value: Any,
exc: Type[Exception]=EncodingTypeError,
msg: Optional[str]=None,
) -> None:
"""
Throws a standard exception for when a value is not encodable by an
encoder.
"""
raise exc(
"Value `{rep}` of typ... | python | def invalidate_value(
cls,
value: Any,
exc: Type[Exception]=EncodingTypeError,
msg: Optional[str]=None,
) -> None:
"""
Throws a standard exception for when a value is not encodable by an
encoder.
"""
raise exc(
"Value `{rep}` of typ... | [
"def",
"invalidate_value",
"(",
"cls",
",",
"value",
":",
"Any",
",",
"exc",
":",
"Type",
"[",
"Exception",
"]",
"=",
"EncodingTypeError",
",",
"msg",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"raise",
"exc",
"(",
... | Throws a standard exception for when a value is not encodable by an
encoder. | [
"Throws",
"a",
"standard",
"exception",
"for",
"when",
"a",
"value",
"is",
"not",
"encodable",
"by",
"an",
"encoder",
"."
] | 0a5cab0bdeae30b77efa667379427581784f1707 | https://github.com/ethereum/eth-abi/blob/0a5cab0bdeae30b77efa667379427581784f1707/eth_abi/encoding.py#L78-L95 | train |
ethereum/eth-abi | eth_abi/base.py | parse_tuple_type_str | def parse_tuple_type_str(old_from_type_str):
"""
Used by BaseCoder subclasses as a convenience for implementing the
``from_type_str`` method required by ``ABIRegistry``. Useful if normalizing
then parsing a tuple type string is required in that method.
"""
@functools.wraps(old_from_type_str)
... | python | def parse_tuple_type_str(old_from_type_str):
"""
Used by BaseCoder subclasses as a convenience for implementing the
``from_type_str`` method required by ``ABIRegistry``. Useful if normalizing
then parsing a tuple type string is required in that method.
"""
@functools.wraps(old_from_type_str)
... | [
"def",
"parse_tuple_type_str",
"(",
"old_from_type_str",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"old_from_type_str",
")",
"def",
"new_from_type_str",
"(",
"cls",
",",
"type_str",
",",
"registry",
")",
":",
"normalized_type_str",
"=",
"normalize",
"(",
"t... | Used by BaseCoder subclasses as a convenience for implementing the
``from_type_str`` method required by ``ABIRegistry``. Useful if normalizing
then parsing a tuple type string is required in that method. | [
"Used",
"by",
"BaseCoder",
"subclasses",
"as",
"a",
"convenience",
"for",
"implementing",
"the",
"from_type_str",
"method",
"required",
"by",
"ABIRegistry",
".",
"Useful",
"if",
"normalizing",
"then",
"parsing",
"a",
"tuple",
"type",
"string",
"is",
"required",
... | 0a5cab0bdeae30b77efa667379427581784f1707 | https://github.com/ethereum/eth-abi/blob/0a5cab0bdeae30b77efa667379427581784f1707/eth_abi/base.py#L80-L110 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.