INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Returns a list of block hashes in the account chain starting at ** block ** up to ** count ** | def chain(self, block, count):
"""
Returns a list of block hashes in the account chain starting at
**block** up to **count**
:param block: Block hash to start at
:type block: str
:param count: Number of blocks to return up to
:type count: int
:raises: :... |
Returns a list of pairs of delegator names given ** account ** a representative and its balance | def delegators(self, account):
"""
Returns a list of pairs of delegator names given **account** a
representative and its balance
.. version 8.0 required
:param account: Account to return delegators for
:type account: str
:raises: :py:exc:`nano.rpc.RPCException`... |
Get number of delegators for a specific representative ** account ** | def delegators_count(self, account):
"""
Get number of delegators for a specific representative **account**
.. version 8.0 required
:param account: Account to get number of delegators for
:type account: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.dele... |
Derive deterministic keypair from ** seed ** based on ** index ** | def deterministic_key(self, seed, index):
"""
Derive deterministic keypair from **seed** based on **index**
:param seed: Seed used to get keypair
:type seed: str
:param index: Index of the generated keypair
:type index: int
:raises: :py:exc:`nano.rpc.RPCExcepti... |
Returns a list of pairs of account and block hash representing the head block starting at ** account ** up to ** count ** | def frontiers(self, account, count):
"""
Returns a list of pairs of account and block hash representing the
head block starting at **account** up to **count**
:param account: Account to get frontier blocks for
:type account: str
:param count: Max amount to return
... |
Reports send/ receive information for a chain of blocks | def history(self, hash, count):
"""
Reports send/receive information for a chain of blocks
:param hash: Hash of block to receive history for
:type hash: str
:param count: Max number of blocks to return
:type count: int
:raises: :py:exc:`nano.rpc.RPCException`
... |
Divide a raw amount down by the Mrai ratio. | def mrai_from_raw(self, amount):
"""
Divide a raw amount down by the Mrai ratio.
:param amount: Amount in raw to convert to Mrai
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.mrai_from_raw(amount=1000000000000000000000000000000)
1
... |
Multiply an Mrai amount by the Mrai ratio. | def mrai_to_raw(self, amount):
"""
Multiply an Mrai amount by the Mrai ratio.
:param amount: Amount in Mrai to convert to raw
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.mrai_to_raw(amount=1)
1000000000000000000000000000000
"""
... |
Divide a raw amount down by the krai ratio. | def krai_from_raw(self, amount):
"""
Divide a raw amount down by the krai ratio.
:param amount: Amount in raw to convert to krai
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.krai_from_raw(amount=1000000000000000000000000000)
1
"""
... |
Multiply an krai amount by the krai ratio. | def krai_to_raw(self, amount):
"""
Multiply an krai amount by the krai ratio.
:param amount: Amount in krai to convert to raw
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.krai_to_raw(amount=1)
1000000000000000000000000000
"""
... |
Divide a raw amount down by the rai ratio. | def rai_from_raw(self, amount):
"""
Divide a raw amount down by the rai ratio.
:param amount: Amount in raw to convert to rai
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.rai_from_raw(amount=1000000000000000000000000)
1
"""
... |
Multiply an rai amount by the rai ratio. | def rai_to_raw(self, amount):
"""
Multiply an rai amount by the rai ratio.
:param amount: Amount in rai to convert to raw
:type amount: int
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.rai_to_raw(amount=1)
1000000000000000000000000
"""
amo... |
Derive public key and account number from ** private key ** | def key_expand(self, key):
"""
Derive public key and account number from **private key**
:param key: Private key to generate account and public key of
:type key: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.key_expand(
key="781186FB9EF17DB6E3D105655... |
Tells the node to send a keepalive packet to ** address **: ** port ** | def keepalive(self, address, port):
"""
Tells the node to send a keepalive packet to **address**:**port**
.. enable_control required
:param address: IP address of node to send keepalive packet to
:type address: str
:param port: Port of node to send keepalive packet to
... |
Returns frontier open block change representative block balance last modified timestamp from local database & block count starting at ** account ** up to ** count ** | def ledger(
self,
account,
count=None,
representative=False,
weight=False,
pending=False,
sorting=False,
):
"""
Returns frontier, open block, change representative block, balance,
last modified timestamp from local database & block coun... |
Begin a new payment session. Searches wallet for an account that s marked as available and has a 0 balance. If one is found the account number is returned and is marked as unavailable. If no account is found a new account is created placed in the wallet and returned. | def payment_begin(self, wallet):
"""
Begin a new payment session. Searches wallet for an account that's
marked as available and has a 0 balance. If one is found, the account
number is returned and is marked as unavailable. If no account is
found, a new account is created, placed ... |
Marks all accounts in wallet as available for being used as a payment session. | def payment_init(self, wallet):
"""
Marks all accounts in wallet as available for being used as a payment
session.
:param wallet: Wallet to init payment in
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.payment_init(
... wallet="... |
End a payment session. Marks the account as available for use in a payment session. | def payment_end(self, account, wallet):
"""
End a payment session. Marks the account as available for use in a
payment session.
:param account: Account to mark available
:type account: str
:param wallet: Wallet to end payment session for
:type wallet: str
... |
Wait for payment of ** amount ** to arrive in ** account ** or until ** timeout ** milliseconds have elapsed. | def payment_wait(self, account, amount, timeout):
"""
Wait for payment of **amount** to arrive in **account** or until **timeout**
milliseconds have elapsed.
:param account: Account to wait for payment
:type account: str
:param amount: Amount in raw of funds to wait for... |
Publish ** block ** to the network | def process(self, block):
"""
Publish **block** to the network
:param block: Block to publish
:type block: dict or json
:raises: :py:exc:`nano.rpc.RPCException`
>>> block = {
"account": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000",
... |
Receive pending ** block ** for ** account ** in ** wallet ** | def receive(self, wallet, account, block, work=None):
"""
Receive pending **block** for **account** in **wallet**
.. enable_control required
:param wallet: Wallet of account to receive block for
:type wallet: str
:param account: Account to receive block for
:ty... |
Set ** amount ** as new receive minimum for node until restart | def receive_minimum_set(self, amount):
"""
Set **amount** as new receive minimum for node until restart
.. enable_control required
.. version 8.0 required
:param amount: Amount in raw to set as minimum to receive
:type amount: int
:raises: :py:exc:`nano.rpc.RPC... |
Returns a list of pairs of representative and its voting weight | def representatives(self, count=None, sorting=False):
"""
Returns a list of pairs of representative and its voting weight
:param count: Max amount of representatives to return
:type count: int
:param sorting: If true, sorts by weight
:type sorting: bool
:raises... |
Returns a list of pairs of unchecked synchronizing block hash and its json representation up to ** count ** | def unchecked(self, count=None):
"""
Returns a list of pairs of unchecked synchronizing block hash and its
json representation up to **count**
.. version 8.0 required
:param count: Max amount of unchecked blocks to return
:type count: int
:raises: :py:exc:`nano... |
Retrieves unchecked database keys blocks hashes & a json representations of unchecked pending blocks starting from ** key ** up to ** count ** | def unchecked_keys(self, key=None, count=None):
"""
Retrieves unchecked database keys, blocks hashes & a json
representations of unchecked pending blocks starting from **key** up
to **count**
.. version 8.0 required
:param key: Starting key to return unchecked keys for
... |
Check whether ** account ** is a valid account number | def validate_account_number(self, account):
"""
Check whether **account** is a valid account number
:param account: Account number to check
:type account: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.validate_account_number(
... account="xrb_3e3j5tk... |
Returns the default representative for ** wallet ** | def wallet_representative(self, wallet):
"""
Returns the default representative for **wallet**
:param wallet: Wallet to get default representative account for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_representative(
... wall... |
Sets the default ** representative ** for ** wallet ** | def wallet_representative_set(self, wallet, representative):
"""
Sets the default **representative** for **wallet**
.. enable_control required
:param wallet: Wallet to set default representative account for
:type wallet: str
:param representative: Representative accoun... |
Add an adhoc private key ** key ** to ** wallet ** | def wallet_add(self, wallet, key, work=True):
"""
Add an adhoc private key **key** to **wallet**
.. enable_control required
:param wallet: Wallet to add private key to
:type wallet: str
:param key: Private key to add
:type key: str
:param work: If fals... |
Returns the sum of all accounts balances in ** wallet ** | def wallet_balance_total(self, wallet):
"""
Returns the sum of all accounts balances in **wallet**
:param wallet: Wallet to return sum of balances for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_balance_total(
... wallet="000D1... |
Returns how many rai is owned and how many have not yet been received by all accounts in ** wallet ** | def wallet_balances(self, wallet):
"""
Returns how many rai is owned and how many have not yet been received
by all accounts in **wallet**
:param wallet: Wallet to return balances for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_bal... |
Changes seed for ** wallet ** to ** seed ** | def wallet_change_seed(self, wallet, seed):
"""
Changes seed for **wallet** to **seed**
.. enable_control required
:param wallet: Wallet to change seed for
:type wallet: str
:param seed: Seed to change wallet to
:type seed: str
:raises: :py:exc:`nano.r... |
Check whether ** wallet ** contains ** account ** | def wallet_contains(self, wallet, account):
"""
Check whether **wallet** contains **account**
:param wallet: Wallet to check contains **account**
:type wallet: str
:param account: Account to check exists in **wallet**
:type account: str
:raises: :py:exc:`nano.r... |
Destroys ** wallet ** and all contained accounts | def wallet_destroy(self, wallet):
"""
Destroys **wallet** and all contained accounts
.. enable_control required
:param wallet: Wallet to destroy
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_destroy(
... wallet="000D1BAE... |
Return a json representation of ** wallet ** | def wallet_export(self, wallet):
"""
Return a json representation of **wallet**
:param wallet: Wallet to export
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_export(wallet="000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F")
... |
Returns a list of pairs of account and block hash representing the head block starting for accounts from ** wallet ** | def wallet_frontiers(self, wallet):
"""
Returns a list of pairs of account and block hash representing the
head block starting for accounts from **wallet**
:param wallet: Wallet to return frontiers for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
... |
Returns if a ** wallet ** key is valid | def wallet_key_valid(self, wallet):
"""
Returns if a **wallet** key is valid
:param wallet: Wallet to check key is valid
:type wallet: str
>>> rpc.wallet_key_valid(
... wallet="000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
... )
T... |
Locks a ** wallet ** | def wallet_lock(self, wallet):
"""
Locks a **wallet**
:param wallet: Wallet to lock
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_lock(
... wallet="000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
... )
... |
Checks whether ** wallet ** is locked | def wallet_locked(self, wallet):
"""
Checks whether **wallet** is locked
:param wallet: Wallet to check if locked
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_locked(
... wallet="000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B24... |
Unlocks ** wallet ** using ** password ** | def wallet_unlock(self, wallet, password):
"""
Unlocks **wallet** using **password**
:param wallet: Wallet to unlock
:type wallet: str
:param password: Password to enter
:type password: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.wallet_unlock... |
Rebroadcast blocks for accounts from ** wallet ** starting at frontier down to ** count ** to the network | def wallet_republish(self, wallet, count):
"""
Rebroadcast blocks for accounts from **wallet** starting at frontier
down to **count** to the network
.. enable_control required
.. version 8.0 required
:param wallet: Wallet to rebroadcast blocks for
:type wallet: ... |
Returns a list of pairs of account and work from ** wallet ** | def wallet_work_get(self, wallet):
"""
Returns a list of pairs of account and work from **wallet**
.. enable_control required
.. version 8.0 required
:param wallet: Wallet to return work for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>... |
Changes the password for ** wallet ** to ** password ** | def password_change(self, wallet, password):
"""
Changes the password for **wallet** to **password**
.. enable_control required
:param wallet: Wallet to change password for
:type wallet: str
:param password: Password to set
:type password: str
:raises:... |
Enters the ** password ** in to ** wallet ** | def password_enter(self, wallet, password):
"""
Enters the **password** in to **wallet**
:param wallet: Wallet to enter password for
:type wallet: str
:param password: Password to enter
:type password: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> r... |
Checks whether the password entered for ** wallet ** is valid | def password_valid(self, wallet):
"""
Checks whether the password entered for **wallet** is valid
:param wallet: Wallet to check password for
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.password_valid(
... wallet="000D1BAEC8EC208142C9... |
Returns a list of pairs of peer IPv6: port and its node network version | def peers(self):
"""
Returns a list of pairs of peer IPv6:port and its node network version
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.peers()
{
"[::ffff:172.17.0.1]:32841": 3
}
"""
resp = self.call('peers')
result = {}
... |
Check whether block is pending by ** hash ** | def pending_exists(self, hash):
"""
Check whether block is pending by **hash**
.. version 8.0 required
:param hash: Hash of block to check if pending
:type hash: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.pending_exists(
hash="000D1BAEC8E... |
Stop generating ** work ** for block | def work_cancel(self, hash):
"""
Stop generating **work** for block
.. enable_control required
:param hash: Hash to stop generating work for
:type hash: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.work_cancel(
... hash="718CC2121C3E641059B... |
Generates ** work ** for block | def work_generate(self, hash):
"""
Generates **work** for block
.. enable_control required
:param hash: Hash to start generating **work** for
:type hash: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.work_generate(
... hash="718CC2121C3E6410... |
Retrieves work for ** account ** in ** wallet ** | def work_get(self, wallet, account):
"""
Retrieves work for **account** in **wallet**
.. enable_control required
.. version 8.0 required
:param wallet: Wallet to get account work for
:type wallet: str
:param account: Account to get work for
:type accoun... |
Set ** work ** for ** account ** in ** wallet ** | def work_set(self, wallet, account, work):
"""
Set **work** for **account** in **wallet**
.. enable_control required
.. version 8.0 required
:param wallet: Wallet to set work for account for
:type wallet: str
:param account: Account to set work for
:typ... |
Add specific ** IP address ** and ** port ** as work peer for node until restart | def work_peer_add(self, address, port):
"""
Add specific **IP address** and **port** as work peer for node until
restart
.. enable_control required
.. version 8.0 required
:param address: IP address of work peer to add
:type address: str
:param port: Po... |
Check whether ** work ** is valid for block | def work_validate(self, work, hash):
"""
Check whether **work** is valid for block
:param work: Work to validate
:type work: str
:param hash: Hash of block to validate work for
:type hash: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.work_valid... |
Rebroadcast blocks starting at ** hash ** to the network | def republish(self, hash, count=None, sources=None, destinations=None):
"""
Rebroadcast blocks starting at **hash** to the network
:param hash: Hash of block to start rebroadcasting from
:type hash: str
:param count: Max number of blocks to rebroadcast
:type count: int
... |
Tells the node to look for pending blocks for any account in ** wallet ** | def search_pending(self, wallet):
"""
Tells the node to look for pending blocks for any account in
**wallet**
.. enable_control required
:param wallet: Wallet to search for pending blocks
:type wallet: str
:raises: :py:exc:`nano.rpc.RPCException`
>>> r... |
Send ** amount ** from ** source ** in ** wallet ** to ** destination ** | def send(self, wallet, source, destination, amount, work=None, id=None):
"""
Send **amount** from **source** in **wallet** to **destination**
.. enable_control required
:param wallet: Wallet of account used to send funds
:type wallet: str
:param source: Account to send... |
Returns the node s RPC version | def version(self):
"""
Returns the node's RPC version
:raises: :py:exc:`nano.rpc.RPCException`
>>> rpc.version()
{
"rpc_version": 1,
"store_version": 10,
"node_vendor": "RaiBlocks 9.0"
}
"""
resp = self.call('version... |
Set API token by authenticating via username/ password. | def authenticate(self, retries=3):
"""Set API token by authenticating via username/password.
:param retries: Number of authentication attempts to make before giving up as an int.
:return: Learned API token
:rtype: string
"""
username = self.username or self._getuser(sel... |
Get user email from github. | def _extract_email(gh):
"""Get user email from github."""
return next(
(x.email for x in gh.emails() if x.verified and x.primary), None) |
Retrieve remote account information used to find local user. | def account_info(remote, resp):
"""Retrieve remote account information used to find local user.
It returns a dictionary with the following structure:
.. code-block:: python
{
'user': {
'email': '...',
'profile': {
'username': '...',
... |
Perform additional setup after user have been logged in. | def account_setup(remote, token, resp):
"""Perform additional setup after user have been logged in.
:param remote: The remote application.
:param token: The token value.
:param resp: The response.
"""
gh = github3.login(token=resp['access_token'])
with db.session.begin_nested():
me ... |
Authorized callback handler for GitHub. | def authorized(resp, remote):
"""Authorized callback handler for GitHub.
:param resp: The response.
:param remote: The remote application.
"""
if resp and 'error' in resp:
if resp['error'] == 'bad_verification_code':
# See https://developer.github.com/v3/oauth/#bad-verification-... |
Construct an equal to ( = ) filter. | def eq(self, value):
"""Construct an equal to (``=``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '='
self.negate_op = '!='
self.value = self._value(value)
return se... |
Construct a not equal to ( ! = ) filter. | def ne(self, value):
"""Construct a not equal to (``!=``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '!='
self.negate_op = '='
self.value = self._value(value)
retur... |
Construct a greater than ( > ) filter. | def gt(self, value):
"""Construct a greater than (``>``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '>'
self.negate_op = '<='
self.value = self._value(value)
return... |
Construct a greater than or equal to ( > = ) filter. | def ge(self, value):
"""Construct a greater than or equal to (``>=``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '>='
self.negate_op = '<'
self.value = self._value(value)
... |
Construct a less than ( < ) filter. | def lt(self, value):
"""Construct a less than (``<``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '<'
self.negate_op = '>='
self.value = self._value(value)
return se... |
Construct a less than or equal to ( < = ) filter. | def le(self, value):
"""Construct a less than or equal to (``<=``) filter.
:param value: Filter value
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '<='
self.negate_op = '>'
self.value = self._value(value)
... |
Construct a regexp match ( ~ ) filter. Combine with not_ method to construct a negative regexp match ( !~ ) filter. | def match(self, value, ignorecase=False):
"""Construct a regexp match (``~``) filter. Combine with ``not_`` method to construct a negative regexp match (``!~``) filter.
:param value: Filter value
:param ignorecase: If bool `True`, make match case insensitive (``~*``, ``!~*``)
:return: ... |
Construct an array contains ( @ > ) filter. | def contains(self, *args):
"""Construct an array contains (``@>``) filter.
:param args: Filter values
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '@>'
self.negate_op = None
self.value = self._array_value(args... |
Construct an array contained by ( <@ ) filter. | def contained_by(self, *args):
"""Construct an array contained by (``<@``) filter.
:param args: Filter values
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '<@'
self.negate_op = None
self.value = self._array_va... |
Construct an array overlaps ( && ) filter. | def overlaps(self, *args):
"""Construct an array overlaps (``&&``) filter.
:param args: Filter values
:return: :class:`filters.Field <filters.Field>` object
:rtype: filters.Field
"""
self.op = '&&'
self.negate_op = None
self.value = self._array_value(args... |
Get all unique sequences from reads spanning a variant locus. This will include partial sequences due to reads starting in the middle of the sequence around around a variant. | def initial_variant_sequences_from_reads(
variant_reads,
max_nucleotides_before_variant=None,
max_nucleotides_after_variant=None):
"""
Get all unique sequences from reads spanning a variant locus. This will
include partial sequences due to reads starting in the middle of the
sequ... |
Trim VariantSequences to desired coverage and then combine any subsequences which get generated. | def trim_variant_sequences(variant_sequences, min_variant_sequence_coverage):
"""
Trim VariantSequences to desired coverage and then combine any
subsequences which get generated.
"""
n_total = len(variant_sequences)
trimmed_variant_sequences = [
variant_sequence.trim_by_coverage(min_vari... |
Drop variant sequences which are shorter than request or don t have enough supporting reads. | def filter_variant_sequences(
variant_sequences,
preferred_sequence_length,
min_variant_sequence_coverage=MIN_VARIANT_SEQUENCE_COVERAGE,):
"""
Drop variant sequences which are shorter than request or don't have
enough supporting reads.
"""
variant_sequences = trim_variant_seq... |
Collapse variant - supporting RNA reads into consensus sequences of approximately the preferred length ( may differ at the ends of transcripts ) filter consensus sequences by length and number of supporting RNA reads. | def reads_to_variant_sequences(
variant,
reads,
preferred_sequence_length,
min_alt_rna_reads=MIN_ALT_RNA_READS,
min_variant_sequence_coverage=MIN_VARIANT_SEQUENCE_COVERAGE,
variant_sequence_assembly=VARIANT_SEQUENCE_ASSEMBLY):
"""
Collapse variant-supporting RNA r... |
For each variant collect all possible sequence contexts around the variant which are spanned by at least min_reads. | def reads_generator_to_sequences_generator(
variant_and_reads_generator,
min_alt_rna_reads=MIN_ALT_RNA_READS,
min_variant_sequence_coverage=MIN_VARIANT_SEQUENCE_COVERAGE,
preferred_sequence_length=VARIANT_SEQUENCE_LENGTH,
variant_sequence_assembly=VARIANT_SEQUENCE_ASSEMBLY):
... |
Creates a dataframe from a generator which yields ( Variant [ VariantSequence ] ) pairs. | def variant_sequences_generator_to_dataframe(variant_sequences_generator):
"""
Creates a dataframe from a generator which yields
(Variant, [VariantSequence]) pairs.
Returns pandas.DataFrame
"""
# TODO: Change VariantSequence.alt to VariantSequence.alt_nucleotides
# or something else that do... |
Is the other VariantSequence a subsequence of this one? | def contains(self, other):
"""
Is the other VariantSequence a subsequence of this one?
The two sequences must agree on the alt nucleotides, the prefix of the
longer must contain the prefix of the shorter, and the suffix of the
longer must contain the suffix of the shorter.
... |
Does this VariantSequence overlap another on the left side? | def left_overlaps(self, other, min_overlap_size=1):
"""
Does this VariantSequence overlap another on the left side?
"""
if self.alt != other.alt:
# allele must match!
return False
if len(other.prefix) > len(self.prefix):
# only consider strin... |
Create another VariantSequence with more supporting reads. | def add_reads(self, reads):
"""
Create another VariantSequence with more supporting reads.
"""
if len(reads) == 0:
return self
new_reads = self.reads.union(reads)
if len(new_reads) > len(self.reads):
return VariantSequence(
prefix=s... |
If this sequence is the prefix of another sequence combine them into a single VariantSequence object. If the other sequence is contained in this one then add its reads to this VariantSequence. Also tries to flip the order ( e. g. this sequence is a suffix or this sequence is a subsequence ). If sequences can t be combi... | def combine(self, other_sequence):
"""
If this sequence is the prefix of another sequence, combine
them into a single VariantSequence object. If the other sequence
is contained in this one, then add its reads to this VariantSequence.
Also tries to flip the order (e.g. this sequen... |
When we combine prefix + alt + suffix into a single string what are is base - 0 index interval which gets us back the alt sequence? First returned index is inclusive the second is exclusive. | def variant_indices(self):
"""
When we combine prefix + alt + suffix into a single string,
what are is base-0 index interval which gets us back the alt
sequence? First returned index is inclusive, the second is exclusive.
"""
variant_start_index = len(self.prefix)
... |
Returns NumPy array indicating number of reads covering each nucleotides of this sequence. | def coverage(self):
"""
Returns NumPy array indicating number of reads covering each
nucleotides of this sequence.
"""
variant_start_index, variant_end_index = self.variant_indices()
n_nucleotides = len(self)
coverage_array = np.zeros(n_nucleotides, dtype="int32")... |
Given the min number of reads overlapping each nucleotide of a variant sequence trim this sequence by getting rid of positions which are overlapped by fewer reads than specified. | def trim_by_coverage(self, min_reads):
"""
Given the min number of reads overlapping each nucleotide of
a variant sequence, trim this sequence by getting rid of positions
which are overlapped by fewer reads than specified.
"""
read_count_array = self.coverage()
lo... |
Load test data fixture. | def records():
"""Load test data fixture."""
with db.session.begin_nested():
for idx in range(20):
# create the record
id_ = uuid.uuid4()
Record.create({
'title': 'LHC experiment {}'.format(idx),
'description': 'Data from experiment {}.... |
Drop all occurrences of N from prefix and suffix nucleotide strings by trimming. | def trim_N_nucleotides(prefix, suffix):
"""
Drop all occurrences of 'N' from prefix and suffix nucleotide strings
by trimming.
"""
if 'N' in prefix:
# trim prefix to exclude all occurrences of N
rightmost_index = prefix.rfind('N')
logger.debug(
"Trimming %d nucleo... |
Depending on how we extract data from pysam we may end up with either a string or a byte array of nucleotides. For consistency and simplicity we want to only use strings in the rest of our code. | def convert_from_bytes_if_necessary(prefix, suffix):
"""
Depending on how we extract data from pysam we may end up with either
a string or a byte array of nucleotides. For consistency and simplicity,
we want to only use strings in the rest of our code.
"""
if isinstance(prefix, bytes):
p... |
Given a SAM/ BAM file and a collection of variants generates a sequence of variants paired with reads which support each variant. | def reads_supporting_variants(variants, samfile, **kwargs):
"""
Given a SAM/BAM file and a collection of variants, generates a sequence
of variants paired with reads which support each variant.
"""
for variant, allele_reads in reads_overlapping_variants(
variants=variants,
sa... |
Validate operation type. | def publish(self, data, **kwargs):
"""Validate operation type."""
assert data.get('op') in {'index', 'create', 'delete', 'update'}
return super(Producer, self).publish(data, **kwargs) |
Index a record. | def index(self, record):
"""Index a record.
The caller is responsible for ensuring that the record has already been
committed to the database. If a newer version of a record has already
been indexed then the provided record will not be indexed. This
behavior can be controlled by... |
Delete a record. | def delete(self, record):
"""Delete a record.
:param record: Record instance.
"""
index, doc_type = self.record_to_index(record)
return self.client.delete(
id=str(record.id),
index=index,
doc_type=doc_type,
) |
Process bulk indexing queue. | def process_bulk_queue(self, es_bulk_kwargs=None):
"""Process bulk indexing queue.
:param dict es_bulk_kwargs: Passed to
:func:`elasticsearch:elasticsearch.helpers.bulk`.
"""
with current_celery_app.pool.acquire(block=True) as conn:
consumer = Consumer(
... |
Context manager that yields an instance of Producer. | def create_producer(self):
"""Context manager that yields an instance of ``Producer``."""
with current_celery_app.pool.acquire(block=True) as conn:
yield Producer(
conn,
exchange=self.mq_exchange,
routing_key=self.mq_routing_key,
... |
Index record in Elasticsearch asynchronously. | def _bulk_op(self, record_id_iterator, op_type, index=None, doc_type=None):
"""Index record in Elasticsearch asynchronously.
:param record_id_iterator: Iterator that yields record UUIDs.
:param op_type: Indexing operation (one of ``index``, ``create``,
``delete`` or ``update``).
... |
Iterate bulk actions. | def _actionsiter(self, message_iterator):
"""Iterate bulk actions.
:param message_iterator: Iterator yielding messages from a queue.
"""
for message in message_iterator:
payload = message.decode()
try:
if payload['op'] == 'delete':
... |
Bulk delete action. | def _delete_action(self, payload):
"""Bulk delete action.
:param payload: Decoded message body.
:returns: Dictionary defining an Elasticsearch bulk 'delete' action.
"""
index, doc_type = payload.get('index'), payload.get('doc_type')
if not (index and doc_type):
... |
Bulk index action. | def _index_action(self, payload):
"""Bulk index action.
:param payload: Decoded message body.
:returns: Dictionary defining an Elasticsearch bulk 'index' action.
"""
record = Record.get_record(payload['id'])
index, doc_type = self.record_to_index(record)
return ... |
Prepare record data for indexing. | def _prepare_record(record, index, doc_type):
"""Prepare record data for indexing.
:param record: The record to prepare.
:param index: The Elasticsearch index.
:param doc_type: The Elasticsearch document type.
:returns: The record metadata.
"""
if current_app.con... |
Returns a list of merged VariantSequence objects and True if any were successfully merged. | def greedy_merge_helper(
variant_sequences,
min_overlap_size=MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE):
"""
Returns a list of merged VariantSequence objects, and True if any
were successfully merged.
"""
merged_variant_sequences = {}
merged_any = False
# here we'll keep tr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.