Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Keywords
Repository
A python library for accessing 2bit files
Basic Info
- Host: GitHub
- Owner: deeptools
- License: mit
- Language: C
- Default Branch: master
- Size: 59.6 KB
Statistics
- Stars: 20
- Watchers: 3
- Forks: 9
- Open Issues: 0
- Releases: 5
Topics
Metadata Files
README.md
py2bit
A python extension, written in C, for quick access to 2bit files. The extension uses lib2bit for file access.
Table of Contents
Installation
You can install the extension directly from github with:
pip install git+https://github.com/dpryan79/py2bit
Usage
Basic usage is as follows:
Load the extension
>>> import py2bit
Open a 2bit file
This will work if your working directory is the py2bit source code directory.
>>> tb = py2bit.open("test/foo.2bit")
Note that if you would like to include information about soft-masked bases, you need to manually specify that:
>>> tb = py2bit.open("test/foo.2bit", True)
Access the list of chromosomes and the lengths
TwoBit objects contain a dictionary holding the chromosome/contig lengths, which can be accessed with the chroms() method.
>>> tb.chroms()
{'chr1': 150L, 'chr2': 100L}
You can directly access a particular chromosome by specifying its name.
>>> tb.chroms('chr1')
150L
The lengths are stored as a "long" integer type, which is why there's an L suffix. If you specify a nonexistent chromosome then nothing is output.
>>> tb.chroms("foo")
>>>
Print file information
The following information about and contained within a 2bit file can be accessed with the info() method:
- file size, in bytes (
file size) - number of chromosomes/contigs (
nChroms) - total sequence length, in bases (
sequence length) - total number of hard-masked (N) bases (
hard-masked length) - total number of soft-masked (lower case) bases(
soft-masked length).
Note that soft-masked length will only be present if open("file.2bit", True) is used, since handling soft-masking increases memory requirements and decreases perfomance.
>>> tb.info()
{'file size': 161, 'nChroms': 2, 'sequence length': 250, 'hard-masked length': 150, 'soft-masked length': 8}
Fetch a sequence
The sequence of a full or partial chromosome/contig can be fetched with the sequence() method.
>>> tb.sequence("chr1")
'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNACGTACGTACGTagctagctGATCGATCGTAGCTAGCTAGCTAGCTGATCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN'
By default, the whole chromosome/contig is returned. A specific range can also be requested.
>>> tb.sequence("chr1", 24, 74)
NNNNNNNNNNNNNNNNNNNNNNNNNNACGTACGTACGTagctagctGATC
The first number is the (0-based) position on the chromosome/contig where the sequence should begin. The second number is the (1-based) position on the chromosome where the sequence should end.
If it was requested during file opening that soft-masking information be stored, then lower case bases may be present. If a nonexistent chromosome/contig is specified then a runtime error occurs.
Fetch per-base statistics
It's often required to compute the percentage of 1 or more bases in a chromosome. This can be done with the bases() method.
>>> tb.bases("chr1")
{'A': 0.08, 'C': 0.08, 'T': 0.08666666666666667, 'G': 0.08666666666666667}
This returns a dictionary with bases as keys and the fraction of the sequence composed of them as values. Note that this will not sum to 1 if there are any hard-masked bases (the chromosome is 2/3 N in this case). One can also request this information over a particular region.
>>> tb.bases("chr1", 24, 74)
{'A': 0.12, 'C': 0.12, 'T': 0.12, 'G': 0.12}
The start and end position are as with the sequence() method described above.
If integer counts are preferred, then they can instead be returned.
>>> tb.bases("chr1", 24, 74, False)
{'A': 6, 'C': 6, 'T': 6, 'G': 6}
Fetch masked blocks
There are two kinds of masking blocks that can be present in 2bit files: hard-masked and soft-masked. Hard-masked blocks are stretches of NNNN, as are commonly found near telomeres and centromeres. Soft-masked blocks are runs of lowercase A/C/T/G, typically indicating repeat elements or low-complexity stretches. In can sometimes be useful to query this information from 2bit files:
>>> tb.hardMaskedBlocks("chr1")
[(0, 50), (100, 150)]
In this (small) example, there are two stretches of hard-masked sequence, from 0 to 50 and again from 100 to 150 (see the note below about coordinates). If you would instead like to query all blocks overlapping with a specific region, you can specify the region bounds:
>>> tb.hardMaskedBlocks("chr1", 75, 101)
[(100, 150)]
If there are no overlapping regions, then an empty list is returned:
>>> tb.hardMaskedBlocks("chr1", 75, 100)
[]
Instead of hardMaskedBlocks(), one can use softMaskedBlocks() in an identical manner:
>>> tb = py2bit.open("foo.2bit", storeMasked=True)
>>> tb.softMaskedBlocks("chr1")
[(62, 70)]
As shown, you must specify storeMasked=True or you will receive a run time error.
Close a file
A TwoBit object can be closed with the close() method.
>>> tb.close()
A note on coordinates
0-based half-open coordinates are used by this python module. So to access the value for the first base on chr1, one would specify the starting position as 0 and the end position as 1. Similarly, bases 100 to 115 would have a start of 99 and an end of 115. This is simply for the sake of consistency with most other bioinformatics packages.
Owner
- Name: The deepTools ecosystem
- Login: deeptools
- Kind: organization
- Repositories: 13
- Profile: https://github.com/deeptools
deepTools and related packages
GitHub Events
Total
- Create event: 6
- Release event: 2
- Issues event: 5
- Watch event: 3
- Delete event: 4
- Issue comment event: 7
- Push event: 15
- Pull request event: 9
Last Year
- Create event: 6
- Release event: 2
- Issues event: 5
- Watch event: 3
- Delete event: 4
- Issue comment event: 7
- Push event: 15
- Pull request event: 9
Committers
Last synced: almost 3 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| dpryan79 | d****9@g****m | 26 |
| Devon Ryan | d****n@g****m | 4 |
| kojix2 | 2****k@g****m | 2 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 10
- Total pull requests: 14
- Average time to close issues: 8 months
- Average time to close pull requests: 10 days
- Total issue authors: 9
- Total pull request authors: 3
- Average comments per issue: 1.7
- Average comments per pull request: 0.57
- Merged pull requests: 13
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 7
- Average time to close issues: about 1 month
- Average time to close pull requests: about 1 hour
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 1.5
- Average comments per pull request: 0.29
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- dpryan79 (2)
- FliegendeWurst (1)
- daquang (1)
- newgene (1)
- TheChymera (1)
- nl835 (1)
- emollier (1)
- LudvigOlsen (1)
- eranroz (1)
Pull Request Authors
- dpryan79 (12)
- emollier (2)
- kojix2 (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 12,332 last-month
- Total docker downloads: 1,274
- Total dependent packages: 5
- Total dependent repositories: 21
- Total versions: 6
- Total maintainers: 2
pypi.org: py2bit
A package for accessing 2bit files using lib2bit
- Documentation: https://py2bit.readthedocs.io/
- License: MIT
-
Latest release: 0.3.3
published over 1 year ago