Package Bio :: Package SearchIO :: Package _model :: Module hit :: Class Hit
[hide private]
[frames] | no frames]

Class Hit

source code

             object --+    
                      |    
_base._BaseSearchObject --+
                          |
                         Hit

Class representing a single database hit of a search result.

Hit objects are the second-level container in the SearchIO module. They
are the objects contained within a QueryResult (see QueryResult). They
themselves are container for HSP objects and will contain at least one
HSP.

To have a quick look at a Hit and its contents, invoke `print` on it:

>>> from Bio import SearchIO
>>> qresult = next(SearchIO.parse('Blast/mirna.xml', 'blast-xml'))
>>> hit = qresult[3]
>>> print(hit)
Query: 33211
       mir_1
  Hit: gi|301171322|ref|NR_035857.1| (86)
       Pan troglodytes microRNA mir-520c (MIR520C), microRNA
 HSPs: ----  --------  ---------  ------  ---------------  ---------------------
          #   E-value  Bit score    Span      Query range              Hit range
       ----  --------  ---------  ------  ---------------  ---------------------
          0   8.9e-20     100.47      60           [1:61]                [13:73]
          1   3.3e-06      55.39      60           [0:60]                [13:73]

You can invoke `len` on a Hit object to see how many HSP objects it contains:

>>> len(hit)
2

Hit objects behave very similar to Python lists. You can retrieve the HSP
object inside a Hit using the HSP's integer index. Hit objects can also be
sliced, which will return a new Hit objects containing only the sliced HSPs:

# HSP items inside the Hit can be retrieved using its integer index
>>> hit[0]
HSP(hit_id='gi|301171322|ref|NR_035857.1|', query_id='33211', 1 fragments)

# slicing returns a new Hit
>>> hit
Hit(id='gi|301171322|ref|NR_035857.1|', query_id='33211', 2 hsps)
>>> hit[:1]
Hit(id='gi|301171322|ref|NR_035857.1|', query_id='33211', 1 hsps)
>>> print(hit[1:])
Query: 33211
       mir_1
  Hit: gi|301171322|ref|NR_035857.1| (86)
       Pan troglodytes microRNA mir-520c (MIR520C), microRNA
 HSPs: ----  --------  ---------  ------  ---------------  ---------------------
          #   E-value  Bit score    Span      Query range              Hit range
       ----  --------  ---------  ------  ---------------  ---------------------
          0   3.3e-06      55.39      60           [0:60]                [13:73]

Hit objects provide `filter` and `map` methods, which are analogous to
Python's built-in `filter` and `map` except that they return a new Hit
object instead of a list.

Here is an example of using `filter` to select for HSPs whose e-value is
less than 1e-10:

>>> evalue_filter = lambda hsp: hsp.evalue < 1e-10
>>> filtered_hit = hit.filter(evalue_filter)
>>> len(hit)
2
>>> len(filtered_hit)
1
>>> print(filtered_hit)
Query: 33211
       mir_1
  Hit: gi|301171322|ref|NR_035857.1| (86)
       Pan troglodytes microRNA mir-520c (MIR520C), microRNA
 HSPs: ----  --------  ---------  ------  ---------------  ---------------------
          #   E-value  Bit score    Span      Query range              Hit range
       ----  --------  ---------  ------  ---------------  ---------------------
          0   8.9e-20     100.47      60           [1:61]                [13:73]

There are also other methods which are counterparts of Python lists' methods
with the same names: `append`, `index`, `pop`, and `sort`. Consult their
respective documentations for more details and examples of their usage.

Instance Methods [hide private]
 
__init__(self, hsps=[], id=None, query_id=None)
Initializes a Hit object.
source code
 
__repr__(self)
repr(x)
source code
 
__iter__(self) source code
 
__len__(self) source code
 
__bool__(self) source code
 
__nonzero__(self) source code
 
__contains__(self, hsp) source code
 
__str__(self)
str(x)
source code
 
__getitem__(self, idx) source code
 
__setitem__(self, idx, hsps) source code
 
__delitem__(self, idx) source code
 
_validate_hsp(self, hsp)
Validates an HSP object.
source code
 
append(self, hsp)
Adds a HSP object to the end of Hit.
source code
 
filter(self, func=None)
Creates a new Hit object whose HSP objects pass the filter function.
source code
 
index(self, hsp)
Returns the index of a given HSP object, zero-based.
source code
 
map(self, func=None)
Creates a new Hit object, mapping the given function to its HSPs.
source code
 
pop(self, index=-1)
Removes and returns the HSP object at the specified index.
source code
 
sort(self, key=None, reverse=False, in_place=True)
Sorts the HSP objects.
source code

Inherited from _base._BaseSearchObject (private): _transfer_attrs

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  _NON_STICKY_ATTRS = ('_items')
Properties [hide private]
  description
Hit description
  query_description
Description of the query that produced the hit
  id
Hit ID string.
  query_id
ID string of the query that produced the hit
  hsps
HSP objects contained in the Hit
  fragments
HSPFragment objects contained in the Hit

Inherited from object: __class__

Method Details [hide private]

__init__(self, hsps=[], id=None, query_id=None)
(Constructor)

source code 
Initializes a Hit object.

Arguments:
hsps -- List containing HSP objects.
id -- String of the Hit ID
query_id -- String of the Hit's query ID

If multiple HSP objects are used for initialization, they must all
have the same `query_id`, `query_description`, `hit_id`, and
`hit_description` properties.

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 
repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 
str(x)

Overrides: object.__str__
(inherited documentation)

_validate_hsp(self, hsp)

source code 
Validates an HSP object.

Valid HSP objects have the same hit_id as the Hit object ID and the
same query_id as the Hit object's query_id.

append(self, hsp)

source code 
Adds a HSP object to the end of Hit.

Parameters
hsp -- HSP object to append.

Any HSP object appended must have the same `hit_id` property as the
Hit object's `id` property and the same `query_id` property as the
Hit object's `query_id` property.

filter(self, func=None)

source code 
Creates a new Hit object whose HSP objects pass the filter
function.

Arguments:
func -- Callback function that accepts a HSP object as its parameter,
        does a boolean check, and returns True or False.

`filter` is analogous to Python's built-in `filter` function, except
that instead of returning a list it returns a `Hit` object. Here is an
example of using `filter` to select for HSPs having bitscores bigger
than 60:

>>> from Bio import SearchIO
>>> qresult = next(SearchIO.parse('Blast/mirna.xml', 'blast-xml'))
>>> hit = qresult[3]
>>> evalue_filter = lambda hsp: hsp.bitscore > 60
>>> filtered_hit = hit.filter(evalue_filter)
>>> len(hit)
2
>>> len(filtered_hit)
1
>>> print(filtered_hit)
Query: 33211
       mir_1
  Hit: gi|301171322|ref|NR_035857.1| (86)
       Pan troglodytes microRNA mir-520c (MIR520C), microRNA
 HSPs: ----  --------  ---------  ------  ---------------  ---------------------
          #   E-value  Bit score    Span      Query range              Hit range
       ----  --------  ---------  ------  ---------------  ---------------------
          0   8.9e-20     100.47      60           [1:61]                [13:73]

index(self, hsp)

source code 
Returns the index of a given HSP object, zero-based.

Arguments:
hsp -- HSP object to be looked up.

map(self, func=None)

source code 
Creates a new Hit object, mapping the given function to its HSPs.

Arguments:
func -- Callback function that accepts a HSP object as its parameter and
        also returns a HSP object.

`map` is analogous to Python's built-in `map` function. It is applied to
all HSPs contained in the Hit object and returns a new Hit object.

pop(self, index=-1)

source code 
Removes and returns the HSP object at the specified index.

Arguments:
index -- Integer denoting the index of the HSP object to remove.

sort(self, key=None, reverse=False, in_place=True)

source code 
Sorts the HSP objects.

Arguments:
key -- Function used to sort the HSP objects.
reverse -- Boolean, whether to reverse the sorting or not.
in_place -- Boolean, whether to perform sorting in place (in the same
            object) or not (creating a new object).

`sort` defaults to sorting in-place, to mimick Python's `list.sort`
method. If you set the `in_place` argument to False, it will treat
return a new, sorted Hit object and keep the initial one unsorted


Property Details [hide private]

description

Hit description

Get Method:
unreachable.getter(self)
Set Method:
unreachable.setter(self, value)

query_description

Description of the query that produced the hit

Get Method:
unreachable.getter(self)
Set Method:
unreachable.setter(self, value)

id

Hit ID string.

Get Method:
unreachable.getter(self)
Set Method:
unreachable.setter(self, value)

query_id

ID string of the query that produced the hit

Get Method:
unreachable.getter(self)
Set Method:
unreachable.setter(self, value)

hsps

HSP objects contained in the Hit

Get Method:
unreachable.getter(self)

fragments

HSPFragment objects contained in the Hit

Get Method:
unreachable.fragments(self) - HSPFragment objects contained in the Hit