cdhit-parser
CD-HIT file reader.
Read CD-HIT .clstr file
Basic usage
from cdhit_reader import read_cdhit
input = "cluster.fa.clstr"
for cluster in read_cdhit(input):
print(f"{cluster.name} refSequence={cluster.refname} size={len(cluster)}")
for member in cluster.sequences:
print(f" {member.name} ({member.length}) identity={member.identity}% {'(Reference sequence)' if member.is_ref else ''}")
Load all clusters in to a list:
# Load all clusters to a list
clusters = read_cdhit(input).read_items()
Sequence to cluster lookup
Clustering loads a whole .clstr file and provides a reverse index
(seqcluster) mapping each sequence name to the name of its cluster:
from cdhit_reader import Clustering
clustering = Clustering.from_file(input)
print(len(clustering)) # number of clusters
for cluster in clustering: # iterate over the clusters
print(cluster.name)
# Which cluster does a sequence belong to?
print(clustering.seqcluster["seq1.A"]) # e.g. "Cluster 0"
Read FASTA file
if os.path.exists(fileName):
for seq in cdhit_reader.read_fasta(fileName, line_len=60):
print(seq) # will be wrapped at 60 chars per line, use 0 to disable wrapping
# to access individual attributes:
# print(">" + seq.name + " " + seq.comment + "\n" + seq.sequence)
Install
pip install cdhit-reader
or via Miniconda, which will also install cd-hit
conda install -c bioconda -c conda-forge cdhit-reader
Demo applications
Cluster stats
The module ships a demo program called cdhit-reader.py.
Compare two fasta files
:warning: This requires cd-hit installed and available in the system path.
cdhit-compare allows to compare two fasta files and print the sequences that are in common, those which are only
present in one of the files or those which are redundant.
Example:
cdhit-compare data/input1.faa data/input2.faa --id 0.99
will produce:
input1 BJJOHBJ_00007
input2 BJJOHBJ_00007
input2 BJJOHBJ_00002
both BJJOHBJ_00003:BJJOHBJ_00003
both BJJOHBJ_00005:BJJOHBJ_00005
both BJJOHBJ_00004:BJJOHBJ_00004
multi input1#IBJJOHBJ_00006,input1#BBJJOHBJ_000B6,input1#CBJJOHBJ_000C6,input2#IBJJOHBJ_00006,input2#BBJJOHBJ_000B6,input2#CBJJOHBJ_000C6
dupl_input1 BJJOHBJ_00001:BJJOHBJ_000F
where records starting with file1 or file2 are only present in one of the files, records starting with both are present in both files (one per file), records starting with dupl are duplicates (two in one of the files), and records starting with multi are present multiple times in at least one of the datasets.
Author
License
This project is licensed under the MIT License.
Acknowledgments
This module was based on fasta_reader by Danilo Horta
Metadata
Release files for cdhit-reader 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cdhit_reader-0.5.0.tar.gz | 20.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cdhit_reader-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.0 kB
Release files / cdhit_reader-0.5.0.tar.gz
| Download URL | cdhit_reader-0.5.0.tar.gz |
|---|---|
| Size | 20.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f55e21ab86b9bc4569ba7e5967be978448edb8569e38618917fc83d68a978a3
|
|
BLAKE2b-256 checksum How to use checksums |
1b1444cb4ace3dcfacb7ea17603f0a4810fcd18b5fffbc1a6c67c8b7bc8c1e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / cdhit_reader-0.5.0-py3-none-any.whl
| Download URL | cdhit_reader-0.5.0-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a65b91f2d7aad7938a9c7ba4d4980b7bd8e4fc72048e6a4e37fa98efce64e9b2
|
|
BLAKE2b-256 checksum How to use checksums |
3feb5fa8df453d90c763c46797f65cec0de8b3c76ffa04aa945eef1f176b35bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for cdhit-reader 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.