API Documentation

autosnapgene.parse(path, block_classes=None)[source]

Parse the given file and return a SnapGene object.

This is an alias for Snapgene(path).

autosnapgene.write(path, dna)[source]

Write the given SnapGene object (dna) to the given path.

This is an alias for dna.write(path).

class autosnapgene.SnapGene(path=None)[source]
__init__(path=None)[source]

Initialize self. See help(type(self)) for accurate signature.

accession_number
add_feature(feature, seq=None)[source]

Add the given feature to the sequence.

The argument should be a Feature instance. Colors and positions are specified as segments, which you can provide by filling in the segments attribute of the Feature instance with FeatureSegments instances.

If you specify the optional seq argument, the position of the feature will automatically be set to the position of that subsequence in the full sequence. If the given subsequence appears multiple times, multiple features will be created. If the subsequence doesn’t appear, a SequenceNotFound exception will be raised. The given feature must have either 0 or 1 segments, otherwise it isn’t clear how the position should be set.

add_trace(path, name=None)[source]

Add the given trace to the sequence, if the sequence doesn’t already have a trace of the same name (or the given name).

The trace is always added after any existing traces.

append_trace(path, name=None)[source]

Add the given trace to this sequence after any existing traces.

Unlike add_trace(), this function adds the trace unconditionally, which may result in duplicates.

author

The creator of this sequence.

clear_features()[source]

Remove all features from the sequence.

clear_history()[source]

Remove all history from the sequence.

clear_traces()[source]

Remove all traces from the sequence.

code_number
comments

Miscellaneous comments on this sequence.

count_features()[source]

Return the number of features in this sequence.

count_traces()[source]

Return the number of traces associated with the sequence.

custom_map_label
date_created

The date the sequence was created.

date_last_modified

The date the sequence was last modified.

description

A description of the sequence.

dna_sequence
export_version
extract_features()[source]
extract_traces(dir)[source]

Save any traces associated with this sequence as separate files in the given directory.

The traces will be saved in the ZTR format, which is the format used internally by SnapGene.

features

Return a list of all the features in this sequence.

file_type
find_block(cls)[source]
find_blocks(cls)[source]
find_or_make_block(cls)[source]
get_accession_number()[source]
get_author()[source]

The creator of this sequence.

get_code_number()[source]
get_comments()[source]

Miscellaneous comments on this sequence.

get_custom_map_label()[source]
get_date_created()[source]

The date the sequence was created.

get_date_last_modified()[source]

The date the sequence was last modified.

get_description()[source]

A description of the sequence.

get_dna_sequence()[source]
get_export_version()[source]
get_feature(name)[source]

Return the feature with the given name.

If multiple features have the given name, only the first one encountered will be returned. A FeatureNotFound exception will be raised if no feature with the given name can be found.

get_features()[source]

Return a list of all the features in this sequence.

get_file_type()[source]
get_import_version()[source]
get_is_confirmed_experimentally()[source]

True if this sequence has been experimentally confirmed.

get_is_dam_methylated()[source]
get_is_dcm_methylated()[source]
get_is_ecoki_methylated()[source]
get_organism()[source]

The organism this sequence derives from.

get_plasmid_type()[source]

“Natural” or “Synthetic”.

get_protein_sequence()[source]
get_references()[source]
get_sequence()[source]

Get the DNA or protein sequence stored in this file.

This method will not indicate whether it returned a protein or DNA sequence, so if that is not clear from the context, use get_dna_sequence() or get_protein_sequence() to be sure. If the file doesn’t contain either type of sequence, a BlockNotFound exception will be raised.

get_sequence_class()[source]
get_strandedness()[source]
get_topology()[source]
get_trace_names()[source]
get_traces(name=None)[source]

Return information about all of the alignments/traces associated with the sequence.

If a name is provided, only traces with that name will be returned. If a pathlib.Path is given as the name, the stem of that path will be taken as the name.

get_transformed_into()[source]

The organism/strain being used to propagate this sequence in the lab.

get_use_custom_map_label()[source]
has_trace(name)[source]

Return True is the sequence contains a trace with the given name.

If a pathlib.Path is given as the name, the stem of that path will be taken as the name.

import_version
insert_trace(i, path, name=None)[source]

Add the given trace to this sequence at the given index.

Unlike add_trace(), this function adds the trace unconditionally, which may result in duplicates.

is_confirmed_experimentally

True if this sequence has been experimentally confirmed.

is_dam_methylated
is_dcm_methylated
is_ecoki_methylated
make_block(cls)[source]
organism

The organism this sequence derives from.

parse(path, block_classes=None)[source]
pick_trace(name)[source]

Hide every trace except for the one specified.

plasmid_type

“Natural” or “Synthetic”.

prepend_trace(path, name=None)[source]

Add the given trace to this sequence before any existing traces.

Unlike add_trace(), this function adds the trace unconditionally, which may result in duplicates.

protein_sequence
references
remove_block(cls)[source]
remove_blocks(cls)[source]
remove_feature(name)[source]

Remove the feature with the given name from this sequence.

Only the feature annotation is removed; the sequence corresponding to the feature remains. If no feature with the given name can be found, a FeatureNotFound exception is raised.

remove_trace(name)[source]

Remove the trace with the given name.

If a pathlib.Path is given as the name, the stem of that path will be taken as the name. If there are multiple traces with the same name, all will be removed. If there are no traces with the given name, a ValueError will be raised.

rename_trace(old_name, new_name)[source]

Rename the given trace.

If multiple traces have the same name, they will all be renamed.

replace_trace(old_name, path, new_name=None)[source]

Replace the trace with the given name with the given path.

If there are multiple traces with the given name, the first will be replaced and the rest will be removed.

reset()[source]
sequence

Get the DNA or protein sequence stored in this file.

This method will not indicate whether it returned a protein or DNA sequence, so if that is not clear from the context, use get_dna_sequence() or get_protein_sequence() to be sure. If the file doesn’t contain either type of sequence, a BlockNotFound exception will be raised.

sequence_class
set_accession_number(value)[source]
set_author(value)[source]
set_code_number(value)[source]
set_comments(value)[source]
set_custom_map_label(value)[source]
set_date_created(value)[source]
set_date_last_modified(value)[source]
set_description(value)[source]
set_dna_sequence(value)[source]
set_export_version(value)[source]
set_file_type(value)[source]
set_import_version(value)[source]
set_is_confirmed_experimentally(value)[source]
set_is_dam_methylated(value)[source]
set_is_dcm_methylated(value)[source]
set_is_ecoki_methylated(value)[source]
set_organism(value)[source]
set_plasmid_type(value)[source]
set_protein_sequence(value)[source]
set_references(value)[source]
set_sequence(value)[source]

Set the DNA or protein sequence stored in this file.

If the file does not yet contain a sequence, the DNA sequence will be set.

set_sequence_class(value)[source]
set_strandedness(value)[source]
set_topology(value)[source]
set_transformed_into(value)[source]
set_use_custom_map_label(value)[source]
sort_traces(key=<function SnapGene.<lambda>>, reverse=False)[source]

Rearrange the traces according to the given key function.

If no key function is given, the traces will be sorted alphabetically. The argument to the key function will be an AlignmentMetadata object.

strandedness
sync_trace_metadata()[source]
topology
trace_names
traces

Return information about all of the alignments/traces associated with the sequence.

If a name is provided, only traces with that name will be returned. If a pathlib.Path is given as the name, the stem of that path will be taken as the name.

transformed_into

The organism/strain being used to propagate this sequence in the lab.

use_custom_map_label
write(path=None)[source]
class autosnapgene.Feature(**kwargs)[source]
class CleavageArrowsAttrib[source]
static from_str(str)[source]
static to_str(value)[source]
class DirectionalityAttrib[source]
str_from_value = {'backward': '2', 'bidirectional': '3', 'forward': '1', 'none': '0'}
value_from_str = {'0': 'none', '1': 'forward', '2': 'backward', '3': 'bidirectional'}
class QualifierTag[source]
data_formats = {<class 'int'>: 'int', <class 'str'>: 'text'}
data_types = {'int': <class 'int'>, 'text': <class 'str'>}
classmethod from_xml(element)[source]
classmethod to_xml(parent, tag, values)[source]
class SegmentTag[source]
static from_xml(element)[source]
static to_xml(parent, tag, segments)[source]
begin
end
classmethod from_segment(**kwargs)[source]

Instantiate a feature with a single segment.

Keyword arguments corresponding to any attribute of either the Feature or FeatureSegment classes are accepted.

get_begin()[source]
get_end()[source]
get_range()[source]
get_segment()[source]

If this feature has only one segment, return it. Otherwise, raise an exception.

get_sequence(full_seq)[source]
range
repr_attrs = ('name', 'type')
segment

If this feature has only one segment, return it. Otherwise, raise an exception.

set_segment(segment)[source]

Remove any segments associated with this feature, and replace them with the given segment.

After calling this setter (or assigning to this attribute), the feature will have exactly one segment. It will still be possible to add or remove segments later, though.

xml_attrib_defs = [('id', 'recentID', <class 'autosnapgene.parser.Xml.IntAttrib'>), ('name', 'name', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('type', 'type', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('directionality', 'directionality', <class 'autosnapgene.blocks.features.Feature.DirectionalityAttrib'>), ('reading_frame', 'readingFrame', <class 'autosnapgene.parser.Xml.IntAttrib'>), ('cleavage_arrows', 'cleavageArrows', <class 'autosnapgene.blocks.features.Feature.CleavageArrowsAttrib'>), ('allow_segment_overlaps', 'allowSegmentOverlaps', <class 'autosnapgene.parser.Xml.BoolAttrib'>), ('swapped_segment_numbering', 'swappedSegmentNumbering', <class 'autosnapgene.parser.Xml.BoolAttrib'>), ('max_run_on', 'maxRunOn', <class 'autosnapgene.parser.Xml.IntAttrib'>), ('max_fused_run_on', 'maxFusedRunOn', <class 'autosnapgene.parser.Xml.IntAttrib'>), ('detection_mode', 'detectionMode', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('genetic_code_id', 'geneticCode', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('first_codon_met', 'translateFirstCodonAsMet', <class 'autosnapgene.parser.Xml.BoolAttrib'>), ('consecutive_translation_numbering', 'consecutiveTranslationNumbering', <class 'autosnapgene.parser.Xml.BoolAttrib'>), ('consecutive_numbering_start', 'consecutiveNumberingStartsFrom', <class 'autosnapgene.parser.Xml.IntAttrib'>), ('translated_mw', 'translationMW', <class 'autosnapgene.parser.Xml.FloatAttrib'>), ('hits_stop_codon', 'hitsStopCodon', <class 'autosnapgene.parser.Xml.BoolAttrib'>)]
xml_subtag_defs = [('segments', 'Segment', <class 'autosnapgene.blocks.features.Feature.SegmentTag'>, []), ('qualifiers', 'Q', <class 'autosnapgene.blocks.features.Feature.QualifierTag'>, {})]
xml_tag = 'Feature'
class autosnapgene.FeatureSegment(**kwargs)[source]
class RangeAttrib[source]
static from_str(str)[source]
static to_str(value)[source]
begin
end
get_begin()[source]
get_end()[source]
repr_attrs = ('type', 'color', 'range')
xml_attrib_defs = [('name', 'name', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('range', 'range', <class 'autosnapgene.blocks.features.FeatureSegment.RangeAttrib'>), ('display', 'type', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('color', 'color', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('is_translated', 'translated', <class 'autosnapgene.parser.Xml.BoolAttrib'>), ('translation_start_number', 'translationNumberingStartsFrom', <class 'autosnapgene.parser.Xml.IntAttrib'>)]
xml_tag = 'Segment'
class autosnapgene.Reference(**kwargs)[source]
repr_attrs = ('pubmed_id',)
xml_attrib_defs = [('title', 'title', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('pubmed_id', 'pubMedID', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('journal', 'journal', <class 'autosnapgene.parser.Xml.TextAttrib'>), ('authors', 'authors', <class 'autosnapgene.parser.Xml.TextAttrib'>)]
xml_tag = 'Reference'
class autosnapgene.BlockNotFound[source]
class autosnapgene.SequenceNotFound[source]
class autosnapgene.FeatureNotFound[source]