diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8f7df13a..58f5a0ed 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -35,6 +35,7 @@ Changed - ``Contact.is_match`` and ``Contact.define_match`` renamed to attribute ``Contact.true_positive`` - ``Contact.is_mismatch`` and ``Contact.define_mismatch`` renamed to attribute ``Contact.false_positive`` - ``Contact.is_unknown`` and ``Contact.define_unknown`` renamed to attribute ``Contact.status_unknown`` +- ``Entity``, ``Gap`` and ``Residue`` classes made public Fixed ~~~~~ - Bug fix in ``SequenceFile.filter`` to remove ``Sequence`` entries reliably diff --git a/conkit/__init__.py b/conkit/__init__.py index 62ac8737..77a507eb 100644 --- a/conkit/__init__.py +++ b/conkit/__init__.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ ConKit is a Python interface for handling and manipulating contact predictions obtained from a variety of different @@ -37,6 +36,6 @@ import conkit.version __author__ = "Felix Simkovic" -__contributing_authors__ = "Jens Thomas" +__contributing_authors__ = "Jens Thomas & Adam Simpkin" __credits__ = "Stefan Seemayer" __version__ = conkit.version.__version__ diff --git a/conkit/applications/bbcontacts.py b/conkit/applications/bbcontacts.py index 7259f975..e082eeed 100644 --- a/conkit/applications/bbcontacts.py +++ b/conkit/applications/bbcontacts.py @@ -71,13 +71,12 @@ class BbcontactsCommandline(AbstractCommandline): bbcontacts You would typically run the command line with :func:`bbcontacts_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. - Notes - ----- - In order to use bbcontacts, head over to the `GitHub repository - `_, download the latest version - and install it using python setup.py install. + Note + ---- + Installation instructions are available via the `GitHub repository + `_. """ @@ -92,46 +91,32 @@ def __init__(self, cmd="bbcontacts", **kwargs): raise RuntimeError(msg) self.parameters = [ - _Option(['-c', 'config_file'], - 'bbcontacts configuration file', - filename=True, - equate=False), - _Option(['-s', 'smoothing_size'], - 'Perform local background correction of the coupling matrix ' - 'before decoding: from each coupling, subtract the average ' - 'coupling (smoothed background) over an area extending by ' - 'SMOOTHINGSIZE in each direction [default=10, use 0 for no ' - 'local background correction]', - equate=False), - _Switch(['-l', 'long_predictions'], - 'Turn off (slow) prediction-shortening mode (this mode is on ' + _Option(['-c', 'config_file'], 'bbcontacts configuration file', filename=True, equate=False), + _Option( + ['-s', 'smoothing_size'], + 'Perform local background correction of the coupling matrix ' + 'before decoding: from each coupling, subtract the average ' + 'coupling (smoothed background) over an area extending by ' + 'SMOOTHINGSIZE in each direction [default=10, use 0 for no ' + 'local background correction]', + equate=False), + _Switch(['-l', 'long_predictions'], 'Turn off (slow) prediction-shortening mode (this mode is on ' 'by default but will only get triggered when long predictions occur)'), - _Option(['-n', 'pdb_name'], - 'Provide a PDB identifier (when also using -e, this will be the ' - 'PDB name to look for in EVALUATIONFILE)', - equate=False), - _Option(['-e', 'evaluation_file'], - 'Provide a file containing the true contacts (BetaSheet916.dat, ' - 'BetaSheet1452.dat or same format) for evaluation', - filename=True, - equate=False), - _Argument(['matfile'], - 'CCMpred-like coupling matrix', - filename=True, - is_required=True), - _Argument(['diversity_score'], - 'sequence-dependent diversity score', - is_required=True), - _Argument(['prefix'], - 'output prefix', - is_required=True), - _Option(['-d', 'dssp_file'], - 'DSSP secondary structure prediction file', - filename=True, - equate=False), - _Option(['-p', 'psipred_file'], - 'PSIPRED secondary structure prediction file', - filename=True, - equate=False), + _Option( + ['-n', 'pdb_name'], + 'Provide a PDB identifier (when also using -e, this will be the ' + 'PDB name to look for in EVALUATIONFILE)', + equate=False), + _Option( + ['-e', 'evaluation_file'], + 'Provide a file containing the true contacts (BetaSheet916.dat, ' + 'BetaSheet1452.dat or same format) for evaluation', + filename=True, + equate=False), + _Argument(['matfile'], 'CCMpred-like coupling matrix', filename=True, is_required=True), + _Argument(['diversity_score'], 'sequence-dependent diversity score', is_required=True), + _Argument(['prefix'], 'output prefix', is_required=True), + _Option(['-d', 'dssp_file'], 'DSSP secondary structure prediction file', filename=True, equate=False), + _Option(['-p', 'psipred_file'], 'PSIPRED secondary structure prediction file', filename=True, equate=False), ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/applications/ccmpred.py b/conkit/applications/ccmpred.py index 2f5a3b7c..0045a128 100644 --- a/conkit/applications/ccmpred.py +++ b/conkit/applications/ccmpred.py @@ -70,54 +70,36 @@ class CCMpredCommandline(AbstractCommandline): ccmpred test.aln output.mat You would typically run the command line with :func:`ccmpred_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ - + def __init__(self, cmd="ccmpred", **kwargs): self.parameters = [ - _Option(['-n', "numiter"], - 'Compute a maximum of NUMITER operations [default: 50]', - equate=False), - _Option(['-e', 'epsilon'], - "Set convergence criterion for minimum decrease in the " - "last K iterations to EPSILON [default: 0.01]", - equate=False), - _Option(['-k', 'lastk'], - "Set K parameter for convergence criterion to LASTK [default: 5]", - equate=False), - - _Option(['-i', 'inifile'], - "Read initial weights from INIFILE", - filename=True, - equate=False), - _Option(['-r', 'rawfile'], - "Store raw prediction matrix in RAWFILE", - filename=True, - equate=False), - _Option(['-t', 'threads'], - 'Calculate using THREADS threads on the CPU (automatically disables CUDA if available) [default: 1]', - equate=False), - - _Option(['-w', 'idthres'], - "Set sequence reweighting identity threshold to IDTHRES [default: 0.8]", - equate=False), - _Option(['-l', 'lfactor'], - "Set pairwise regularization coefficients to LFACTOR * (L-1) [default: 0.2]", - equate=False), - - _Switch(['-A', 'apc'], - "Disable average product correction (APC)"), - _Switch(['-R', 'renormalize'], - "Re-normalize output matrix to [0,1]"), - - _Argument(['alnfile'], - "Input alignment file [JONES format]", - filename=True, - is_required=True), - _Argument(['matfile'], - "Output matrix file", - filename=True, - is_required=True), + _Option(['-n', "numiter"], 'Compute a maximum of NUMITER operations [default: 50]', equate=False), + _Option( + ['-e', 'epsilon'], + "Set convergence criterion for minimum decrease in the " + "last K iterations to EPSILON [default: 0.01]", + equate=False), + _Option(['-k', 'lastk'], "Set K parameter for convergence criterion to LASTK [default: 5]", equate=False), + _Option(['-i', 'inifile'], "Read initial weights from INIFILE", filename=True, equate=False), + _Option(['-r', 'rawfile'], "Store raw prediction matrix in RAWFILE", filename=True, equate=False), + _Option( + ['-t', 'threads'], + 'Calculate using THREADS threads on the CPU (automatically disables CUDA if available) [default: 1]', + equate=False), + _Option( + ['-w', 'idthres'], + "Set sequence reweighting identity threshold to IDTHRES [default: 0.8]", + equate=False), + _Option( + ['-l', 'lfactor'], + "Set pairwise regularization coefficients to LFACTOR * (L-1) [default: 0.2]", + equate=False), + _Switch(['-A', 'apc'], "Disable average product correction (APC)"), + _Switch(['-R', 'renormalize'], "Re-normalize output matrix to [0,1]"), + _Argument(['alnfile'], "Input alignment file [JONES format]", filename=True, is_required=True), + _Argument(['matfile'], "Output matrix file", filename=True, is_required=True), ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/applications/cdhit.py b/conkit/applications/cdhit.py index a4d74df3..90cf707c 100644 --- a/conkit/applications/cdhit.py +++ b/conkit/applications/cdhit.py @@ -71,126 +71,128 @@ class CdhitCommandline(AbstractCommandline): >>> print(cdhit_cline) You would typically run the command line with :func:`cdhit_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ def __init__(self, cmd="cd-hit", **kwargs): self.parameters = [ - _Option(['-i', 'input'], - 'input filename in fasta format, required', - filename=True, - equate=False, - is_required=True), - _Option(['-o', 'output'], - 'output filename, required', - filename=True, - equate=False, - is_required=True), - _Option(['-c', 'seq_id_thres'], - "sequence identity threshold, default 0.9 " - "this is the default cd-hit's 'global sequence identity' calculated as: " - "number of identical amino acids in alignment divided by " - "the full length of the shorter sequence", - equate=False), - _Option(['-G', 'global_seq_id'], - "use global sequence identity, default 1 " - "if set to 0, then use local sequence identity, calculated as : " - "number of identical amino acids in alignment " - "divided by the length of the alignment " - "NOTE!!! don't use -G 0 unless you use alignment coverage controls " - "see options -aL (kwarg: `cov_alignment_long`), -AL (kwarg: `cov_alignment_long_control`)," - " -aS (kwarg: `cov_alignment_short`), -AS (kwarg: `cov_alignment_short_control`)", - equate=False), - _Option(['-b', 'band_width'], - 'band_width of alignment, default 20', - equate=False), - _Option(['-M', 'memory_limit'], - 'memory limit (in MB) for the program, default 800; 0 for unlimited', - equate=False), - _Option(['-T', 'num_threads'], - 'number of threads, default 1; with 0, all CPUs will be used', - equate=False), - _Option(['-n', 'word_length'], - "word_length, default 5, see user's guide for choosing it", - equate=False), - _Option(['-l', 'len_throw_away_seqs'], - "length of throw_away_sequences, default 10", - equate=False), - _Option(['-t', 'tol_4_redundance'], - "tolerance for redundance, default 2", - equate=False), - _Option(['-d', 'len_desc'], - "length of description in .clstr file, default 20 " - "if set to 0, it takes the fasta defline and stops at first space " - "-s length difference cutoff, default 0.0", - equate=False), - _Option(['-s', 'len_diff_cutoff'], - "length difference cutoff, default 0.0 " - "if set to 0.9, the shorter sequences need to be " - "at least 90% length of the representative of the cluster", - equate=False), - _Option(['-S', 'len_diff_cutoff_aa'], - "length difference cutoff in amino acid, default 999999 " - "if set to 60, the length difference between the shorter sequences " - "and the representative of the cluster can not be bigger than 60", - equate=False), - _Option(['-aL', 'cov_alignment_long'], - "alignment coverage for the longer sequence, default 0.0 " - "if set to 0.9, the alignment must covers 90% of the sequence", - equate=False), - _Option(['-AL', 'cov_alignment_long_control'], - "alignment coverage control for the longer sequence, default 99999999 " - "if set to 60, and the length of the sequence is 400, " - "then the alignment must be >= 340 (400-60) residues", - equate=False), - _Option(['-aS', 'cov_alignment_short'], - "alignment coverage for the shorter sequence, default 0.0 " - "if set to 0.9, the alignment must covers 90% of the sequence", - equate=False), - _Option(['-AS', 'cov_alignment_short_control'], - "alignment coverage control for the shorter sequence, default 99999999 " - "if set to 60, and the length of the sequence is 400, " - "then the alignment must be >= 340 (400-60) residues", - equate=False), - _Option(['-A', 'cov_alignment'], - "minimal alignment coverage control for the both sequences, default 0 " - "alignment must cover >= this value for both sequences", - equate=False), - _Option(['-uL', 'max_unmatched_percentage_long'], - "maximum unmatched percentage for the longer sequence, default 1.0 " - "if set to 0.1, the unmatched region (excluding leading and tailing gaps) " - "must not be more than 10% of the sequence", - equate=False), - _Option(['-uS', 'max_unmatched_percentage_short'], - "maximum unmatched percentage for the shorter sequence, default 1.0 " - "if set to 0.1, the unmatched region (excluding leading and tailing gaps) " - "must not be more than 10% of the sequence", - equate=False), - _Option(['-U', 'len_max_unmatched'], - "maximum unmatched length, default 99999999 " - "if set to 10, the unmatched region (excluding leading and tailing gaps) " - "must not be more than 10 bases", - equate=False), - _Option(['-B', 'hdd_storage'], - "1 or 0, default 0, by default, sequences are stored in RAM " - "if set to 1, sequence are stored on hard drive " - "it is recommended to use -B 1 for huge databases", - equate=False), - _Option(['-p', 'aln_overlap_2_file'], - "1 or 0, default 0 " - "if set to 1, print alignment overlap in .clstr file", - equate=False), - _Option(['-g', 'accurate_mode'], - "1 or 0, default 0 " - "by cd-hit's default algorithm, a sequence is clustered to the first " - "cluster that meet the threshold (fast cluster). If set to 1, the program " - "will cluster it into the most similar cluster that meet the threshold " - "(accurate but slow mode) " - "but either 1 or 0 won't change the representatives of final clusters", - equate=False), - _Option(['-bak', 'backup'], - "write backup cluster file (1 or 0, default 0)", - equate=False), + _Option( + ['-i', 'input'], + 'input filename in fasta format, required', + filename=True, + equate=False, + is_required=True), + _Option(['-o', 'output'], 'output filename, required', filename=True, equate=False, is_required=True), + _Option( + ['-c', 'seq_id_thres'], + "sequence identity threshold, default 0.9 " + "this is the default cd-hit's 'global sequence identity' calculated as: " + "number of identical amino acids in alignment divided by " + "the full length of the shorter sequence", + equate=False), + _Option( + ['-G', 'global_seq_id'], + "use global sequence identity, default 1 " + "if set to 0, then use local sequence identity, calculated as : " + "number of identical amino acids in alignment " + "divided by the length of the alignment " + "NOTE!!! don't use -G 0 unless you use alignment coverage controls " + "see options -aL (kwarg: `cov_alignment_long`), -AL (kwarg: `cov_alignment_long_control`)," + " -aS (kwarg: `cov_alignment_short`), -AS (kwarg: `cov_alignment_short_control`)", + equate=False), + _Option(['-b', 'band_width'], 'band_width of alignment, default 20', equate=False), + _Option( + ['-M', 'memory_limit'], + 'memory limit (in MB) for the program, default 800; 0 for unlimited', + equate=False), + _Option(['-T', 'num_threads'], 'number of threads, default 1; with 0, all CPUs will be used', equate=False), + _Option(['-n', 'word_length'], "word_length, default 5, see user's guide for choosing it", equate=False), + _Option(['-l', 'len_throw_away_seqs'], "length of throw_away_sequences, default 10", equate=False), + _Option(['-t', 'tol_4_redundance'], "tolerance for redundance, default 2", equate=False), + _Option( + ['-d', 'len_desc'], + "length of description in .clstr file, default 20 " + "if set to 0, it takes the fasta defline and stops at first space " + "-s length difference cutoff, default 0.0", + equate=False), + _Option( + ['-s', 'len_diff_cutoff'], + "length difference cutoff, default 0.0 " + "if set to 0.9, the shorter sequences need to be " + "at least 90% length of the representative of the cluster", + equate=False), + _Option( + ['-S', 'len_diff_cutoff_aa'], + "length difference cutoff in amino acid, default 999999 " + "if set to 60, the length difference between the shorter sequences " + "and the representative of the cluster can not be bigger than 60", + equate=False), + _Option( + ['-aL', 'cov_alignment_long'], + "alignment coverage for the longer sequence, default 0.0 " + "if set to 0.9, the alignment must covers 90% of the sequence", + equate=False), + _Option( + ['-AL', 'cov_alignment_long_control'], + "alignment coverage control for the longer sequence, default 99999999 " + "if set to 60, and the length of the sequence is 400, " + "then the alignment must be >= 340 (400-60) residues", + equate=False), + _Option( + ['-aS', 'cov_alignment_short'], + "alignment coverage for the shorter sequence, default 0.0 " + "if set to 0.9, the alignment must covers 90% of the sequence", + equate=False), + _Option( + ['-AS', 'cov_alignment_short_control'], + "alignment coverage control for the shorter sequence, default 99999999 " + "if set to 60, and the length of the sequence is 400, " + "then the alignment must be >= 340 (400-60) residues", + equate=False), + _Option( + ['-A', 'cov_alignment'], + "minimal alignment coverage control for the both sequences, default 0 " + "alignment must cover >= this value for both sequences", + equate=False), + _Option( + ['-uL', 'max_unmatched_percentage_long'], + "maximum unmatched percentage for the longer sequence, default 1.0 " + "if set to 0.1, the unmatched region (excluding leading and tailing gaps) " + "must not be more than 10% of the sequence", + equate=False), + _Option( + ['-uS', 'max_unmatched_percentage_short'], + "maximum unmatched percentage for the shorter sequence, default 1.0 " + "if set to 0.1, the unmatched region (excluding leading and tailing gaps) " + "must not be more than 10% of the sequence", + equate=False), + _Option( + ['-U', 'len_max_unmatched'], + "maximum unmatched length, default 99999999 " + "if set to 10, the unmatched region (excluding leading and tailing gaps) " + "must not be more than 10 bases", + equate=False), + _Option( + ['-B', 'hdd_storage'], + "1 or 0, default 0, by default, sequences are stored in RAM " + "if set to 1, sequence are stored on hard drive " + "it is recommended to use -B 1 for huge databases", + equate=False), + _Option( + ['-p', 'aln_overlap_2_file'], + "1 or 0, default 0 " + "if set to 1, print alignment overlap in .clstr file", + equate=False), + _Option( + ['-g', 'accurate_mode'], + "1 or 0, default 0 " + "by cd-hit's default algorithm, a sequence is clustered to the first " + "cluster that meet the threshold (fast cluster). If set to 1, the program " + "will cluster it into the most similar cluster that meet the threshold " + "(accurate but slow mode) " + "but either 1 or 0 won't change the representatives of final clusters", + equate=False), + _Option(['-bak', 'backup'], "write backup cluster file (1 or 0, default 0)", equate=False), ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/applications/hhblits.py b/conkit/applications/hhblits.py index 545faad5..2fdbc63f 100644 --- a/conkit/applications/hhblits.py +++ b/conkit/applications/hhblits.py @@ -68,7 +68,7 @@ class HHblitsCommandline(AbstractCommandline): hhblits -i test.fasta -d uniprot20_29Feb2012 You would typically run the command line with :func:`hhblits_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ diff --git a/conkit/applications/hhfilter.py b/conkit/applications/hhfilter.py index 03b140ee..24764c2c 100644 --- a/conkit/applications/hhfilter.py +++ b/conkit/applications/hhfilter.py @@ -67,50 +67,46 @@ class HHfilterCommandline(AbstractCommandline): hhfilter -i test.a3m -o test.filtered.a3m You would typically run the command line with :func:`hhfilter_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ def __init__(self, cmd='hhfilter', **kwargs): self.parameters = [ - _Option(['-i', 'input'], - 'read input file in A3M/A2M or FASTA format', - filename=True, - is_required=True, - equate=False), - _Option(['-o', 'output'], - 'write to output file in A3M format', - filename=True, - is_required=True, - equate=False), - _Option(['-a', 'append_output'], - 'append to output file in A3M format', - filename=True, - equate=False), + _Option( + ['-i', 'input'], + 'read input file in A3M/A2M or FASTA format', + filename=True, + is_required=True, + equate=False), + _Option( + ['-o', 'output'], 'write to output file in A3M format', filename=True, is_required=True, equate=False), + _Option(['-a', 'append_output'], 'append to output file in A3M format', filename=True, equate=False), # Options - _Option(['-v', 'verbose'], - 'verbose mode: 0:no screen output 1:only warings 2: verbose [default: 2]', - equate=False), - _Option(['-id', 'pairwise_identity'], - 'maximum pairwise sequence identity [default: 90]', - equate=False), - _Option(['-diff', 'diversity'], - 'filter MSAs by selecting most diverse set of sequences, keeping ' - 'at least this many seqs in each MSA block of length 50 [default: 1000]', - equate=False), - _Option(['-cov', 'coverage'], - 'minimum coverage with master sequence (%) [default: 0]', - equate=False), - _Option(['-qid', 'query_identity'], - 'minimum sequence identity with master sequence (%) [default: 0]', - equate=False), - _Option(['-qsc', 'per_column_score'], - 'minimum score per column with master sequence [default: -20.0]', - equate=False), - _Option(['-neff', 'nr_effective_sequences'], - 'target diversity of multiple sequence alignment [default: off]', - equate=False), + _Option( + ['-v', 'verbose'], + 'verbose mode: 0:no screen output 1:only warings 2: verbose [default: 2]', + equate=False), + _Option(['-id', 'pairwise_identity'], 'maximum pairwise sequence identity [default: 90]', equate=False), + _Option( + ['-diff', 'diversity'], + 'filter MSAs by selecting most diverse set of sequences, keeping ' + 'at least this many seqs in each MSA block of length 50 [default: 1000]', + equate=False), + _Option(['-cov', 'coverage'], 'minimum coverage with master sequence (%) [default: 0]', equate=False), + _Option( + ['-qid', 'query_identity'], + 'minimum sequence identity with master sequence (%) [default: 0]', + equate=False), + _Option( + ['-qsc', 'per_column_score'], + 'minimum score per column with master sequence [default: -20.0]', + equate=False), + _Option( + ['-neff', 'nr_effective_sequences'], + 'target diversity of multiple sequence alignment [default: off]', + equate=False), # # Input alignment options # _Option(['-M', 'a2m'], @@ -122,7 +118,6 @@ def __init__(self, cmd='hhfilter', **kwargs): # _Option(['-M', 'match_states'], # 'use FASTA: columns with fewer than X% gaprs are match states', # equate=False), - ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/applications/jackhmmer.py b/conkit/applications/jackhmmer.py index 50b39d14..75ee76ed 100644 --- a/conkit/applications/jackhmmer.py +++ b/conkit/applications/jackhmmer.py @@ -67,213 +67,165 @@ class JackhmmerCommandline(AbstractCommandline): jackhmmer test.fasta uniref100.fasta You would typically run the command line with :func:`jackhmmer_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ def __init__(self, cmd='jackhmmer', **kwargs): self.parameters = [ - _Option(['-N', 'niterations'], - 'set maximum number of iterations [default: 5]', - equate=False), + _Option(['-N', 'niterations'], 'set maximum number of iterations [default: 5]', equate=False), # Options directing output - _Option(['-o', 'output'], - 'direct output to file , not stdout', - filename=True, - equate=False), - _Option(['-A', 'msa_hits'], - 'save multiple alignment of hits to file ', - filename=True, - equate=False), - _Option(['--tblout', 'per_sequence_hits'], - 'save parseable table of per-sequence hits to file ', - filename=True, - equate=False), - _Option(['--domtblout', 'per_domain_hits'], - 'save parseable table of per-domain hits to file ', - filename=True, - equate=False), - _Option(['--chkhmm', 'hmm_checkpoints'], - 'save HMM checkpoints to files -.hmm', - filename=True, - equate=False), - _Option(['--chkali', 'alignment_checkpoints'], - 'save alignment checkpoints to files -.sto', - filename=True, - equate=False), - _Switch(['--acc', 'accession'], - 'prefer accessions over names in output'), - _Switch(['--noali', 'no_alignment'], - 'don\'t output alignments, so output is smaller'), - _Switch(['--notextw', 'notextw'], - 'unlimit ASCII text output line width'), - _Switch(['--textw', 'textw'], - 'set max width of ASCII text output lines [default: 120] (n>=120)'), + _Option(['-o', 'output'], 'direct output to file , not stdout', filename=True, equate=False), + _Option(['-A', 'msa_hits'], 'save multiple alignment of hits to file ', filename=True, equate=False), + _Option( + ['--tblout', 'per_sequence_hits'], + 'save parseable table of per-sequence hits to file ', + filename=True, + equate=False), + _Option( + ['--domtblout', 'per_domain_hits'], + 'save parseable table of per-domain hits to file ', + filename=True, + equate=False), + _Option( + ['--chkhmm', 'hmm_checkpoints'], + 'save HMM checkpoints to files -.hmm', + filename=True, + equate=False), + _Option( + ['--chkali', 'alignment_checkpoints'], + 'save alignment checkpoints to files -.sto', + filename=True, + equate=False), + _Switch(['--acc', 'accession'], 'prefer accessions over names in output'), + _Switch(['--noali', 'no_alignment'], 'don\'t output alignments, so output is smaller'), + _Switch(['--notextw', 'notextw'], 'unlimit ASCII text output line width'), + _Switch(['--textw', 'textw'], 'set max width of ASCII text output lines [default: 120] (n>=120)'), # Options controlling scoring system in first iteration - _Option(['--popen', 'gap_open_probability'], - 'gap open probability', - equate=False), - _Option(['--pextend', 'gap_extend_probability'], - 'gap extend probability', - equate=False), - _Option(['--mx', 'matrix_choice'], - 'substitution score matrix choice (of some built-in matrices)', - equate=False), - _Option(['--mxfile', 'matrix_option'], - 'read substitution score matrix from file ', - filename=True, - equate=False), + _Option(['--popen', 'gap_open_probability'], 'gap open probability', equate=False), + _Option(['--pextend', 'gap_extend_probability'], 'gap extend probability', equate=False), + _Option( + ['--mx', 'matrix_choice'], 'substitution score matrix choice (of some built-in matrices)', + equate=False), + _Option( + ['--mxfile', 'matrix_option'], + 'read substitution score matrix from file ', + filename=True, + equate=False), # Options controlling reporting thresholds - _Option(['-E', 'evalue'], - 'report sequences <= this E-value threshold in output [default: 10.0] (x>0)', - equate=False), - _Option(['-T', 'score_threshold'], - 'report sequences >= this score threshold in output', - equate=False), - _Option(['--domE', 'domain_evalue'], - 'report domains <= this E-value threshold in output [default: 10.0] (x>0)', - equate=False), - _Option(['--domT', 'domain_score_threshold'], - 'report domains >= this score cutoff in output', - equate=False), + _Option( + ['-E', 'evalue'], + 'report sequences <= this E-value threshold in output [default: 10.0] (x>0)', + equate=False), + _Option(['-T', 'score_threshold'], 'report sequences >= this score threshold in output', equate=False), + _Option( + ['--domE', 'domain_evalue'], + 'report domains <= this E-value threshold in output [default: 10.0] (x>0)', + equate=False), + _Option( + ['--domT', 'domain_score_threshold'], 'report domains >= this score cutoff in output', equate=False), # Options controlling significance thresholds for inclusion in next round - _Option(['--incE', 'inclusion_evalue'], - 'consider sequences <= this E-value threshold as significant', - equate=False), - _Option(['--incT', 'inclusion_score_threshold'], - 'consider sequences >= this score threshold as significant', - equate=False), - _Option(['--incdomE', 'inclusion_domain_evalue'], - 'consider domains <= this E-value threshold as significant', - equate=False), - _Option(['--incdomT', 'inclusion_domain_score_threshold'], - 'consider domains >= this score threshold as significant', - equate=False), + _Option( + ['--incE', 'inclusion_evalue'], + 'consider sequences <= this E-value threshold as significant', + equate=False), + _Option( + ['--incT', 'inclusion_score_threshold'], + 'consider sequences >= this score threshold as significant', + equate=False), + _Option( + ['--incdomE', 'inclusion_domain_evalue'], + 'consider domains <= this E-value threshold as significant', + equate=False), + _Option( + ['--incdomT', 'inclusion_domain_score_threshold'], + 'consider domains >= this score threshold as significant', + equate=False), # Options controlling acceleration heuristics - _Switch(['--max', 'no_heuristics'], - 'Turn all heuristic filters off (less speed, more power)'), - _Option(['--F1', 'stage1_threshold'], - 'Stage 1 (MSV) threshold: promote hits w/ P <= F1 [default: 0.02]', - equate=False), - _Option(['--F2', 'stage2_threshold'], - 'Stage 2 (Vit) threshold: promote hits w/ P <= F2 [default: 1e-3]', - equate=False), - _Option(['--F3', 'stage3_threshold'], - 'Stage 3 (Fwd) threshold: promote hits w/ P <= F3 [default: 1e-5]', - equate=False), - _Switch(['--nobias', 'nobias'], - 'turn off composition bias filter'), + _Switch(['--max', 'no_heuristics'], 'Turn all heuristic filters off (less speed, more power)'), + _Option( + ['--F1', 'stage1_threshold'], + 'Stage 1 (MSV) threshold: promote hits w/ P <= F1 [default: 0.02]', + equate=False), + _Option( + ['--F2', 'stage2_threshold'], + 'Stage 2 (Vit) threshold: promote hits w/ P <= F2 [default: 1e-3]', + equate=False), + _Option( + ['--F3', 'stage3_threshold'], + 'Stage 3 (Fwd) threshold: promote hits w/ P <= F3 [default: 1e-5]', + equate=False), + _Switch(['--nobias', 'nobias'], 'turn off composition bias filter'), # Options controlling model construction after first iteration - _Switch(['--fast', 'fast'], - 'assign cols w/ >= symfrac residues as consensus'), - _Switch(['--hand', 'hand'], - 'manual construction (requires reference annotation)'), - _Option(['--symfrac', 'symfrac'], - 'sets sym fraction controlling --fast construction', - equate=False), - _Option(['--fragthres', 'fragthres'], - 'if L <= x*alen, tag sequence as a fragment', - equate=False), + _Switch(['--fast', 'fast'], 'assign cols w/ >= symfrac residues as consensus'), + _Switch(['--hand', 'hand'], 'manual construction (requires reference annotation)'), + _Option(['--symfrac', 'symfrac'], 'sets sym fraction controlling --fast construction', equate=False), + _Option(['--fragthres', 'fragthres'], 'if L <= x*alen, tag sequence as a fragment', equate=False), # Options controlling relative weights in models after first iteration - _Switch(['--wpb', 'henikoff_pb_weights'], - 'Henikoff position-based weights [default]'), - _Switch(['--wgsc', 'GSC_weights'], - 'Gerstein/Sonnhammer/Chothia tree weights'), - _Switch(['--wblosum', 'henikoff_sf_weights'], - 'Henikoff simple filter weights'), - _Switch(['--wnone', 'no_weight'], - 'don\'t do any relative weighting; set all to 1'), - _Option(['--wid', 'wblosum_cutoff'], - 'for --wblosum: set identity cutoff [default: 0.62] (0<=x<=1)', - equate=False), + _Switch(['--wpb', 'henikoff_pb_weights'], 'Henikoff position-based weights [default]'), + _Switch(['--wgsc', 'GSC_weights'], 'Gerstein/Sonnhammer/Chothia tree weights'), + _Switch(['--wblosum', 'henikoff_sf_weights'], 'Henikoff simple filter weights'), + _Switch(['--wnone', 'no_weight'], 'don\'t do any relative weighting; set all to 1'), + _Option( + ['--wid', 'wblosum_cutoff'], + 'for --wblosum: set identity cutoff [default: 0.62] (0<=x<=1)', + equate=False), # Options controlling effective seq number in models after first iteration - _Switch(['--eent', 'eent'], - 'adjust eff seq # to achieve relative entropy target [default]'), - _Switch(['--eclust', 'ecluse'], - 'eff seq # is # of single linkage clusters'), - _Switch(['--enone', 'enone'], - 'no effective seq # weighting: just use nseq'), - _Option(['--eset', 'eset'], - 'set eff seq # for all models to ', - equate=False), - _Option(['--ere', 'ere'], - 'for --eent: set minimum rel entropy/position to ', - equate=False), - _Option(['--esigma', 'esigma'], - 'for --eent: set sigma param to [default: 45.0]', - equate=False), - _Option(['--eid', 'eid'], - 'for --eclust: set fractional identity cutoff to [default: 0.62]', - equate=False), + _Switch(['--eent', 'eent'], 'adjust eff seq # to achieve relative entropy target [default]'), + _Switch(['--eclust', 'ecluse'], 'eff seq # is # of single linkage clusters'), + _Switch(['--enone', 'enone'], 'no effective seq # weighting: just use nseq'), + _Option(['--eset', 'eset'], 'set eff seq # for all models to ', equate=False), + _Option(['--ere', 'ere'], 'for --eent: set minimum rel entropy/position to ', equate=False), + _Option(['--esigma', 'esigma'], 'for --eent: set sigma param to [default: 45.0]', equate=False), + _Option( + ['--eid', 'eid'], 'for --eclust: set fractional identity cutoff to [default: 0.62]', equate=False), # Options controlling prior strategy in models after first iteration - _Switch(['--pnone', 'pnone'], - 'don\'t use any prior; parameters are frequencies'), - _Switch(['--plaplace', 'plaplace'], - 'use a Laplace +1 prior'), + _Switch(['--pnone', 'pnone'], 'don\'t use any prior; parameters are frequencies'), + _Switch(['--plaplace', 'plaplace'], 'use a Laplace +1 prior'), # Options controlling E value calibration - _Option(['--EmL', 'eml'], - 'length of sequences for MSV Gumbel mu fit [default: 200] (n>0)', - equate=False), - _Option(['--EmN', 'emn'], - 'number of sequences for MSV Gumbel mu fit [default: 200] (n>0)', - equate=False), - _Option(['--EvL', 'evl'], - 'length of sequences for Viterbi Gumbel mu fit [default: 200] (n>0)', - equate=False), - _Option(['--EvN', 'evn'], - 'number of sequences for Viterbi Gumbel mu fit [default: 200] (n>0)', - equate=False), - _Option(['--EfL', 'efl'], - 'length of sequences for Forward exp tail tau fit [default: 100] (n>0)', - equate=False), - _Option(['--EfN', 'efn'], - 'number of sequences for Forward exp tail tau fit [default: 200] (n>0)', - equate=False), - _Option(['--Eft', 'eft'], - 'tail mass for Forward exponential tail tau fit [default: 0.04] (00)', equate=False), + _Option(['--EmN', 'emn'], 'number of sequences for MSV Gumbel mu fit [default: 200] (n>0)', equate=False), + _Option( + ['--EvL', 'evl'], 'length of sequences for Viterbi Gumbel mu fit [default: 200] (n>0)', equate=False), + _Option( + ['--EvN', 'evn'], 'number of sequences for Viterbi Gumbel mu fit [default: 200] (n>0)', equate=False), + _Option( + ['--EfL', 'efl'], 'length of sequences for Forward exp tail tau fit [default: 100] (n>0)', + equate=False), + _Option( + ['--EfN', 'efn'], 'number of sequences for Forward exp tail tau fit [default: 200] (n>0)', + equate=False), + _Option( + ['--Eft', 'eft'], + 'tail mass for Forward exponential tail tau fit [default: 0.04] (0 (if 0: one-time arbitrary seed) [default: 42]', - equate=False), - _Option(['--qformat', 'qformat'], - 'assert query is in format : no autodetection', - equate=False), - _Option(['--tformat', 'tformat'], - 'assert target < seqdb > is in format < s >>: no autodetection', - equate=False), - _Option(['--cpu', 'cpu'], - 'number of parallel CPU workers to use for multithreads', - equate=False), + _Switch(['--nonull2', 'nonull2'], 'turn off biased composition score corrections'), + _Option(['-Z', 'ncomparison'], 'set # of comparisons done, for E-value calculation', equate=False), + _Option(['--domZ', 'domz'], 'set # of significant seqs, for domain E-value calculation', equate=False), + _Option( + ['--seed', 'seed'], 'set RNG seed to (if 0: one-time arbitrary seed) [default: 42]', equate=False), + _Option( + ['--qformat', 'qformat'], 'assert query is in format : no autodetection', equate=False), + _Option( + ['--tformat', 'tformat'], 'assert target < seqdb > is in format < s >>: no autodetection', + equate=False), + _Option(['--cpu', 'cpu'], 'number of parallel CPU workers to use for multithreads', equate=False), # Required arguments - _Argument(['input'], - 'sequence containing file', - filename=True, - is_required=True), - _Argument(['database'], - 'sequence database', - filename=True, - is_required=True), + _Argument(['input'], 'sequence containing file', filename=True, is_required=True), + _Argument(['database'], 'sequence database', filename=True, is_required=True), ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/applications/psicov.py b/conkit/applications/psicov.py index 1468ef5f..a4ca7d40 100644 --- a/conkit/applications/psicov.py +++ b/conkit/applications/psicov.py @@ -67,57 +67,31 @@ class PsicovCommandline(AbstractCommandline): psicov test.aln You would typically run the command line with :func:`psicov_cline` or via - the Python subprocess module. + the :mod:`~subprocess` module. """ def __init__(self, cmd='psicov', **kwargs): self.parameters = [ - - _Switch(['-a', 'lasso'], - "use approximate Lasso algorithm"), - _Switch(['-n', 'noshrink'], - "don't pre-shrink the sample covariance matrix"), - _Switch(['-f', 'filter'], - "filer low-scoring contacts"), - _Switch(['-p', 'ppv_output'], - "output PPV estimates rather than raw scores"), - _Switch(['-l', 'noapc'], - "don't apply APC to Lasso output"), - - _Option(['-r', 'rho'], - "set initial rho paramter", - equate=False), - _Option(['-d', 'sparsity'], - "set target precision matrix sparsity [default: 0; not specified]", - equate=False), - _Option(['-t', 'convergence_threshold'], - "set Lasso convergence threshold [default: 1e-4]", - equate=False), - _Option(['-i', 'blosum_weighting'], - "select BLOSUM-like weighting with given identity threshold " - "[default selects threshold automatically]", - equate=False), - _Option(['-c', 'pseudocount'], - "set pseudocount value [default: 1]", - equate=False), - _Option(['-j', 'sequence_separation'], - "set minimum sequence sparation [default: 5]", - equate=False), - _Option(['-g', 'gap_fraction'], - "set maximum fraction of gaps [default: 0.9]", - equate=False), - _Option(['-z', 'nr_threads'], - "set maximum number of threads", - equate=False), - _Option(['-b', 'rho_parameter_file'], - "read rho parameter file", - filename=True, - equate=False), - - _Argument(['alnfile'], - "Input alignment file [JONES format]", - filename=True, - is_required=True), + _Switch(['-a', 'lasso'], "use approximate Lasso algorithm"), + _Switch(['-n', 'noshrink'], "don't pre-shrink the sample covariance matrix"), + _Switch(['-f', 'filter'], "filer low-scoring contacts"), + _Switch(['-p', 'ppv_output'], "output PPV estimates rather than raw scores"), + _Switch(['-l', 'noapc'], "don't apply APC to Lasso output"), + _Option(['-r', 'rho'], "set initial rho paramter", equate=False), + _Option( + ['-d', 'sparsity'], "set target precision matrix sparsity [default: 0; not specified]", equate=False), + _Option(['-t', 'convergence_threshold'], "set Lasso convergence threshold [default: 1e-4]", equate=False), + _Option( + ['-i', 'blosum_weighting'], + "select BLOSUM-like weighting with given identity threshold " + "[default selects threshold automatically]", + equate=False), + _Option(['-c', 'pseudocount'], "set pseudocount value [default: 1]", equate=False), + _Option(['-j', 'sequence_separation'], "set minimum sequence sparation [default: 5]", equate=False), + _Option(['-g', 'gap_fraction'], "set maximum fraction of gaps [default: 0.9]", equate=False), + _Option(['-z', 'nr_threads'], "set maximum number of threads", equate=False), + _Option(['-b', 'rho_parameter_file'], "read rho parameter file", filename=True, equate=False), + _Argument(['alnfile'], "Input alignment file [JONES format]", filename=True, is_required=True), ] AbstractCommandline.__init__(self, cmd, **kwargs) diff --git a/conkit/command_line/__init__.py b/conkit/command_line/__init__.py index de16ae92..7f7879e0 100644 --- a/conkit/command_line/__init__.py +++ b/conkit/command_line/__init__.py @@ -52,8 +52,8 @@ def setup_logging(level='info', logfile=None): Returns ------- - logger - Instance of a :obj:`logger ` + :obj:`~logging.Logger` + Instance of a :obj:`~logging.Logger` """ @@ -62,21 +62,17 @@ class ColorFormatter(logging.Formatter): # ANSI foreground color codes colors = { - logging.DEBUG: 34, # blue - logging.WARNING: 33, # yellow - logging.ERROR: 31, # red - logging.CRITICAL: 31, # red + logging.DEBUG: 34, # blue + logging.WARNING: 33, # yellow + logging.ERROR: 31, # red + logging.CRITICAL: 31, # red } def format(self, record): if record.levelno in self.colors: - prefix = '\033[1;{}m'.format( - ColorFormatter.colors[record.levelno]) + prefix = '\033[1;{}m'.format(ColorFormatter.colors[record.levelno]) postfix = '\033[0m' - record.msg = os.linesep.join( - [prefix + l + - postfix for l in str(record.msg).splitlines()] - ) + record.msg = os.linesep.join([prefix + l + postfix for l in str(record.msg).splitlines()]) return logging.Formatter.format(self, record) # Reset any Handlers or Filters already in the logger to start from scratch @@ -85,8 +81,12 @@ def format(self, record): map(logging.getLogger().removeFilter, logging.getLogger().filters[:]) logging_levels = { - 'notset': logging.NOTSET, 'info': logging.INFO, 'debug': logging.DEBUG, - 'warning': logging.WARNING, 'error': logging.ERROR, 'critical': logging.CRITICAL + 'notset': logging.NOTSET, + 'info': logging.INFO, + 'debug': logging.DEBUG, + 'warning': logging.WARNING, + 'error': logging.ERROR, + 'critical': logging.CRITICAL } # Create logger and default settings @@ -102,14 +102,10 @@ def format(self, record): if logfile: fh = logging.FileHandler(logfile) fh.setLevel(logging.NOTSET) - fh.setFormatter( - logging.Formatter( - '%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s') - ) + fh.setFormatter(logging.Formatter('%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s')) logging.getLogger().addHandler(fh) - logging.getLogger().debug('Console logger level: %s', - logging_levels.get(level, logging.INFO)) + logging.getLogger().debug('Console logger level: %s', logging_levels.get(level, logging.INFO)) logging.getLogger().debug('File logger level: %s', logging.NOTSET) return logging.getLogger() diff --git a/conkit/core/contact.py b/conkit/core/contact.py index 7292d14c..76ad139f 100644 --- a/conkit/core/contact.py +++ b/conkit/core/contact.py @@ -39,12 +39,12 @@ __version__ = "1.0" from enum import Enum, unique -from conkit.core._entity import _Entity +from conkit.core.entity import Entity from conkit.core.mappings import AminoAcidOneToThree, AminoAcidThreeToOne, ContactMatchState from conkit.misc import deprecate -class Contact(_Entity): +class Contact(Entity): """A contact pair template to store all associated information Attributes diff --git a/conkit/core/contactfile.py b/conkit/core/contactfile.py index 01a42c07..8f9269ed 100644 --- a/conkit/core/contactfile.py +++ b/conkit/core/contactfile.py @@ -38,10 +38,10 @@ __date__ = "03 Aug 2016" __version__ = "1.0" -from conkit.core._entity import _Entity +from conkit.core.entity import Entity -class ContactFile(_Entity): +class ContactFile(Entity): """A contact file object representing a single prediction file The contact file class represents a data structure to hold all predictions @@ -89,9 +89,7 @@ def __init__(self, id): super(ContactFile, self).__init__(id) def __repr__(self): - return "{0}(id=\"{1}\" nmaps={2})".format( - self.__class__.__name__, self.id, len(self) - ) + return "{0}(id=\"{1}\" nmaps={2})".format(self.__class__.__name__, self.id, len(self)) @property def author(self): diff --git a/conkit/core/contactmap.py b/conkit/core/contactmap.py index 640af90e..63877a22 100644 --- a/conkit/core/contactmap.py +++ b/conkit/core/contactmap.py @@ -46,14 +46,14 @@ if sys.version_info.major < 3: from itertools import izip as zip -from conkit.core._entity import _Entity -from conkit.core._struct import _Gap, _Residue +from conkit.core.entity import Entity +from conkit.core.struct import Gap, Residue from conkit.core.mappings import AminoAcidMapping, ContactMatchState from conkit.core.sequence import Sequence from conkit.misc import fAND, fOR, deprecate, normalize -class ContactMap(_Entity): +class ContactMap(Entity): """A contact map object representing a single prediction The :obj:`ContactMap ` class represents a data structure to hold a single @@ -278,8 +278,8 @@ def recall(self): determined by running the :func:`match ` function providing a reference structure. - Notes - ----- + Note + ---- To determine and **save** the false negatives, please use the `add_false_negatives` keyword when running the :func:`match ` function. @@ -531,13 +531,13 @@ def get_jaccard_index(self, other): -------- match, precision - Warnings - -------- + Warning + ------- The Jaccard distance ranges from :math:`[0, 1]`, where :math:`1` means the maps contain identical contacts pairs. - Notes - ----- + Note + ---- The Jaccard index is different from the Jaccard distance mentioned in [#]_. The Jaccard distance corresponds to :math:`1-Jaccard_{index}`. @@ -762,7 +762,7 @@ def match(self, _id = (contact.res1_seq, contact.res2_seq) _id_alt = tuple(r.res_seq for r in contact_map2_keymap for i in _id if i == r.res_altseq) - if any(i == _Gap.IDENTIFIER for i in _id_alt) and any(j not in residues_map2 for j in _id): + if any(i == Gap.IDENTIFIER for i in _id_alt) and any(j not in residues_map2 for j in _id): contact_map1[_id].status = ContactMatchState.unknown elif all(i in residues_map2 for i in _id): if _id_alt in contact_map2: @@ -957,7 +957,7 @@ def to_string(self): @staticmethod def _adjust(contact_map, keymap): """Adjust res_altseq entries to insertions and deletions""" - encoder = dict((x.res_seq, x.res_altseq) for x in keymap if isinstance(x, _Residue)) + encoder = dict((x.res_seq, x.res_altseq) for x in keymap if isinstance(x, Residue)) for contact in contact_map: if contact.res1_seq in encoder: contact.res1_altseq = encoder[contact.res1_seq] @@ -982,8 +982,8 @@ def _create_keymap(contact_map, altloc=False): """ contact_map_keymap = collections.OrderedDict() for contact in contact_map: - pos1 = _Residue(contact.res1_seq, contact.res1_altseq, contact.res1, contact.res1_chain) - pos2 = _Residue(contact.res2_seq, contact.res2_altseq, contact.res2, contact.res2_chain) + pos1 = Residue(contact.res1_seq, contact.res1_altseq, contact.res1, contact.res1_chain) + pos2 = Residue(contact.res2_seq, contact.res2_altseq, contact.res2, contact.res2_chain) if altloc: res1_index, res2_index = contact.res1_altseq, contact.res2_altseq else: @@ -1007,7 +1007,7 @@ def _insert_states(sequence, keymap): keymap_ = [] for amino_acid in sequence: if amino_acid == ord('-'): - keymap_.append(_Gap()) + keymap_.append(Gap()) else: keymap_.append(next(it)) return keymap_ @@ -1023,7 +1023,7 @@ def _reindex_by_keymap(keymap): def _renumber(contact_map, self_keymap, other_keymap): """Renumber the contact map based on the mapping of self and other keymaps""" for self_residue, other_residue in zip(self_keymap, other_keymap): - if isinstance(self_residue, _Gap): + if isinstance(self_residue, Gap): continue for contact in ContactMap._find_single(contact_map, self_residue.res_seq): # Make sure we check with the ID, which doesn't change diff --git a/conkit/core/_entity.py b/conkit/core/entity.py similarity index 82% rename from conkit/core/_entity.py rename to conkit/core/entity.py index d7f785e2..33b77ef4 100644 --- a/conkit/core/_entity.py +++ b/conkit/core/entity.py @@ -42,7 +42,7 @@ import operator -class _Entity(object): +class Entity(object): """Base class for all entities used in this interface. It handles the storage of data. It also provides a high-efficiency @@ -50,29 +50,29 @@ class _Entity(object): provides a hierarchical structure to remember parent and child entities. + Warning + ------- + It is strongly advised against the use of the :obj:`~conkit.core.entity.Entity` class directly. + Instead, use one or more of the the remaining data models. + Attributes ---------- id : str, list, tuple The ID of the selected entity full_id : tuple A traceback id including all parent classes - parent : :obj:`Entity ` - An attribute to store the reference to the parent :obj:`Entity ` + parent : :obj:`~conkit.core.entity.Entity` + An attribute to store the reference to the parent :obj:`~conkit.core.entity.Entity` child_list : list A list storing the child entities child_dict : dict A dictionary storing the child entities - Notes - ----- - It is strongly advised against the use of the :obj:`Entity ` class directly. - Instead, use one or more of the the remaining data models. - """ __slots__ = ['_id', '_parent', '_child_list', '_child_dict'] def __init__(self, id): - """Initialise a generic :obj:`Entity ` + """Initialise a generic :obj:`~conkit.core.entity.Entity` Parameters ---------- @@ -162,15 +162,15 @@ def full_id(self): """A traceback id including all parent classes The full id is a tuple containing all id's starting from - the top object (:obj:`ContactFile `) down to the current object. - A full id for a :obj:`Contact ` e.g. is something like: + the top object (:obj:`~conkit.core.contactfile.ContactFile`) down to the current object. + A full id for a :obj:`~conkit.core.contact.Contact` e.g. is something like: ('1aa', 1, (1, 10)) This corresponds to: - :obj:`ContactFile ` identifier => 1aaa - :obj:`ContactMap ` identifier => 1 - :obj:`Contact ` identifier => (1, 10) + :obj:`~conkit.core.contactfile.ContactFile` identifier => 1aaa + :obj:`~conkit.core.contactmap.ContactMap` identifier => 1 + :obj:`~conkit.core.contact.Contact` identifier => (1, 10) """ traceback = [self.id] @@ -192,10 +192,10 @@ def id(self, id): Parameters ---------- id : str, list, tuple - The unique ID for an :obj:`Entity ` + The unique ID for an :obj:`~conkit.core.entity.Entity` - Warnings - -------- + Warning + ------- You cannot provide an :obj:`int` or :obj:`float` as ID. """ @@ -207,23 +207,23 @@ def id(self, id): @property def parent(self): - """An attribute to store the reference to the parent :obj:`Entity `""" + """An attribute to store the reference to the parent :obj:`~conkit.core.entity.Entity`""" return self._parent @parent.setter def parent(self, parent): - """Define the reference to the parent :obj:`Entity ` + """Define the reference to the parent :obj:`~conkit.core.entity.Entity` Parameters ---------- - parent : :obj:`Entity ` + parent : :obj:`~conkit.core.entity.Entity` """ self._parent = parent @property def top(self): - """The first child in the :obj:`Entity `""" + """The first child in the :obj:`~conkit.core.entity.Entity`""" if len(self) > 0: return self._child_list[0] else: @@ -243,17 +243,17 @@ def _inplace(self, inplace): return self.deepcopy() def _sort(self, kword, reverse): - """Sort the :obj:`Entity `""" + """Sort the :obj:`~conkit.core.entity.Entity`""" if any(not hasattr(e, kword) for e in self._child_list): raise ValueError('Attribute not defined') self.child_list.sort(key=operator.attrgetter(kword), reverse=reverse) def add(self, entity): - """Add a child to the :obj:`Entity ` + """Add a child to the :obj:`~conkit.core.entity.Entity` Parameters ---------- - entity : :obj:`Entity ` + entity : :obj:`~conkit.core.entity.Entity` """ if entity.id in self: @@ -263,7 +263,7 @@ def add(self, entity): self.child_dict[entity.id] = entity def copy(self): - """Create a shallow copy of :obj:`Entity `""" + """Create a shallow copy of :obj:`~conkit.core.entity.Entity`""" shallow = copy.copy(self) shallow.child_list = [] @@ -275,7 +275,7 @@ def copy(self): return shallow def deepcopy(self): - """Create a deep copy of :obj:`Entity `""" + """Create a deep copy of :obj:`~conkit.core.entity.Entity`""" deep = copy.deepcopy(self) deep.child_list = [] @@ -293,10 +293,11 @@ def remove(self, id): ---------- id : str, int, list, tuple - Warnings - -------- - If ``id`` is of type :obj:`int`, then the :obj:`Entity ` - in the ``child_list`` at index ``id`` will be deleted + Warning + ------- + If `id` is of type :obj:`int`, then the :obj:`~conkit.core.entity.Entity` + in the :attr:`~conkit.core.entity.Entity.child_list`` at index `id` will + be deleted """ del self[id] diff --git a/conkit/core/sequence.py b/conkit/core/sequence.py index e4376ba2..29bd4b46 100644 --- a/conkit/core/sequence.py +++ b/conkit/core/sequence.py @@ -39,11 +39,11 @@ __version__ = "1.0" from Bio import pairwise2 -from conkit.core._entity import _Entity +from conkit.core.entity import Entity from conkit.core.mappings import AminoAcidMapping, AminoAcidOneToThree -class Sequence(_Entity): +class Sequence(Entity): """A sequence template to store all associated information Attributes @@ -98,8 +98,8 @@ def __repr__(self): seq_string = ''.join([self.seq[:5], '...', self.seq[-5:]]) else: seq_string = self.seq - return "{0}(id=\"{1}\" seq=\"{2}\" seq_len={3})".format( - self.__class__.__name__, self.id, seq_string, self.seq_len) + return "{0}(id=\"{1}\" seq=\"{2}\" seq_len={3})".format(self.__class__.__name__, self.id, seq_string, + self.seq_len) @property def remark(self): @@ -186,9 +186,8 @@ def align_global(self, other, id_chars=2, nonid_chars=1, gap_open_pen=-0.5, gap_ sequence1 = self._inplace(inplace) sequence2 = other._inplace(inplace) - alignment = pairwise2.align.globalms( - sequence1.seq, sequence2.seq, id_chars, nonid_chars, gap_open_pen, gap_ext_pen - ) + alignment = pairwise2.align.globalms(sequence1.seq, sequence2.seq, id_chars, nonid_chars, gap_open_pen, + gap_ext_pen) sequence1.seq = alignment[-1][0] sequence2.seq = alignment[-1][1] @@ -218,9 +217,8 @@ def align_local(self, other, id_chars=2, nonid_chars=1, gap_open_pen=-0.5, gap_e sequence1 = self._inplace(inplace) sequence2 = other._inplace(inplace) - alignment = pairwise2.align.localms( - sequence1.seq, sequence2.seq, id_chars, nonid_chars, gap_open_pen, gap_ext_pen - ) + alignment = pairwise2.align.localms(sequence1.seq, sequence2.seq, id_chars, nonid_chars, gap_open_pen, + gap_ext_pen) sequence1.seq = alignment[-1][0] sequence2.seq = alignment[-1][1] diff --git a/conkit/core/sequencefile.py b/conkit/core/sequencefile.py index c23a9dec..d774cc13 100644 --- a/conkit/core/sequencefile.py +++ b/conkit/core/sequencefile.py @@ -45,12 +45,12 @@ if sys.version_info.major < 3: from itertools import izip as zip -from conkit.core._entity import _Entity +from conkit.core.entity import Entity from conkit.core.mappings import AminoAcidMapping, SequenceAlignmentState from conkit.misc import deprecate -class SequenceFile(_Entity): +class SequenceFile(Entity): """A sequence file object representing a single sequence file The :obj:`~conkit.core.sequencefile.SequenceFile` class represents a data structure to hold diff --git a/conkit/core/_struct.py b/conkit/core/struct.py similarity index 95% rename from conkit/core/_struct.py rename to conkit/core/struct.py index 95922506..45de4ab3 100644 --- a/conkit/core/_struct.py +++ b/conkit/core/struct.py @@ -46,19 +46,19 @@ def __repr__(self): return string.format(name=self.__class__.__name__, **{k: getattr(self, k) for k in self.__class__.__slots__}) -class _Gap(_Struct): +class Gap(_Struct): """A basic class representing a gap residue""" IDENTIFIER = -999999 def __init__(self): - self.res_seq = _Gap.IDENTIFIER - self.res_altseq = _Gap.IDENTIFIER + self.res_seq = Gap.IDENTIFIER + self.res_altseq = Gap.IDENTIFIER self.res_name = 'X' self.res_chain = '' -class _Residue(_Struct): +class Residue(_Struct): """A basic class representing a residue""" def __init__(self, res_seq, res_altseq, res_name, res_chain): diff --git a/conkit/core/tests/test__entity.py b/conkit/core/tests/test__entity.py index b918a36e..ae4cfc31 100644 --- a/conkit/core/tests/test__entity.py +++ b/conkit/core/tests/test__entity.py @@ -1,38 +1,37 @@ -"""Testing facility for conkit.core._Entity""" +"""Testing facility for conkit.core.Entity""" __author__ = "Felix Simkovic" __date__ = "12 Aug 2016" import unittest -from conkit.core._entity import _Entity +from conkit.core.entity import Entity -class Test_Entity(unittest.TestCase): - +class TestEntity(unittest.TestCase): def test_contains_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) self.assertTrue('foo' in entity) def test_contains_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) self.assertTrue('foo' in entity) self.assertTrue('bar' in entity) self.assertFalse('cho' in entity) def test_delitem_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) del entity['foo'] self.assertFalse('foo' in entity) def test_delitem_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) del entity['foo'] self.assertFalse('foo' in entity) self.assertTrue('bar' in entity) @@ -40,45 +39,45 @@ def test_delitem_2(self): self.assertFalse('bar' in entity) def test_delitem_3(self): - entity = _Entity('test') + entity = Entity('test') with self.assertRaises(KeyError): del entity['foo'] def test_getitem_1(self): - entity = _Entity('test') - child_entity = _Entity('foo') + entity = Entity('test') + child_entity = Entity('foo') entity.add(child_entity) self.assertEqual(child_entity, entity['foo']) def test_getitem_2(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') - child_entity2 = _Entity('bar') + entity = Entity('test') + child_entity1 = Entity('foo') + child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(child_entity1, entity['foo']) self.assertEqual(child_entity2, entity['bar']) def test_getitem_3(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') - child_entity2 = _Entity('bar') + entity = Entity('test') + child_entity1 = Entity('foo') + child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(child_entity1, entity['foo']) self.assertEqual(child_entity2, entity['bar']) def test_getitem_4(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') + entity = Entity('test') + child_entity1 = Entity('foo') entity.add(child_entity1) self.assertEqual(child_entity1, entity[0]) def test_getitem_5(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') - child_entity2 = _Entity('bar') - child_entity3 = _Entity('cho') + entity = Entity('test') + child_entity1 = Entity('foo') + child_entity2 = Entity('bar') + child_entity3 = Entity('cho') entity.add(child_entity1) entity.add(child_entity2) entity.add(child_entity3) @@ -88,124 +87,124 @@ def test_getitem_5(self): self.assertEqual(child_entity3, entity[-1]) def test_getitem_6(self): - entity = _Entity('test') + entity = Entity('test') for i in range(10): - entity.add(_Entity('foo_{0}'.format(i))) + entity.add(Entity('foo_{0}'.format(i))) new_entity = entity[:5] self.assertEqual(type(entity), type(new_entity)) self.assertEqual(5, len(new_entity)) self.assertEqual(['foo_0', 'foo_1', 'foo_2', 'foo_3', 'foo_4'], [e.id for e in new_entity]) def test_getitem_7(self): - entity = _Entity('test') + entity = Entity('test') for i in range(10): - entity.add(_Entity('foo_{0}'.format(i))) + entity.add(Entity('foo_{0}'.format(i))) new_entity = entity[1::2] self.assertEqual(type(entity), type(new_entity)) self.assertEqual(5, len(new_entity)) self.assertEqual(['foo_1', 'foo_3', 'foo_5', 'foo_7', 'foo_9'], [e.id for e in new_entity]) def test_iter_1(self): - entity = _Entity('test') + entity = Entity('test') for i in range(10): - entity.add(_Entity('foo_{0}'.format(i))) + entity.add(Entity('foo_{0}'.format(i))) for i, e in enumerate(entity): self.assertEqual('foo_{0}'.format(i), e.id) def test_len_1(self): - entity = _Entity('test') + entity = Entity('test') for i in range(10): - entity.add(_Entity('foo_{0}'.format(i))) + entity.add(Entity('foo_{0}'.format(i))) self.assertEqual(10, len(entity)) def test_len_2(self): - entity = _Entity('test') + entity = Entity('test') self.assertEqual(0, len(entity)) def test_reversed_1(self): - entity = _Entity('test') + entity = Entity('test') for i in range(10): - entity.add(_Entity('foo_{0}'.format(i))) + entity.add(Entity('foo_{0}'.format(i))) rev = list(reversed(list(range(10)))) for i, e in enumerate(reversed(entity)): self.assertNotEqual('foo_{0}'.format(i), e.id) self.assertEqual('foo_{0}'.format(rev[i]), e.id) def test_child_list_1(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') + entity = Entity('test') + child_entity1 = Entity('foo') entity.add(child_entity1) self.assertEqual(1, len(entity.child_list)) self.assertEqual([child_entity1], entity.child_list) def test_child_list_2(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') - child_entity2 = _Entity('bar') + entity = Entity('test') + child_entity1 = Entity('foo') + child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(2, len(entity.child_list)) self.assertEqual([child_entity1, child_entity2], entity.child_list) def test_child_dict_1(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') + entity = Entity('test') + child_entity1 = Entity('foo') entity.add(child_entity1) self.assertDictEqual({'foo': child_entity1}, entity.child_dict) def test_child_dict_2(self): - entity = _Entity('test') - child_entity1 = _Entity('foo') - child_entity2 = _Entity('bar') + entity = Entity('test') + child_entity1 = Entity('foo') + child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertDictEqual({'foo': child_entity1, 'bar': child_entity2}, entity.child_dict) def test_full_id_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) self.assertEqual(('test', 'foo'), entity[0].full_id) def test_full_id_2(self): - entity = _Entity('test') - self.assertEqual(('test',), entity.full_id) + entity = Entity('test') + self.assertEqual(('test', ), entity.full_id) def test_full_id_3(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity[0].add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity[0].add(Entity('bar')) self.assertEqual(('test', 'foo', 'bar'), entity[0][0].full_id) def test_full_id_4(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity[0].add(_Entity('bar')) - entity[0].add(_Entity('cho')) + entity = Entity('test') + entity.add(Entity('foo')) + entity[0].add(Entity('bar')) + entity[0].add(Entity('cho')) self.assertEqual(('test', 'foo', 'bar'), entity[0][0].full_id) self.assertEqual(('test', 'foo', 'cho'), entity[0][1].full_id) def test_id_1(self): - entity = _Entity('test') + entity = Entity('test') self.assertEqual('test', entity.id) def test_id_2(self): - entity = _Entity((1, 2)) + entity = Entity((1, 2)) self.assertEqual((1, 2), entity.id) def test_id_3(self): - entity = _Entity([1, 2]) + entity = Entity([1, 2]) self.assertEqual((1, 2), entity.id) def test_id_4(self): - entity = _Entity((1., 2.)) + entity = Entity((1., 2.)) self.assertEqual((1., 2.), entity.id) def test_parent_1(self): - entity = _Entity('test') - child_entity = _Entity('foo') + entity = Entity('test') + child_entity = Entity('foo') entity.add(child_entity) - child_child_entity1 = _Entity('bar') - child_child_entity2 = _Entity('cho') + child_child_entity1 = Entity('bar') + child_child_entity2 = Entity('cho') child_entity.add(child_child_entity1) child_entity.add(child_child_entity2) self.assertEqual(entity, entity[0].parent) @@ -213,56 +212,56 @@ def test_parent_1(self): self.assertEqual(child_entity, entity[0][1].parent) def test__inplace_1(self): - entity = _Entity('foo') + entity = Entity('foo') entity_inplace = entity._inplace(True) self.assertEqual(entity, entity_inplace) def test__inplace_2(self): - entity = _Entity('foo') + entity = Entity('foo') entity_inplace = entity._inplace(False) self.assertNotEqual(entity, entity_inplace) def test__sort_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) entity._sort('id', False) self.assertEqual(['bar', 'foo'], [e.id for e in entity]) def test__sort_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) entity._sort('id', True) self.assertEqual(['foo', 'bar'], [e.id for e in entity]) def test__sort_3(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) with self.assertRaises(ValueError): entity._sort('test', True) def test_add_1(self): - entity = _Entity('test') + entity = Entity('test') self.assertFalse('foo' in entity.child_dict) - child_entity = _Entity('foo') + child_entity = Entity('foo') entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue('foo' in entity.child_dict) def test_add_2(self): - entity = _Entity('test') - child_entity = _Entity('foo') + entity = Entity('test') + child_entity = Entity('foo') entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue('foo' in entity.child_dict) with self.assertRaises(ValueError): - entity.add(_Entity('foo')) + entity.add(Entity('foo')) def test_copy_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) shallow = entity.copy() self.assertNotEqual(entity, shallow) self.assertTrue(entity.id, shallow.id) @@ -270,8 +269,8 @@ def test_copy_1(self): self.assertEqual(entity[0].id, shallow[0].id) def test_copy_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) shallow = entity[0].copy() self.assertNotEqual(entity[0], shallow) self.assertEqual(entity[0].id, shallow.id) @@ -279,8 +278,8 @@ def test_copy_2(self): self.assertEqual('foo', entity[0].id) def test_deepcopy_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) deep = entity.deepcopy() self.assertNotEqual(entity, deep) self.assertTrue(entity.id, deep.id) @@ -288,8 +287,8 @@ def test_deepcopy_1(self): self.assertEqual(entity[0].id, deep[0].id) def test_deepcopy_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) deep = entity[0].deepcopy() self.assertNotEqual(entity[0], deep) self.assertEqual(entity[0].id, deep.id) @@ -297,15 +296,15 @@ def test_deepcopy_2(self): self.assertEqual('foo', entity[0].id) def test_remove_1(self): - entity = _Entity('test') - entity.add(_Entity('foo')) + entity = Entity('test') + entity.add(Entity('foo')) entity.remove('foo') self.assertFalse('foo' in entity) def test_remove_2(self): - entity = _Entity('test') - entity.add(_Entity('foo')) - entity.add(_Entity('bar')) + entity = Entity('test') + entity.add(Entity('foo')) + entity.add(Entity('bar')) entity.remove('foo') self.assertFalse('foo' in entity) self.assertTrue('bar' in entity) @@ -313,7 +312,7 @@ def test_remove_2(self): self.assertFalse('bar' in entity) def test_remove_3(self): - entity = _Entity('test') + entity = Entity('test') with self.assertRaises(KeyError): entity.remove('foo') diff --git a/conkit/core/tests/test_contactmap.py b/conkit/core/tests/test_contactmap.py index dfc3d797..5b347c38 100644 --- a/conkit/core/tests/test_contactmap.py +++ b/conkit/core/tests/test_contactmap.py @@ -11,7 +11,7 @@ except ImportError: SKLEARN = False -from conkit.core._struct import _Gap, _Residue +from conkit.core.struct import Gap, Residue from conkit.core.contact import Contact from conkit.core.contactmap import ContactMap from conkit.core.mappings import ContactMatchState @@ -597,9 +597,9 @@ def test_match_7(self): contact_map1.match(contact_map2, renumber=True, inplace=True) self.assertEqual([TP, TP, FP, TP, UNK], [c.status for c in contact_map1]) - self.assertEqual([95, 95, _Gap.IDENTIFIER, 97, _Gap.IDENTIFIER], [c.res1_seq for c in contact_map1]) + self.assertEqual([95, 95, Gap.IDENTIFIER, 97, Gap.IDENTIFIER], [c.res1_seq for c in contact_map1]) self.assertEqual(['A', 'A', '', 'A', ''], [c.res1_chain for c in contact_map1]) - self.assertEqual([30, 31, _Gap.IDENTIFIER, 30, _Gap.IDENTIFIER], [c.res2_seq for c in contact_map1]) + self.assertEqual([30, 31, Gap.IDENTIFIER, 30, Gap.IDENTIFIER], [c.res2_seq for c in contact_map1]) self.assertEqual(['B', 'B', '', 'B', ''], [c.res2_chain for c in contact_map1]) def test_match_8(self): @@ -638,9 +638,9 @@ def test_match_8(self): contact_map1.match(contact_map2, remove_unmatched=True, renumber=True, inplace=True) self.assertEqual([TP, TP, FP, TP], [c.status for c in contact_map1]) - self.assertEqual([95, 95, _Gap.IDENTIFIER, 97], [c.res1_seq for c in contact_map1]) + self.assertEqual([95, 95, Gap.IDENTIFIER, 97], [c.res1_seq for c in contact_map1]) self.assertEqual(['A', 'A', '', 'A'], [c.res1_chain for c in contact_map1]) - self.assertEqual([30, 31, _Gap.IDENTIFIER, 30], [c.res2_seq for c in contact_map1]) + self.assertEqual([30, 31, Gap.IDENTIFIER, 30], [c.res2_seq for c in contact_map1]) self.assertEqual(['B', 'B', '', 'B'], [c.res2_chain for c in contact_map1]) def test_match_9(self): @@ -741,7 +741,7 @@ def test_match_10(self): contact_map1.match(contact_map2, renumber=True, inplace=True) self.assertEqual([TP, FP, TP, TP, FP], [c.status for c in contact_map1]) - self.assertEqual([(6, 2), (6, _Gap.IDENTIFIER), (7, 4), (8, 2), (7, _Gap.IDENTIFIER)], + self.assertEqual([(6, 2), (6, Gap.IDENTIFIER), (7, 4), (8, 2), (7, Gap.IDENTIFIER)], [(c.res1_seq, c.res2_seq) for c in contact_map1]) self.assertEqual([('A', 'B'), ('A', ''), ('A', 'B'), ('A', 'B'), ('A', '')], [(c.res1_chain, c.res2_chain) for c in contact_map1]) @@ -988,59 +988,58 @@ def test__find_single_2(self): self.assertEqual([(2, 4)], [c.id for c in found_contacts]) def test__insert_states_1(self): - keymap = [_Residue(1, 1, 'X', ''), _Residue(2, 2, 'X', ''), _Residue(3, 3, 'X', '')] + keymap = [Residue(1, 1, 'X', ''), Residue(2, 2, 'X', ''), Residue(3, 3, 'X', '')] sequence = [ord(x) for x in 'XXX'] inserts_added = ContactMap._insert_states(sequence, keymap) self.assertEqual(3, len(inserts_added)) - self.assertEqual([True, True, True], [isinstance(r, _Residue) for r in inserts_added]) + self.assertEqual([True, True, True], [isinstance(r, Residue) for r in inserts_added]) def test__insert_states_2(self): - keymap = [_Residue(2, 2, 'X', ''), _Residue(3, 3, 'X', '')] + keymap = [Residue(2, 2, 'X', ''), Residue(3, 3, 'X', '')] sequence = [ord(x) for x in '-XX'] inserts_added = ContactMap._insert_states(sequence, keymap) self.assertEqual(3, len(inserts_added)) - self.assertEqual([False, True, True], [isinstance(r, _Residue) for r in inserts_added]) - self.assertEqual([True, False, False], [isinstance(r, _Gap) for r in inserts_added]) + self.assertEqual([False, True, True], [isinstance(r, Residue) for r in inserts_added]) + self.assertEqual([True, False, False], [isinstance(r, Gap) for r in inserts_added]) def test__insert_states_3(self): - keymap = [_Residue(2, 10, 'X', ''), _Residue(3, 11, 'X', '')] + keymap = [Residue(2, 10, 'X', ''), Residue(3, 11, 'X', '')] sequence = [ord(x) for x in '-X-X--'] inserts_added = ContactMap._insert_states(sequence, keymap) self.assertEqual(6, len(inserts_added)) - self.assertEqual([False, True, False, True, False, False], [isinstance(r, _Residue) for r in inserts_added]) - self.assertEqual([True, False, True, False, True, True], [isinstance(r, _Gap) for r in inserts_added]) - self.assertEqual([2, 3], [r.res_seq for r in inserts_added if isinstance(r, _Residue)]) - self.assertEqual([10, 11], [r.res_altseq for r in inserts_added if isinstance(r, _Residue)]) + self.assertEqual([False, True, False, True, False, False], [isinstance(r, Residue) for r in inserts_added]) + self.assertEqual([True, False, True, False, True, True], [isinstance(r, Gap) for r in inserts_added]) + self.assertEqual([2, 3], [r.res_seq for r in inserts_added if isinstance(r, Residue)]) + self.assertEqual([10, 11], [r.res_altseq for r in inserts_added if isinstance(r, Residue)]) def test__reindex_by_keymap_1(self): - keymap = [_Residue(1, 1, 'X', ''), _Residue(2, 2, 'X', ''), _Residue(3, 3, 'X', '')] + keymap = [Residue(1, 1, 'X', ''), Residue(2, 2, 'X', ''), Residue(3, 3, 'X', '')] reindex = ContactMap._reindex_by_keymap(keymap) self.assertEqual([1, 2, 3], [c.res_seq for c in reindex]) self.assertEqual([1, 2, 3], [c.res_altseq for c in reindex]) def test__reindex_by_keymap_2(self): - keymap = [_Residue(1, -5, 'X', ''), _Residue(2, -4, 'X', ''), _Residue(3, -3, 'X', '')] + keymap = [Residue(1, -5, 'X', ''), Residue(2, -4, 'X', ''), Residue(3, -3, 'X', '')] reindex = ContactMap._reindex_by_keymap(keymap) self.assertEqual([1, 2, 3], [c.res_seq for c in reindex]) self.assertEqual([1, 2, 3], [c.res_altseq for c in reindex]) def test__reindex_by_keymap_3(self): - keymap = [_Gap(), _Residue(2, 1, 'X', ''), _Residue(3, 2, 'X', '')] + keymap = [Gap(), Residue(2, 1, 'X', ''), Residue(3, 2, 'X', '')] reindex = ContactMap._reindex_by_keymap(keymap) - self.assertEqual([_Gap.IDENTIFIER, 2, 3], [c.res_seq for c in reindex]) + self.assertEqual([Gap.IDENTIFIER, 2, 3], [c.res_seq for c in reindex]) self.assertEqual([1, 2, 3], [c.res_altseq for c in reindex]) def test__reindex_by_keymap_4(self): - keymap = [_Gap(), _Residue(200000, 10000, 'X', ''), _Gap(), _Gap()] + keymap = [Gap(), Residue(200000, 10000, 'X', ''), Gap(), Gap()] reindex = ContactMap._reindex_by_keymap(keymap) - self.assertEqual([_Gap.IDENTIFIER, 200000, _Gap.IDENTIFIER, _Gap.IDENTIFIER], [c.res_seq for c in reindex]) + self.assertEqual([Gap.IDENTIFIER, 200000, Gap.IDENTIFIER, Gap.IDENTIFIER], [c.res_seq for c in reindex]) self.assertEqual([1, 2, 3, 4], [c.res_altseq for c in reindex]) def test__reindex_by_keymap_5(self): - keymap = [_Gap(), _Gap(), _Gap(), _Gap()] + keymap = [Gap(), Gap(), Gap(), Gap()] reindex = ContactMap._reindex_by_keymap(keymap) - self.assertEqual([_Gap.IDENTIFIER, _Gap.IDENTIFIER, _Gap.IDENTIFIER, _Gap.IDENTIFIER], - [c.res_seq for c in reindex]) + self.assertEqual([Gap.IDENTIFIER, Gap.IDENTIFIER, Gap.IDENTIFIER, Gap.IDENTIFIER], [c.res_seq for c in reindex]) self.assertEqual([1, 2, 3, 4], [c.res_altseq for c in reindex]) def test_as_list_1(self): diff --git a/conkit/io/__init__.py b/conkit/io/__init__.py index 6d4f438c..4e815239 100644 --- a/conkit/io/__init__.py +++ b/conkit/io/__init__.py @@ -64,8 +64,8 @@ def convert(fname_in, format_in, fname_out, format_out): >>> with open('example.a3m', 'r') as f_in, open('example.fas', 'w') as f_out: ... io.convert(f_in, 'a3m', f_out, 'fasta') - Notes - ----- + Note + ---- A3M format comes by default WITHOUT insert states, these are removed. To obtain an alignment WITH insert states, use format ``a3m-inserts``. diff --git a/conkit/io/_iotools.py b/conkit/io/_iotools.py index da686ab2..2f4fd777 100644 --- a/conkit/io/_iotools.py +++ b/conkit/io/_iotools.py @@ -76,9 +76,9 @@ def is_str_like(content): bool True if is str like else False - Notes - ----- - Function taken from Numpy, credits to the author + Note + ---- + Function identical to :func:`numpy.is_str_like`, credits to the author """ try: @@ -105,16 +105,15 @@ def open_f_handle(f_handle, mode): Raises ------ - TypeError + :obj:`TypeError` f_handle must be str of filehandle - ValueError + :obj:`ValueError` Mode needs to be one of: append, read, write """ - # Check the mode of opening the file if mode not in ['append', 'read', 'write']: raise ValueError('Mode needs to be one of: append, read, write') - + try: if is_str_like(f_handle) and sys.version_info.major >= 3: return io.open(f_handle, mode[0], encoding="utf-8") @@ -126,4 +125,3 @@ def open_f_handle(f_handle, mode): raise TypeError("f_handle must be str or filehandle") except AttributeError: raise TypeError("f_handle must be str or filehandle") - diff --git a/conkit/io/a3m.py b/conkit/io/a3m.py index 2d8ad8d1..c855cce9 100644 --- a/conkit/io/a3m.py +++ b/conkit/io/a3m.py @@ -72,7 +72,7 @@ def read(self, f_handle, f_id='a3m', remove_inserts=True): Returns ------- - :obj:`SequenceFile ` + :obj:`~conkit.core.sequencefile.SequenceFile` """ @@ -164,7 +164,7 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`SequenceFile `, :obj:`Sequence ` + hierarchy : :obj:`~conkit.core.sequencefile.SequenceFile`, :obj:`~conkit.core.sequence.Sequence` """ # Double check the type of hierarchy and reconstruct if necessary diff --git a/conkit/io/bbcontacts.py b/conkit/io/bbcontacts.py index c21ac69c..f92a4c51 100644 --- a/conkit/io/bbcontacts.py +++ b/conkit/io/bbcontacts.py @@ -64,7 +64,7 @@ def read(self, f_handle, f_id="bbcontacts", del_one_two=False): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -77,16 +77,13 @@ def read(self, f_handle, f_id="bbcontacts", del_one_two=False): line = line.strip() if line and not line.startswith('#'): - _, _, _, raw_score, _, current, res2_seq, res1_seq = line.split( - ) + _, _, _, raw_score, _, current, res2_seq, res1_seq = line.split() if del_one_two and previous == 'first' and current == 'last': contact_map.child_list.pop() - elif any(value == "NA" - for value in [raw_score, res2_seq, res1_seq]): + elif any(value == "NA" for value in [raw_score, res2_seq, res1_seq]): pass else: - contact = Contact( - int(res1_seq), int(res2_seq), float(raw_score)) + contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact_map.add(contact) previous = current @@ -104,20 +101,18 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` - Notes - ----- - Creating a :func:`write` function for the Bbcontacts parser + Note + ---- + Creating a :meth:`~conkit.io.bbcontacts.BbcontactsParser.write` method would come with a lot of issues, such as the parallel/antiparallel - direction, scoring etc. - - Thus, no :func:`write` method is available. + direction, scoring etc ... thus, this function is unvailable. Raises ------ - NotImplementedError + :obj:`NotImplementedError` Write function not available """ diff --git a/conkit/io/bclcontact.py b/conkit/io/bclcontact.py index 18f610a6..aa8bcbfb 100644 --- a/conkit/io/bclcontact.py +++ b/conkit/io/bclcontact.py @@ -48,6 +48,7 @@ class BCLContactParser(ContactFileParser): """Class to parse a BCL::Contact contact file """ + def __init__(self): super(BCLContactParser, self).__init__() @@ -63,7 +64,7 @@ def read(self, f_handle, f_id="bclcontact"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -90,14 +91,13 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - NotImplementedError + :obj:`NotImplementedError` Write function not available """ raise NotImplementedError("Write function not available") - diff --git a/conkit/io/casp.py b/conkit/io/casp.py index c38c09ba..c1db8316 100644 --- a/conkit/io/casp.py +++ b/conkit/io/casp.py @@ -60,8 +60,9 @@ # Intermediate storage structures ModelTemplate = collections.namedtuple('Model', ['id', 'contacts', 'sequence']) -ContactTemplate = collections.namedtuple('Contact', ['res1_seq', 'res2_seq', 'lb', 'ub', 'raw_score', - 'res1_chain', 'res2_chain', 'res1_altseq', 'res2_altseq']) +ContactTemplate = collections.namedtuple( + 'Contact', + ['res1_seq', 'res2_seq', 'lb', 'ub', 'raw_score', 'res1_chain', 'res2_chain', 'res1_altseq', 'res2_altseq']) class CaspParser(ContactFileParser): @@ -71,7 +72,7 @@ def __init__(self): super(CaspParser, self).__init__() def read(self, f_handle, f_id="casp"): - """Read a contact file into a :obj:`conkit.core.contactfile.ContactFile` instance + """Read a contact file into a :obj:`~conkit.core.contactfile.ContactFile` instance Parameters ---------- @@ -82,7 +83,7 @@ def read(self, f_handle, f_id="casp"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ lines = [l.strip() for l in f_handle.readlines()] @@ -152,8 +153,8 @@ def read(self, f_handle, f_id="casp"): elif len(res2_split) == 4: res2_chain, res2_seq = res2_split[1], res2_split[2] - contact = Contact(int(res1_seq), int(res2_seq), float(raw_score), - distance_bound=(float(lb), float(ub))) + contact = Contact( + int(res1_seq), int(res2_seq), float(raw_score), distance_bound=(float(lb), float(ub))) contact.res1_chain = res1_chain contact.res2_chain = res2_chain contact.res1_altseq = int(res1_seq) @@ -182,8 +183,8 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` """ @@ -208,7 +209,7 @@ def write(self, f_handle, hierarchy): if isinstance(contact_map.sequence, Sequence): sequence = contact_map.sequence for i in range(0, sequence.seq_len, 50): - content += sequence.seq[i:i+50] + os.linesep + content += sequence.seq[i:i + 50] + os.linesep # Casp Roll format specifies raw scores to be in [0, 1] if any(c.raw_score > 1.0 or c.raw_score < 0.0 for c in contact_map): contact_map.rescale(inplace=True) @@ -221,8 +222,14 @@ def write(self, f_handle, hierarchy): res2_chain = contact.res2_chain lb = int(contact.lower_bound) if float(contact.lower_bound).is_integer() else contact.lower_bound ub = int(contact.upper_bound) if float(contact.upper_bound).is_integer() else contact.upper_bound - s = s.format(res1_chain=res1_chain, res1_seq=contact.res1_seq, res2_chain=res2_chain, - res2_seq=contact.res2_seq, lb=lb, ub=ub, raw_score=contact.raw_score) + s = s.format( + res1_chain=res1_chain, + res1_seq=contact.res1_seq, + res2_chain=res2_chain, + res2_seq=contact.res2_seq, + lb=lb, + ub=ub, + raw_score=contact.raw_score) content += s + os.linesep content += "ENDMDL" + os.linesep diff --git a/conkit/io/ccmpred.py b/conkit/io/ccmpred.py index fc455584..5167c7a1 100644 --- a/conkit/io/ccmpred.py +++ b/conkit/io/ccmpred.py @@ -67,7 +67,7 @@ def read(self, f_handle, f_id="ccmpred"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ contact_file = ContactFile(f_id) @@ -93,12 +93,12 @@ def _get_contact_pairs(self, mat): Parameters ---------- - mat : np.ndarray - A np arranged matrix + mat : :obj:`~numpy.ndarray` + A :mod:`numpy` matrix Returns ------- - contacts : list + list A list of contact pairs """ @@ -114,15 +114,15 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy - TypeError - Python3 requires f_handle to be in 'wb' or 'ab' mode + :obj:`TypeError` + Python3 requires f_handle to be in `wb` or `ab` mode """ # Python3 support requires bytes mode diff --git a/conkit/io/comsat.py b/conkit/io/comsat.py index a7246e55..e8c59e85 100644 --- a/conkit/io/comsat.py +++ b/conkit/io/comsat.py @@ -49,6 +49,7 @@ class ComsatParser(ContactFileParser): """Class to parse a COMSAT contact file """ + def __init__(self): super(ComsatParser, self).__init__() @@ -64,7 +65,7 @@ def read(self, f_handle, f_id="comsat"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -80,11 +81,7 @@ def read(self, f_handle, f_id="comsat"): else: res1_seq, res1, res2_seq, res2, _ = RE_SPLIT.split(line) - contact = Contact( - int(res1_seq), - int(res2_seq), - 0.0 - ) + contact = Contact(int(res1_seq), int(res2_seq), 0.0) contact.res1 = res1 contact.res2 = res2 @@ -101,12 +98,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ @@ -121,8 +118,12 @@ def write(self, f_handle, hierarchy): for contact_map in contact_file: for contact in contact_map: line = "{res1_seq}{sep}{res1}{sep}{res2_seq}{sep}{res2}{sep}Hx-Hx" - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, - res1=contact.res1, res2=contact.res2, sep="\t") + line = line.format( + res1_seq=contact.res1_seq, + res2_seq=contact.res2_seq, + res1=contact.res1, + res2=contact.res2, + sep="\t") content += line + os.linesep f_handle.write(content) diff --git a/conkit/io/epcmap.py b/conkit/io/epcmap.py index f20cc66b..579cb473 100644 --- a/conkit/io/epcmap.py +++ b/conkit/io/epcmap.py @@ -46,6 +46,7 @@ class EPCMapParser(ContactFileParser): """Class to parse a EPC-Map contact prediction """ + def read(self, f_handle, f_id="epcmap"): """Read a contact file @@ -58,7 +59,7 @@ def read(self, f_handle, f_id="epcmap"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -73,8 +74,8 @@ def read(self, f_handle, f_id="epcmap"): continue elif line[0].isdigit(): - _contact = Contact(int(line[0]), int(line[1]), float(line[4]), - distance_bound=(float(line[2]), float(line[3]))) + _contact = Contact( + int(line[0]), int(line[1]), float(line[4]), distance_bound=(float(line[2]), float(line[3]))) _map.add(_contact) hierarchy.method = 'Contact map predicted using EPC-Map' @@ -88,12 +89,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ @@ -110,8 +111,8 @@ def write(self, f_handle, hierarchy): line = "{res1_seq} {res2_seq} {lb} {ub} {raw_score:.6f}" lb = int(contact.lower_bound) if float(contact.lower_bound).is_integer() else contact.lower_bound ub = int(contact.upper_bound) if float(contact.upper_bound).is_integer() else contact.upper_bound - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, raw_score=contact.raw_score, - lb=lb, ub=ub) + line = line.format( + res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, raw_score=contact.raw_score, lb=lb, ub=ub) content += line + os.linesep f_handle.write(content) diff --git a/conkit/io/evfold.py b/conkit/io/evfold.py index ffddad95..c86f00f7 100644 --- a/conkit/io/evfold.py +++ b/conkit/io/evfold.py @@ -49,6 +49,7 @@ class EVfoldParser(ContactFileParser): """Class to parse a EVfold contact file """ + def __init__(self): super(EVfoldParser, self).__init__() @@ -64,7 +65,7 @@ def read(self, f_handle, f_id="evfold"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -81,11 +82,7 @@ def read(self, f_handle, f_id="evfold"): else: res1_seq, res1, res2_seq, res2, _, raw_score = RE_SPLIT.split(line) - contact = Contact( - int(res1_seq), - int(res2_seq), - float(raw_score) - ) + contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact.res1 = res1 contact.res2 = res2 contact_map.add(contact) @@ -101,12 +98,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ @@ -121,8 +118,12 @@ def write(self, f_handle, hierarchy): for contact_map in contact_file: for contact in contact_map: line = "{res1_seq} {res1} {res2_seq} {res2} 0 {raw_score}" - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, - res1=contact.res1, res2=contact.res2, raw_score=contact.raw_score) + line = line.format( + res1_seq=contact.res1_seq, + res2_seq=contact.res2_seq, + res1=contact.res1, + res2=contact.res2, + raw_score=contact.raw_score) content += line + os.linesep f_handle.write(content) diff --git a/conkit/io/fasta.py b/conkit/io/fasta.py index 9db9c705..828e85cd 100644 --- a/conkit/io/fasta.py +++ b/conkit/io/fasta.py @@ -45,6 +45,7 @@ class FastaParser(SequenceFileParser): """Parser class for FASTA sequence files """ + def __init__(self): super(FastaParser, self).__init__() @@ -60,7 +61,7 @@ def read(self, f_handle, f_id='fasta'): Returns ------- - :obj:`SequenceFile ` + :obj:`~conkit.core.sequencefile.SequenceFile` """ @@ -83,7 +84,7 @@ def read(self, f_handle, f_id='fasta'): if not line.startswith('>'): raise ValueError("Fasta record needs to start with '>'") - id = line[1:] # Header without '>' + id = line[1:] # Header without '>' chunks = [] line = f_handle.readline().rstrip() @@ -94,7 +95,7 @@ def read(self, f_handle, f_id='fasta'): break chunks.append(line) line = f_handle.readline().rstrip() - _seq_string = "".join(chunks) # Sequence from chunks + _seq_string = "".join(chunks) # Sequence from chunks # Create the sequence record instance sequence_entry = Sequence(id, _seq_string) @@ -114,7 +115,7 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`SequenceFile `, :obj:`Sequence ` + hierarchy : :obj:`~conkit.core.sequencefile.SequenceFile`, :obj:`~conkit.core.sequence.Sequence` """ # Double check the type of hierarchy and reconstruct if necessary @@ -133,8 +134,8 @@ def write(self, f_handle, hierarchy): content += header + os.linesep # Cut the sequence into chunks [FASTA <= 60 chars per line] - sequence_string = sequence_entry.seq.upper() # UPPER CASE !!! + sequence_string = sequence_entry.seq.upper() # UPPER CASE !!! for i in range(0, sequence_entry.seq_len, 60): - content += sequence_string[i:i+60] + os.linesep + content += sequence_string[i:i + 60] + os.linesep f_handle.write(content) diff --git a/conkit/io/freecontact.py b/conkit/io/freecontact.py index 151f7bbd..76484c5d 100644 --- a/conkit/io/freecontact.py +++ b/conkit/io/freecontact.py @@ -49,6 +49,7 @@ class FreeContactParser(ContactFileParser): """Class to parse a FreeContact contact file """ + def __init__(self): super(FreeContactParser, self).__init__() @@ -64,7 +65,7 @@ def read(self, f_handle, f_id="freecontact"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -81,11 +82,7 @@ def read(self, f_handle, f_id="freecontact"): else: res1_seq, res1, res2_seq, res2, raw_score, _ = RE_SPLIT.split(line) - contact = Contact( - int(res1_seq), - int(res2_seq), - float(raw_score) - ) + contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact.res1 = res1 contact.res2 = res2 contact_map.add(contact) @@ -101,16 +98,15 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ - # Double check the type of hierarchy and reconstruct if necessary contact_file = self._reconstruct(hierarchy) if len(contact_file) > 1: @@ -121,8 +117,12 @@ def write(self, f_handle, hierarchy): for contact_map in contact_file: for contact in contact_map: line = "{res1_seq} {res1} {res2_seq} {res2} {raw_score} 0" - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, - res1=contact.res1, res2=contact.res2, raw_score=contact.raw_score) + line = line.format( + res1_seq=contact.res1_seq, + res2_seq=contact.res2_seq, + res1=contact.res1, + res2=contact.res2, + raw_score=contact.raw_score) content += line + os.linesep f_handle.write(content) diff --git a/conkit/io/gremlin.py b/conkit/io/gremlin.py index 83e4112c..e49a2f6c 100644 --- a/conkit/io/gremlin.py +++ b/conkit/io/gremlin.py @@ -52,6 +52,7 @@ class GremlinParser(ContactFileParser): """Parser class for GREMLIN contact prediction file """ + def __init__(self): super(GremlinParser, self).__init__() @@ -67,7 +68,7 @@ def read(self, f_handle, f_id="gremlin"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ hierarchy = ContactFile(f_id) @@ -147,8 +148,8 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` """ # Double check the type of hierarchy and reconstruct if necessary @@ -160,15 +161,18 @@ def write(self, f_handle, hierarchy): header_args = ['i', 'j', 'gene', 'i_id', 'j_id', 'r_sco', 's_sco', 'prob', 'I_prob'] content += '\t'.join(header_args) + os.linesep - out_kwargs = ['{res1_seq}', '{res2_seq}', '{chains}', '{res1_code}', '{res2_code}', - '{raw_score}', '{scalar_score}', '1.0', 'N/A'] + out_kwargs = [ + '{res1_seq}', '{res2_seq}', '{chains}', '{res1_code}', '{res2_code}', '{raw_score}', '{scalar_score}', + '1.0', 'N/A' + ] else: header_args = ['i', 'j', 'i_id', 'j_id', 'r_sco', 's_sco', 'prob'] content += '\t'.join(header_args) + os.linesep - out_kwargs = ['{res1_seq}', '{res2_seq}', '{res1_code}', '{res2_code}', - '{raw_score}', '{scalar_score}', '1.0'] + out_kwargs = [ + '{res1_seq}', '{res2_seq}', '{res1_code}', '{res2_code}', '{raw_score}', '{scalar_score}', '1.0' + ] for contact_map in contact_file: contact_map.set_scalar_score() @@ -182,9 +186,14 @@ def write(self, f_handle, hierarchy): chains = "{0}{1}".format(c.res1_chain, c.res2_chain) out_line = '\t'.join(out_kwargs) - out_line = out_line.format(res1_seq=c.res1_seq, res2_seq=c.res2_seq, res1_code=res1_code, - res2_code=res2_code, chains=chains, - raw_score=c.raw_score, scalar_score=round(c.scalar_score, 1)) + out_line = out_line.format( + res1_seq=c.res1_seq, + res2_seq=c.res2_seq, + res1_code=res1_code, + res2_code=res2_code, + chains=chains, + raw_score=c.raw_score, + scalar_score=round(c.scalar_score, 1)) content += out_line + os.linesep diff --git a/conkit/io/membrain.py b/conkit/io/membrain.py index 00980d9c..6788490e 100644 --- a/conkit/io/membrain.py +++ b/conkit/io/membrain.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ Parser module specific to ComsatIO predictions """ @@ -51,6 +50,7 @@ class MemBrainParser(ContactFileParser): """Class to parse a MemBrain contact file """ + def __init__(self): super(MemBrainParser, self).__init__() @@ -66,7 +66,7 @@ def read(self, f_handle, f_id="membrain"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -86,11 +86,7 @@ def read(self, f_handle, f_id="membrain"): else: _, res1_seq, res1, _, res2_seq, res2, raw_score = RE_SPLIT.split(line) - contact = Contact( - int(res1_seq), - int(res2_seq), - float(raw_score) - ) + contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact.res1 = res1 contact.res2 = res2 contact_map.add(contact) @@ -106,12 +102,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ @@ -127,9 +123,12 @@ def write(self, f_handle, hierarchy): content += 'Helix Position Residue Helix Position Residue Probability' + os.linesep for contact in contact_map: line = "Hx {res1_seq: <7} {res1: <7} Hx {res2_seq: <7} {res2: <7} {raw_score: <.6f}" - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, - res1=contact.res1, res2=contact.res2, raw_score=contact.raw_score) + line = line.format( + res1_seq=contact.res1_seq, + res2_seq=contact.res2_seq, + res1=contact.res1, + res2=contact.res2, + raw_score=contact.raw_score) content += line + os.linesep f_handle.write(content) - diff --git a/conkit/io/ncont.py b/conkit/io/ncont.py index 24de9dbf..28a5c28d 100644 --- a/conkit/io/ncont.py +++ b/conkit/io/ncont.py @@ -66,7 +66,7 @@ def read(self, f_handle, f_id="ncont"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -106,20 +106,18 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` - Notes - ----- - Creating a :func:`write` function for the Ncont parser + Note + ---- + Creating a :meth:`~conkit.io.ncont.NcontParser.write` function would come with a lot of issues, such as the parallel/antiparallel - direction, scoring etc. - - Thus, no :func:`write` method is available. + direction, scoring etc ... thus, this method is unavailable. Raises ------ - NotImplementedError + :obj:`NotImplementedError` Write function not available """ diff --git a/conkit/io/pcons.py b/conkit/io/pcons.py index c3ed5609..5fbd0391 100644 --- a/conkit/io/pcons.py +++ b/conkit/io/pcons.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ Parser module specific to Pcons predictions @@ -82,7 +81,7 @@ def read(self, f_handle, f_id="pcons"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ contact_file = ContactFile(f_id) @@ -124,10 +123,7 @@ def read(self, f_handle, f_id="pcons"): if RE_CONTACT.match(line): res1_seq, res2_seq, raw_score = line.split() - contact = Contact( - int(res1_seq), int(res2_seq), - float(raw_score) - ) + contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact_map.add(contact) line = next(lines, done) @@ -149,14 +145,14 @@ def write(self, f_handle, hierarchy, write_header_footer=True): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` write_header_footer : bool Write a PconsC3-typical header Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ @@ -179,10 +175,8 @@ def write(self, f_handle, hierarchy, write_header_footer=True): if contact_map.sequence is not None: content += "Sequence number: 1" + os.linesep - content += "Sequence name: {0}".format( - contact_map.sequence.id) + os.linesep - content += "Sequence length: {0} aa.".format( - contact_map.sequence.seq_len) + os.linesep + content += "Sequence name: {0}".format(contact_map.sequence.id) + os.linesep + content += "Sequence length: {0} aa.".format(contact_map.sequence.seq_len) + os.linesep content += "Sequence:" + os.linesep content += contact_map.sequence.seq + os.linesep * 3 @@ -193,8 +187,8 @@ def write(self, f_handle, hierarchy, write_header_footer=True): res1_seq = contact.res1_seq res2_seq = contact.res2_seq raw_score = contact.raw_score - l = "{res1_seq:>4} {res2_seq:>4} {raw_score:>.6f}".format(res1_seq=res1_seq, res2_seq=res2_seq, - raw_score=raw_score) + l = "{res1_seq:>4} {res2_seq:>4} {raw_score:>.6f}".format( + res1_seq=res1_seq, res2_seq=res2_seq, raw_score=raw_score) content += l + os.linesep if write_header_footer: diff --git a/conkit/io/pdb.py b/conkit/io/pdb.py index f1554325..97cd5f6a 100644 --- a/conkit/io/pdb.py +++ b/conkit/io/pdb.py @@ -65,7 +65,7 @@ class GenericStructureParser(ContactFileParser): """ def _build_sequence(self, chain): - """Build a peptide using Biopython to extract the sequence""" + """Build a peptide using :mod:`biopython` to extract the sequence""" return Sequence(chain.id + '_seq', ''.join(AminoAcidThreeToOne[residue.resname].value for residue in chain)) def _chain_contacts(self, chain1, chain2): @@ -73,14 +73,14 @@ def _chain_contacts(self, chain1, chain2): Parameters ---------- - chain1 : :obj:`Bio.PDB.Chain` + chain1 : :obj:`~Bio.PDB.Chain` A first chain object - chain2 : :obj:`Bio.PDB.Chain` + chain2 : :obj:`~Bio.PDB.Chain` A second chain object Yields ------ - atom_comb : list + list A list of tuples containing the contact information """ @@ -133,7 +133,7 @@ def _read(self, structure, f_id, distance_cutoff, atom_type): Parameters ---------- structure - A :obj:`Structure ` instance + A :obj:`~Bio.PDB.Structure.Structure>` instance f_id : str Unique contact file identifier distance_cutoff : int @@ -143,7 +143,7 @@ def _read(self, structure, f_id, distance_cutoff, atom_type): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile~` """ hierarchies = [] @@ -242,7 +242,7 @@ def read(self, f_handle, f_id="mmcif", distance_cutoff=8, atom_type='CB'): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ structure = MMCIFParser(QUIET=True).get_structure("mmcif", f_handle) @@ -255,12 +255,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - NotImplementedError + :obj:`NotImplementedError` Write function not available """ @@ -292,7 +292,7 @@ def read(self, f_handle, f_id="pdb", distance_cutoff=8, atom_type='CB'): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ structure = PDBParser(QUIET=True).get_structure("pdb", f_handle) @@ -305,12 +305,12 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - NotImplementedError + :obj:`NotImplementedError` Write function not available """ diff --git a/conkit/io/plmdca.py b/conkit/io/plmdca.py index 4da754bf..e87ec70e 100644 --- a/conkit/io/plmdca.py +++ b/conkit/io/plmdca.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ Parser module specific to plmDCA predictions """ @@ -47,6 +46,7 @@ class PlmDCAParser(ContactFileParser): """Class to parse a plmDCA contact prediction """ + def __init__(self): super(PlmDCAParser, self).__init__() @@ -62,7 +62,7 @@ def read(self, f_handle, f_id="plmdca"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -92,16 +92,15 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ - # Double check the type of hierarchy and reconstruct if necessary contact_file = self._reconstruct(hierarchy) if len(contact_file) > 1: diff --git a/conkit/io/psicov.py b/conkit/io/psicov.py index 5c02dee2..85abb888 100644 --- a/conkit/io/psicov.py +++ b/conkit/io/psicov.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ Parser module specific to PSICOV predictions """ @@ -47,6 +46,7 @@ class PsicovParser(ContactFileParser): """Class to parse a PSICOV contact prediction """ + def read(self, f_handle, f_id="psicov"): """Read a contact file @@ -59,7 +59,7 @@ def read(self, f_handle, f_id="psicov"): Returns ------- - :obj:`ContactFile ` + :obj:`~conkit.core.contactfile.ContactFile` """ @@ -74,8 +74,8 @@ def read(self, f_handle, f_id="psicov"): continue elif line[0].isdigit(): - _contact = Contact(int(line[0]), int(line[1]), float(line[4]), - distance_bound=(float(line[2]), float(line[3]))) + _contact = Contact( + int(line[0]), int(line[1]), float(line[4]), distance_bound=(float(line[2]), float(line[3]))) _map.add(_contact) hierarchy.method = 'Contact map predicted using PSICOV' @@ -89,16 +89,15 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`ContactFile `, :obj:`ContactMap ` - or :obj:`Contact ` + hierarchy : :obj:`~conkit.core.contactfile.ContactFile`, :obj:`~conkit.core.contactmap.ContactMap` + or :obj:`~conkit.core.contact.Contact` Raises ------ - RuntimeError + :obj:`RuntimeError` More than one contact map in the hierarchy """ - # Double check the type of hierarchy and reconstruct if necessary contact_file = self._reconstruct(hierarchy) if len(contact_file) > 1: @@ -111,8 +110,8 @@ def write(self, f_handle, hierarchy): line = "{res1_seq} {res2_seq} {lb} {ub} {raw_score:.6f}" lb = int(contact.lower_bound) if float(contact.lower_bound).is_integer() else contact.lower_bound ub = int(contact.upper_bound) if float(contact.upper_bound).is_integer() else contact.upper_bound - line = line.format(res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, raw_score=contact.raw_score, - lb=lb, ub=ub) + line = line.format( + res1_seq=contact.res1_seq, res2_seq=contact.res2_seq, raw_score=contact.raw_score, lb=lb, ub=ub) content += line + os.linesep f_handle.write(content) diff --git a/conkit/io/stockholm.py b/conkit/io/stockholm.py index f0d91062..7c3b7c89 100644 --- a/conkit/io/stockholm.py +++ b/conkit/io/stockholm.py @@ -27,7 +27,6 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ Parser module specific to Stockholm sequence files """ @@ -43,7 +42,6 @@ from conkit.core.sequence import Sequence from conkit.core.sequencefile import SequenceFile - V_RECORD = re.compile(r'^#(\s+STOCKHOLM.*)$') GF_RECORD = re.compile(r'^#=GF\s+\S+\s+(.*)$') GR_RECORD = re.compile(r'^#=GR\s+(\S+)\s+(\S+)\s+(.*)$') @@ -55,6 +53,7 @@ class StockholmParser(SequenceFileParser): """Parser class for Stockholm sequence files """ + def __init__(self): super(StockholmParser, self).__init__() @@ -70,7 +69,7 @@ def read(self, f_handle, f_id='stockholm'): Returns ------- - :obj:`SequenceFile ` + :obj:`~conkit.core.sequencefile.SequenceFile` """ @@ -124,10 +123,9 @@ def write(self, f_handle, hierarchy): ---------- f_handle Open file handle [write permissions] - hierarchy : :obj:`SequenceFile ` or :obj:`Sequence ` + hierarchy : :obj:`~conkit.core.sequencefile.SequenceFile` or :obj:`~conkit.core.sequence.Sequence` """ - # Double check the type of sequence_file and reconstruct if necessary sequence_file = self._reconstruct(hierarchy) content = "# STOCKHOLM 1.0" + os.linesep diff --git a/conkit/misc/__init__.py b/conkit/misc/__init__.py index 7f84293c..83ae0937 100644 --- a/conkit/misc/__init__.py +++ b/conkit/misc/__init__.py @@ -59,7 +59,7 @@ def deprecate(version, msg=None): Examples -------- - Enable :obj:`DeprecationWarning ` messages to be displayed. + Enable :obj:`~DeprecationWarning` messages to be displayed. >>> import warnings >>> warnings.simplefilter('default') diff --git a/conkit/plot/__init__.py b/conkit/plot/__init__.py index faf1009b..0e3b22cf 100644 --- a/conkit/plot/__init__.py +++ b/conkit/plot/__init__.py @@ -35,36 +35,36 @@ def ContactMapFigure(*args, **kwargs): - """:obj:`ContactMapFigure ` instance""" + """:obj:`~conkit.plot.contactmap.ContactMapFigure` instance""" from conkit.plot.contactmap import ContactMapFigure return ContactMapFigure(*args, **kwargs) def ContactMapChordFigure(*args, **kwargs): - """:obj:`ContactMapChordFigure ` instance""" + """:obj:`~conkit.plot.contactmapchord.ContactMapChordFigure` instance""" from conkit.plot.contactmapchord import ContactMapChordFigure return ContactMapChordFigure(*args, **kwargs) def ContactMapMatrixFigure(*args, **kwargs): - """:obj:`ContactMapMatrixFigure ` instance""" + """:obj:`~conkit.plot.contactmatrix.ContactMapMatrixFigure` instance""" from conkit.plot.contactmapmatrix import ContactMapMatrixFigure return ContactMapMatrixFigure(*args, **kwargs) def ContactDensityFigure(*args, **kwargs): - """:obj:`ContactDensityFigure ` instance""" + """:obj:`~conkit.plot.contactdensity.ContactDensityFigure` instance""" from conkit.plot.contactdensity import ContactDensityFigure return ContactDensityFigure(*args, **kwargs) def PrecisionEvaluationFigure(*args, **kwargs): - """:obj:`PrecisionEvaluationFigure ` instance""" + """:obj:`~conkit.plot.precisionevaluation.PrecisionEvaluationFigure` instance""" from conkit.plot.precisionevaluation import PrecisionEvaluationFigure return PrecisionEvaluationFigure(*args, **kwargs) def SequenceCoverageFigure(*args, **kwargs): - """:obj:`SequenceCoverageFigure ` instance""" + """:obj:`~conkit.plot.sequencecoverage.SequenceCoverageFigure` instance""" from conkit.plot.sequencecoverage import SequenceCoverageFigure return SequenceCoverageFigure(*args, **kwargs) diff --git a/conkit/plot/contactdensity.py b/conkit/plot/contactdensity.py index 45c6d0d0..12867806 100644 --- a/conkit/plot/contactdensity.py +++ b/conkit/plot/contactdensity.py @@ -57,7 +57,7 @@ class ContactDensityFigure(Figure): Attributes ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy bw_method : str The method to estimate the bandwidth @@ -75,12 +75,12 @@ def __init__(self, hierarchy, bw_method='bowman', **kwargs): Parameters ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy bw_method : str, optional The method to estimate the bandwidth [default: bowman] **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(ContactDensityFigure, self).__init__(**kwargs) @@ -102,7 +102,7 @@ def bw_method(self): """The method to estimate the bandwidth For a full list of options, please refer to - :func:`get_contact_density() ` + :meth:`~conkit.core.contactmap.ContactMap.get_contact_density` """ return self._bw_method @@ -114,7 +114,7 @@ def bw_method(self, bw_method): @property def hierarchy(self): - """A ConKit :obj:`ContactMap `""" + """A :obj:`~conkit.core.contactmap.ContactMap`""" return self._hierarchy @hierarchy.setter @@ -123,8 +123,8 @@ def hierarchy(self, hierarchy): Raises ------ - TypeError - The hierarchy is not a :obj:`ContactMap ` + :obj:`TypeError` + The hierarchy is not a :obj:`~conkit.core.contactmap.ContactMap` """ if hierarchy and _isinstance(hierarchy, "ContactMap"): diff --git a/conkit/plot/contactmap.py b/conkit/plot/contactmap.py index d8f1cbb5..c6708bc9 100644 --- a/conkit/plot/contactmap.py +++ b/conkit/plot/contactmap.py @@ -40,14 +40,14 @@ import matplotlib.pyplot as plt import numpy as np -from conkit.core._struct import _Gap +from conkit.core.struct import Gap from conkit.misc import deprecate, normalize from conkit.plot.figure import Figure from conkit.plot.tools import ColorDefinitions, _isinstance class ContactMapFigure(Figure): - """A Figure object specifically for a Contact Map + """A Figure object specifically for a :obj:`~conkit.core.contactmap.ContactMap` This figure will illustrate the contacts in a contact map. This plot is a very common representation of contacts. @@ -57,14 +57,14 @@ class ContactMapFigure(Figure): Attributes ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy - other : :obj:`ContactMap ` + other : :obj:`~conkit.core.contactmap.ContactMap` The second contact map hierarchy - reference : :obj:`ContactMap ` + reference : :obj:`~conkit.core.contactmap.ContactMap` The reference contact map hierarchy altloc : bool - Use the res_altloc positions [default: False] + Use the :attr:`~conkit.core.contact.Contact.res_altloc` positions [default: False] use_conf : bool The marker size will correspond to the raw score [default: False] @@ -81,20 +81,20 @@ def __init__(self, hierarchy, other=None, reference=None, altloc=False, use_conf Parameters ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy - other : :obj:`ContactMap `, optional + other : :obj:`~conkit.core.contactmap.ContactMap`, optional The second contact map hierarchy - reference : :obj:`ContactMap `, optional + reference : :obj:`~conkit.core.contactmap.ContactMap`, optional The reference contact map hierarchy altloc : bool, optional - Use the res_altloc positions [default: False] + Use the :attr:`~conkit.core.contact.Contact.res_altloc` positions [default: False] use_conf : bool, optional The marker size will correspond to the raw score [default: False] lim : tuple, list, optional The [min, max] residue numbers to show **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(ContactMapFigure, self).__init__(**kwargs) @@ -182,16 +182,16 @@ def draw(self): reference_data = np.empty((0, 2)) reference_colors = [] - self_data = np.array([c for c in self._hierarchy.as_list() if all(ci != _Gap.IDENTIFIER for ci in c)]) + self_data = np.array([c for c in self._hierarchy.as_list() if all(ci != Gap.IDENTIFIER for ci in c)]) self_colors = ContactMapFigure._determine_color(self._hierarchy) self_rawsc = np.array( - [c.raw_score for c in self._hierarchy if all(ci != _Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) + [c.raw_score for c in self._hierarchy if all(ci != Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) if self._other: - other_data = np.array([c for c in self._other.as_list() if any(ci != _Gap.IDENTIFIER for ci in c)]) + other_data = np.array([c for c in self._other.as_list() if any(ci != Gap.IDENTIFIER for ci in c)]) other_colors = ContactMapFigure._determine_color(self._other) other_rawsc = np.array( - [c.raw_score for c in self._other if all(ci != _Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) + [c.raw_score for c in self._other if all(ci != Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) else: other_data = self_data other_colors = self_colors diff --git a/conkit/plot/contactmapchord.py b/conkit/plot/contactmapchord.py index ee2396ac..f56582e0 100644 --- a/conkit/plot/contactmapchord.py +++ b/conkit/plot/contactmapchord.py @@ -49,7 +49,7 @@ class ContactMapChordFigure(Figure): - """A Figure object specifically for a Contact Map chord diagram + """A Figure object specifically for a :obj:`~conkit.core.contactmap.ContactMap` This figure will illustrate the contacts linking the residues in the target sequence. This plot is a very common representation @@ -69,7 +69,7 @@ class ContactMapChordFigure(Figure): Attributes ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy Examples @@ -85,12 +85,12 @@ def __init__(self, hierarchy, use_conf=False, **kwargs): Parameters ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy use_conf : bool, optional The marker size will correspond to the raw score [default: False] **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(ContactMapChordFigure, self).__init__(**kwargs) diff --git a/conkit/plot/contactmapmatrix.py b/conkit/plot/contactmapmatrix.py index 98889555..4a2c8ae1 100644 --- a/conkit/plot/contactmapmatrix.py +++ b/conkit/plot/contactmapmatrix.py @@ -40,14 +40,14 @@ import matplotlib.pyplot as plt import numpy as np -from conkit.core._struct import _Gap +from conkit.core.struct import Gap from conkit.misc import normalize from conkit.plot.figure import Figure from conkit.plot.tools import ColorDefinitions, _isinstance class ContactMapMatrixFigure(Figure): - """A Figure object specifically for a Contact Map Matrix + """A Figure object specifically for a :obj:`~conkit.core.contactmap.ContactMap` This figure will illustrate the contacts in a contact map matrix. This plot is a very common representation of contacts. @@ -57,12 +57,12 @@ class ContactMapMatrixFigure(Figure): Attributes ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy - other : :obj:`ContactMap ` + other : :obj:`~conkit.core.contactmap.ContactMap` The second contact map hierarchy altloc : bool - Use the res_altloc positions [default: False] + Use the :attr:`~conkit.core.contact.Contact.res_altloc` positions [default: False] Examples -------- @@ -77,16 +77,16 @@ def __init__(self, hierarchy, other=None, altloc=False, lim=None, **kwargs): Parameters ---------- - hierarchy : :obj:`ContactMap ` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The default contact map hierarchy - other : :obj:`ContactMap `, optional + other : :obj:`~conkit.core.contactmap.ContactMap`, optional The second contact map hierarchy altloc : bool, optional - Use the res_altloc positions [default: False] + Use the :attr:`~conkit.core.contact.Contact.res_altloc` positions [default: False] lim : tuple, list, optional The [min, max] residue numbers to show **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(ContactMapMatrixFigure, self).__init__(**kwargs) @@ -146,22 +146,26 @@ def lim(self, lim): def draw(self): _hierarchy = self._hierarchy.rescale() - self_data = np.array([c for c in _hierarchy.as_list() if all(ci != _Gap.IDENTIFIER for ci in c)]) + self_data = np.array([c for c in _hierarchy.as_list() if all(ci != Gap.IDENTIFIER for ci in c)]) self_colors = ContactMapMatrixFigure._determine_color(_hierarchy) - self_rawsc = np.array([c.raw_score for c in _hierarchy if all(ci != _Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) + self_rawsc = np.array( + [c.raw_score for c in _hierarchy if all(ci != Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) if self._other: _other = self._other.rescale() - other_data = np.array([c for c in _other.as_list() if any(ci != _Gap.IDENTIFIER for ci in c)]) + other_data = np.array([c for c in _other.as_list() if any(ci != Gap.IDENTIFIER for ci in c)]) other_colors = ContactMapMatrixFigure._determine_color(_other) - other_rawsc = np.array([c.raw_score for c in _other if all(ci != _Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) + other_rawsc = np.array( + [c.raw_score for c in _other if all(ci != Gap.IDENTIFIER for ci in [c.res1_seq, c.res2_seq])]) else: other_data = self_data other_colors = self_colors other_rawsc = self_rawsc - self._patch_scatter(self_data[:, 1], self_data[:, 0], symbol="s", facecolor=self_colors, radius=1.0, linewidth=0) - self._patch_scatter(other_data[:, 0], other_data[:, 1], symbol="s", facecolor=other_colors, radius=1.0, linewidth=0) + self._patch_scatter( + self_data[:, 1], self_data[:, 0], symbol="s", facecolor=self_colors, radius=1.0, linewidth=0) + self._patch_scatter( + other_data[:, 0], other_data[:, 1], symbol="s", facecolor=other_colors, radius=1.0, linewidth=0) if self.lim: min_max_data = np.arange(self.lim[0], self.lim[1] + 1) diff --git a/conkit/plot/figure.py b/conkit/plot/figure.py index acf031fe..8b577172 100644 --- a/conkit/plot/figure.py +++ b/conkit/plot/figure.py @@ -47,8 +47,8 @@ def __init__(self, ax=None, legend=True, **kwargs): Parameters ---------- - ax : :obj:`Axes ` - A pre-defined :obj:`Axes ` + ax : :obj:`~matplotlib.axes.Axes` + A pre-defined :obj:`~matplotlib.axes.Axes` If ``None`` is provided, a new plot will be created legend : bool, optional @@ -85,7 +85,7 @@ def __repr__(self): return self.__class__.__name__ def _patch_scatter(self, x, y, symbol="o", facecolor="#ffffff", edgecolor="#000000", radius=0.5, linewidth=1.0): - """Draw scatter points as :obj:`Circles ` to control width for discrete data""" + """Draw scatter points as :obj:`~matplotlib.patches.Circle` to control width for discrete data""" if len(x) != len(y): raise ValueError("Unequal x and y data provided") diff --git a/conkit/plot/precisionevaluation.py b/conkit/plot/precisionevaluation.py index 8b7f5daa..3eec6aad 100644 --- a/conkit/plot/precisionevaluation.py +++ b/conkit/plot/precisionevaluation.py @@ -54,7 +54,7 @@ class PrecisionEvaluationFigure(Figure): Attributes ---------- - hierarchy : :obj:`conkit.core.ContactMap` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The contact map hierarchy cutoff_step : float The cutoff step @@ -79,7 +79,7 @@ def __init__(self, hierarchy, min_cutoff=0.0, max_cutoff=100.0, cutoff_step=0.2, Parameters ---------- - hierarchy : :obj:`conkit.core.ContactMap` + hierarchy : :obj:`~conkit.core.contactmap.ContactMap` The contact map hierarchy min_cutoff : float, optional The minimum factor @@ -88,7 +88,7 @@ def __init__(self, hierarchy, min_cutoff=0.0, max_cutoff=100.0, cutoff_step=0.2, cutoff_step : float, optional The cutoff step **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(PrecisionEvaluationFigure, self).__init__(**kwargs) @@ -118,16 +118,16 @@ def cutoff_step(self, cutoff_step): @property def hierarchy(self): - """A ConKit :obj:`conkit.core.ContactMap`""" + """A ConKit :obj:`~conkit.core.contactmap.ContactMap`""" return self._hierarchy @hierarchy.setter def hierarchy(self, hierarchy): - """Define the ConKit :obj:`conkit.core.ContactMap` + """Define the ConKit :obj:`~conkit.core.contactmap.ContactMap` Raises ------ - RuntimeError + :obj:`RuntimeError` The hierarchy is not an alignment """ @@ -142,7 +142,7 @@ def min_cutoff(self): Raises ------ - ValueError + :obj:`ValueError` The minimum cutoff value is larger than or equal to the maximum """ @@ -164,7 +164,7 @@ def max_cutoff(self): Raises ------ - ValueError + :obj:`ValueError` The maximum cutoff value is smaller than the the minimum """ diff --git a/conkit/plot/sequencecoverage.py b/conkit/plot/sequencecoverage.py index 2c67ee21..39c9d225 100644 --- a/conkit/plot/sequencecoverage.py +++ b/conkit/plot/sequencecoverage.py @@ -58,7 +58,7 @@ class SequenceCoverageFigure(Figure): Attributes ---------- - hierarchy : :obj:`SequenceFile ` + hierarchy : :obj:`~conkit.core.sequencefile.SequenceFile` The Multiple Sequence Alignment hierarchy Examples @@ -74,10 +74,10 @@ def __init__(self, hierarchy, **kwargs): Parameters ---------- - hierarchy : :obj:`SequenceFile ` + hierarchy : :obj:`~conkit.core.sequencefile.SequenceFile` The Multiple Sequence Alignment hierarchy **kwargs - General :obj:`Figure ` keyword arguments + General :obj:`~conkit.plot.figure.Figure` keyword arguments """ super(SequenceCoverageFigure, self).__init__(**kwargs) @@ -92,12 +92,12 @@ def __repr__(self): @property def hierarchy(self): - """A ConKit :obj:`SequenceFile `""" + """A ConKit :obj:`~conkit.core.sequencefile.SequenceFile`""" return self._hierarchy @hierarchy.setter def hierarchy(self, hierarchy): - """Define the ConKit :obj:`SequenceFile ` """ + """Define the ConKit :obj:`~conkit.core.sequencefile.SequenceFile` """ if hierarchy and _isinstance(hierarchy, "SequenceFile") and hierarchy.is_alignment: self._hierarchy = hierarchy elif hierarchy and _isinstance(hierarchy, "SequenceFile"): diff --git a/conkit/plot/tools.py b/conkit/plot/tools.py index 0cc3c6fa..60f07acd 100644 --- a/conkit/plot/tools.py +++ b/conkit/plot/tools.py @@ -103,15 +103,15 @@ def find_minima(data, order=1): list A list of indices for minima - Warnings - -------- - For multi-dimensional problems, see :func:`scipy.signal.argrelmin`. + Warning + ------- + For multi-dimensional problems, see :func:`~scipy.signal.argrelmin`. Raises ------ - ValueError + :obj:`ValueError` Order needs to be >= 1! - ValueError + :obj:`ValueError` More than two elements required! """ @@ -134,18 +134,18 @@ def get_adjusted_aspect(ax, aspect_ratio): Parameters ---------- - ax : :obj:`Axes ` - A :obj:`Axes ` instance + ax : :obj:`~matplotlib.axes.Axes` + A :obj:`~matplotlib.axes.Axes` instance aspect_ratio : float - The desired aspect ratio for :obj:`Axes ` + The desired aspect ratio for :obj:`~matplotlib.axes.Axes` Returns ------- float The required aspect ratio to achieve the desired one - Warnings - -------- + Warning + ------- This function only works for non-logarithmic axes. """ diff --git a/docs/conf.py b/docs/conf.py index 349f4bce..5b6c2801 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -364,11 +364,9 @@ def run_apidoc(_): # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { 'python': ('https://docs.python.org/3', None), + 'subprocess': ('https://docs.python.org/3', None), 'numpy': ('https://docs.scipy.org/doc/numpy/', None), - 'numbas': ('http://numba.pydata.org/numba-doc/latest/', None), 'matplotlib': ('https://matplotlib.org/', None), - 'biopython': ('http://biopython.org/', None), - 'warnings': ('https://docs.python.org/3/', None), } diff --git a/docs/examples/rst/python_analyse_conpred.rst b/docs/examples/rst/python_analyse_conpred.rst index 44f52314..85fd0a71 100644 --- a/docs/examples/rst/python_analyse_conpred.rst +++ b/docs/examples/rst/python_analyse_conpred.rst @@ -12,26 +12,26 @@ Contact Prediction Analysis >>> conpred.sequence = conkit.io.read("toxd/toxd.fasta", "fasta").top_sequence >>> conpred.set_sequence_register() -Note, we've chosen the top contact map immediately because this file only contained a single one. We also added the sequence straight away and assigned the sequence register using the :func:`set_sequence_register() ` function. The latter makes sure that each residue number has the right amino acid assigned. +Note, we've chosen the top :obj:`~conkit.core.contactmap.ContactMap` immediately because this file only contained a single one. We also added the sequence straight away and assigned the sequence register using the :meth:`~conkit.core.contactmap.ContactMap.set_sequence_register` function. The latter makes sure that each residue number has the right amino acid assigned. -2. **Plotting a contact map** +2. **Plotting a :obj:`conkit.core.contactmap.ContactMap`** -Similar to the example on plotting a contact map, this is something you will almost certainly do every single time you obtain a contact prediction. Head over to the :ref:`contact map plotting example ` in case you haven't looked at it. +Similar to the example on plotting a :obj:`~conkit.core.contactmap.ContactMap`, this is something you will almost certainly do every single time you obtain a contact prediction. Head over to the :ref:`python_plot_map` example in case you haven't looked at it. -Let's assume we have created the following contact map plot +Let's assume we have created the following :obj:`conkit.core.contactmap.ContactMap` plot .. figure:: ../images/toxd_cmap_simple.png :alt: Toxd CMap Simple :scale: 30 -Looking at this contact map tells us that there is most likely a |beta|-strand between residues 13-23 and 33-34. The spread of the contacts also gives us an indication that we are dealing with a monomeric protein structure. However, our contact prediction contains a lot more information that is not visible from this plot. +Looking at this :obj:`conkit.core.contactmap.ContactMap` tells us that there is most likely a |beta|-strand between residues 13-23 and 33-34. The spread of the contacts also gives us an indication that we are dealing with a monomeric protein structure. However, our contact prediction contains a lot more information that is not visible from this plot. 3. **Looking at individual residues** -Assume you have prior knowledge about the protein target, in this case PDB entry `1DTX `_. Let's assume that this prior knowledge includes information about a residue, e.g. residue 34. As a result, we might want to look at all contacts related to residue 34 in our contact map to see specifically if any relevant contacts were predicted. +Assume you have prior knowledge about the protein target, in this case PDB entry `1DTX `_. Let's assume that this prior knowledge includes information about a residue, e.g. residue 34. As a result, we might want to look at all contacts related to residue 34 in our :obj:`conkit.core.contactmap.ContactMap` to see specifically if any relevant contacts were predicted. -In ConKit, we can use the :func:`find() ` function to extract all contacts containing one or more residues. +In ConKit, we can use the :meth:`~conkit.core.contactmap.ContactMap.find` function to extract all contacts containing one or more residues. .. code-block:: python @@ -41,7 +41,7 @@ In ConKit, we can use the :func:`find() ` function This print statement in the last line indicates that there a total of 59 contacts are associated with residue 34. Let's rank them to see the most confidently predicted contact involving residue 34. -We use the :func:`sort() ` function for ranking our map. We want to sort it by the ``raw_score`` in reverse order, i.e. largest values at the top of the list. We don't want to create a new contact map but instead apply the changes to the existing one, thus we use the ``inplace=True`` keyword argument. +We use :meth:`~conkit.core.contactmap.ContactMap.sort` for ranking our map. We want to sort it by the :attr:`~conkit.core.contact.Contact.raw_score` in reverse order, i.e. largest values at the top of the list. We don't want to create a new :obj:`~conkit.core.contactmap.ContactMap` but instead apply the changes to the existing one, thus we use the ``inplace=True`` keyword argument. .. code-block:: python @@ -50,7 +50,7 @@ We use the :func:`sort() ` function for ranking our Contact(id="(21, 34)" res1="P" res1_chain="" res1_seq=21 res2="R" res2_chain="" res2_seq=34 raw_score=0.459334760904) -This shows that the most confidently predicted contact is between residues 21 and 34 with a prediction score of 0.46. Considering our contact map from the step 2, this information would make sense as we assumed |beta|-sheet in that region of residues. +This shows that the most confidently predicted contact is between residues 21 and 34 with a prediction score of 0.46. Considering our :obj:`conkit.core.contactmap.ContactMap` from the step 2, this information would make sense as we assumed |beta|-sheet in that region of residues. 4. **Calculating the precision score** @@ -60,7 +60,7 @@ This shows that the most confidently predicted contact is between residues 21 an Finally, in some cases you either have already existing structural information, such as a crystal structure, or a predicted model and you want to assess how accurate or satisfied your contact prediction is. For this kind of analysis, the precision score is the ideal measure. It compares one set of contacts against a second and calculates the ratio between the matches and the total number of contacts compared. -In ConKit, this functionality is provided via the :attr:`precision ` attribute of each contact map. If we want to use the latter, we need to :func:`match() ` the two contact maps first. The following Python code shows the entire process. +In ConKit, this functionality is provided via the :attr:`~conkit.core.contactmap.ContactMap.precision` attribute of each :obj:`~conkit.core.contactmap.ContactMap`. If we want to use the latter, we need to :meth:`~conkit.core.contactmap.ContactMap.match` the two :obj:`~conkit.core.contactmap.ContactMap`'s first. The following Python code shows the entire process. .. code-block:: python @@ -73,7 +73,7 @@ In ConKit, this functionality is provided via the :attr:`precision ` class. It accepts a **matched** contact map and calculates the precision values at different thresholds to produce a plot. +If you would like to automate this process, or rather visualise the data, you can use the :obj:`~conkit.plot.precisionevaluation.PrecisionEvaluationFigure` class. It accepts a **matched** :obj:`~conkit.core.contactmap.ContactMap` and calculates the precision values at different thresholds to produce a plot. + To produce a precision evaluation plot with factors between 0.0 and 5.0 with a stepwise increase of 0.1, use the following command. diff --git a/docs/examples/rst/python_analyse_msa.rst b/docs/examples/rst/python_analyse_msa.rst index d19913ff..2ace2b9c 100644 --- a/docs/examples/rst/python_analyse_msa.rst +++ b/docs/examples/rst/python_analyse_msa.rst @@ -4,7 +4,7 @@ Multiple Sequence Alignment Analysis ------------------------------------ .. warning:: - You require the optional dependency `SciPy `_ package to use this script. If you are unsure if it is installed on your system, refer to the :ref:`Installation` documentation + You require the :mod:`scipy` package to use this script. If you are unsure if it is installed on your system, refer to the :ref:`Installation` documentation **1. The MSA ConKit hierarchy needs to be created first.** diff --git a/docs/examples/rst/python_convert_conpred.rst b/docs/examples/rst/python_convert_conpred.rst index 393c1fbb..47c5be67 100644 --- a/docs/examples/rst/python_convert_conpred.rst +++ b/docs/examples/rst/python_convert_conpred.rst @@ -6,7 +6,7 @@ File Format Conversion In order to convert files in ConKit, we need to use the ConKit I/O framework. .. note:: - ConKit I/O framework consists of three main functions that handle the relevant parsers: :func:`read() `, :func:`write() ` and :func:`convert() `. The latter effectively uses the former two but handles everything in one step. + ConKit I/O framework consists of three main functions that handle the relevant parsers: :func:`~conkit.io.read`, :func:`~conkit.io.write` and :func:`~conkit.io.convert`. The latter effectively uses the former two but handles everything in one step. **1. Files can be read in ConKit's internal hierarchies using simple Python code.** @@ -22,7 +22,7 @@ In order to convert files in ConKit, we need to use the ConKit I/O framework. >>> import conkit.io >>> conkit.io.write('toxd/toxd.rr', 'casprr', conpred) -**3. To convert file formats in single call, you can use the :func:`conkit.io.convert` function.** +**3. To convert file formats in single call, you can use the :func:`~conkit.io.convert` function.** .. code-block:: python diff --git a/docs/examples/rst/python_convert_msa.rst b/docs/examples/rst/python_convert_msa.rst index 956398ad..1f8d380d 100644 --- a/docs/examples/rst/python_convert_msa.rst +++ b/docs/examples/rst/python_convert_msa.rst @@ -6,7 +6,7 @@ File Format Conversion In order to convert files in ConKit, we need to use the ConKit I/O framework. .. note:: - ConKit I/O framework consists of three main functions that handle the relevant parsers: :func:`read() `, :func:`write() ` and :func:`convert() `. The latter effectively uses the former two but handles everything in one step. + ConKit I/O framework consists of three main functions that handle the relevant parsers: :func:`~conkit.io.read`, :func:`~conkit.io.write` and :func:`~conkit.io.convert`. The latter effectively uses the former two but handles everything in one step. **1. Files can be read in ConKit's internal hierarchies using simple Python code.** @@ -22,7 +22,7 @@ In order to convert files in ConKit, we need to use the ConKit I/O framework. >>> import conkit.io >>> conkit.io.write('toxd/toxd.mfa', 'fasta', msa) -**3. To convert file formats in single call, you can use the :func:`conkit.io.convert` function.** +**3. To convert file formats in single call, you can use the :func:`~conkit.io.convert` function.** .. code-block:: python diff --git a/docs/examples/rst/python_create_contactfile.rst b/docs/examples/rst/python_create_contactfile.rst index 40173961..a339223c 100644 --- a/docs/examples/rst/python_create_contactfile.rst +++ b/docs/examples/rst/python_create_contactfile.rst @@ -8,39 +8,39 @@ If you wish to construct it as part of a new development to store your contact i Entities ++++++++ -**1. How to create a Contact?** +**1. How to create a :obj:`~conkit.core.contact.Contact`?** .. code-block:: python >>> from conkit.core import Contact >>> contact = Contact(1, 10, 1.0) -The example above creates a contact between residues ``1`` and ``10`` and assigns a ``raw_score`` of ``1.0`` to it. By default, this contact has many more default attributes assigned, such as the distance value often seen in columns 3 and 4 in the Casp RR format. +The example above creates a contact between residues ``1`` and ``10`` and assigns a :attr:`~conkit.core.contact.Contact.raw_score` of ``1.0`` to it. By default, this contact has many more default attributes assigned, such as the distance value often seen in columns 3 and 4 in the Casp RR format. -**2. How to create a ContactMap?** +**2. How to create a :obj:`~conkit.core.contactmap.ContactMap`?** .. code-block:: python >>> from conkit.core import ContactMap >>> cmap = ContactMap('example') -This example shows you how to create a :obj:`ContactMap ` which can store a :obj:`Contact `. +This example shows you how to create a :obj:`~conkit.core.contactmap.ContactMap` which can store a :obj:`~conkit.core.contact.Contact`. -**3. How to create a ContactFile?** +**3. How to create a :obj:`~conkit.core.contactfile.ContactFile`?** .. code-block:: python >>> from conkit.core import ContactFile >>> cmap = ContactFile('example') -This example shows you how to create a :obj:`ContactFile ` which can store a :obj:`ContactMap `. +This example shows you how to create a :obj:`~conkit.core.contactfile.ContactFile` which can store a :obj:`~conkit.core.contactmap.ContactMap`. Hierarchy +++++++++ -Above is an outline for the different contact-related entities. Each higher entity allows you to store one or more lower-level ones, i.e. you can store one or more :obj:`ContactMap ` entities in a single :obj:`ContactFile `. Similarly, you could many :obj:`Contact ` entities in a :obj:`ContactMap `; however, be aware that all **must** have unique IDs. +Above is an outline for the different contact-related :obj:`~conkit.core.entity.Entity` classes. Each higher entity allows you to store one or more lower-level ones, i.e. you can store one or more :obj:`~conkit.core.contactmap.ContactMap` entities in a single :obj:`~conkit.core.contactfile.ContactFile`. Similarly, you could many :obj:`~conkit.core.contact.Contact` entities in a :obj:`~conkit.core.contactmap.ContactMap`; however, be aware that all **must** have unique IDs. -To illustrate how you can combine the entities, look at the following: +To illustrate how you can combine the :obj:`~conkit.core.entity.Entity` classes, look at the following: .. code-block:: python @@ -53,6 +53,6 @@ To illustrate how you can combine the entities, look at the following: >>> # Add the contact map to the contact file >>> cfile.add(cmap) -Note, the order in which you add entities does not matter. We could also add the ``cmap`` to the ``cfile`` before adding the ``contact`` to the ``cmap``. +Note, the order in which you add :obj:`~conkit.core.entity.Entity` instances does not matter. We could also add the ``cmap`` to the ``cfile`` before adding the ``contact`` to the ``cmap``. Once you have constructed your hierarchy, all related functions are available to you. diff --git a/docs/examples/rst/python_create_sequencefile.rst b/docs/examples/rst/python_create_sequencefile.rst index a97ba567..7847b6a0 100644 --- a/docs/examples/rst/python_create_sequencefile.rst +++ b/docs/examples/rst/python_create_sequencefile.rst @@ -8,41 +8,40 @@ If you wish to construct it as part of a new development to store your sequence Entities ++++++++ -1. **How to create a Sequence?** +1. **How to create a :obj:`~conkit.core.sequence.Sequence`?** .. code-block:: python >>> import conkit.core >>> seq = conkit.core.Sequence("example", "ABCDEF") -The example above creates a :obj:`Sequence ` object with id "example" and sequence "ABCDEF". This sequence contains numerous functions, such as :func:`align_global() ` for a global pairwise alignment with a second sequence +The example above creates a :obj:`~conkit.core.sequence.Sequence` object with id "example" and sequence "ABCDEF". This sequence contains numerous functions, such as :meth:`~conkit.core.sequence.Sequence.align_global` for a global pairwise alignment with a second sequence -2. **How to create a SequenceFile?** +2. **How to create a :obj:`~conkit.core.sequencefile.SequenceFile`?** .. code-block:: python >>> import conkit.core - >>> sfile = conkit.core.SequenceFile("example) + >>> sfile = conkit.core.SequenceFile("example") -This example shows you how to create a :obj:`SequenceFile ` which can store one or more :obj:`Sequence ` objects. +This example shows you how to create a :obj:`~conkit.core.sequencefile.SequenceFile` which can store one or more :obj:`~conkit.core.sequence.Sequence` objects. Hierarchy +++++++++ -Above is an outline for the different sequence-related entities. Each higher entity allows you to store one or more lower-level ones, i.e. you can store one or more :obj:`Sequence ` entities in a single :obj:`SequenceFile `; however, be aware that all **must** have unique IDs. +Above is an outline for the different sequence-related :obj:`~conkit.core.entity.Entity` classes. Each higher entity allows you to store one or more lower-level ones, i.e. you can store one or more :obj:`~conkit.core.sequence.Sequence` entities in a single :obj:`~conkit.core.sequencefile.SequenceFile`; however, be aware that all **must** have unique IDs. To illustrate how you can combine the entities, look at the following: .. code-block:: python >>> import conkit.core - >>> sfile = conkit.core.SequenceFile("example) + >>> sfile = conkit.core.SequenceFile("example") >>> seq1 = conkit.core.Sequence("example", "ABCDEF") >>> seq2 = conkit.core.Sequence("elpmaxe", "FEDCBA") - >>> # Add the sequences to the sequence file >>> sfile.add(seq1) >>> sfile.add(seq2) -Note, the order in which you add entities does not matter. +Note, the order in which you add :obj:`~conkit.core.entity.Entity` instances does not matter. Once you have constructed your hierarchy, all related functions are available to you. diff --git a/docs/examples/rst/python_plot_chord.rst b/docs/examples/rst/python_plot_chord.rst index 6946908a..eea01aff 100644 --- a/docs/examples/rst/python_plot_chord.rst +++ b/docs/examples/rst/python_plot_chord.rst @@ -15,7 +15,7 @@ Contact Map Chord Diagram Plotting :alt: Toxd Chord Simple :scale: 30 -Each residue in the Chord plot corresponds to an amino acid in your sequence. For a full list of the encoding used, check the :obj:`ContactMapChordFigure `. +Each residue in the Chord plot corresponds to an amino acid in your sequence. For a full list of the encoding used, check the :obj:`ContactMapChordFigure `. .. role:: ala .. role:: cys diff --git a/docs/examples/rst/script_analyse_msa.rst b/docs/examples/rst/script_analyse_msa.rst index 6cdc7588..21a7e648 100644 --- a/docs/examples/rst/script_analyse_msa.rst +++ b/docs/examples/rst/script_analyse_msa.rst @@ -4,7 +4,7 @@ Multiple Sequence Alignment Analysis ------------------------------------ .. warning:: - You require the optional dependency `SciPy `_ package to use this script. If you are unsure if it is installed on your system, refer to the :ref:`Installation` documentation + You require the :mod:`scipy` package to use this script. If you are unsure if it is installed on your system, refer to the :ref:`Installation` documentation If you would like to analyse a Multiple Sequence Alignment (MSA) file, you can do so using ConKit's provided script, which is called ``conkit-msatool``. diff --git a/docs/examples/rst/script_plot_chord.rst b/docs/examples/rst/script_plot_chord.rst index b2bcf013..15c79de8 100644 --- a/docs/examples/rst/script_plot_chord.rst +++ b/docs/examples/rst/script_plot_chord.rst @@ -16,7 +16,7 @@ The call above uses the contact prediction file ``toxd.mat`` file, which is in ` :align: center :scale: 30 -Each residue in the Chord plot corresponds to an amino acid in your sequence. For a full list of the encoding used, check the :obj:`ContactMapChordFigure `. +Each residue in the Chord plot corresponds to an amino acid in your sequence. For a full list of the encoding used, check the :obj:`~conkit.plot.contactmapchord.ContactMapChordFigure`. .. role:: ala .. role:: cys