Browse Source

Write Features segment to SnapGene file.

snapgene-write
Damien Goutte-Gattat 2 years ago
parent
commit
4078e160ab
  1. 46
      incenp/bio/seqio/SnapGeneIO.py

46
incenp/bio/seqio/SnapGeneIO.py

@ -295,6 +295,18 @@ class SnapGeneWriter(SequenceWriter):
notes.append('<AccessionNumber>%s</AccessionNumber>' % record.id)
self._write_xml_segment(_NOTES_SEGMENT, 'Notes', notes)
features = []
for feature in [f for f in record.features if f.type != 'primer_bind']:
features.extend(self._feature_to_snapgene_xml(feature))
if features:
self._write_xml_segment(_FEATURES_SEGMENT, 'Features', features)
primers = []
for feature in [f for f in record.features if f.type == 'primer_bind']:
primers.extend(self._primer_to_snapgene_xml(feature))
if primers:
self._write_xml_segment(_PRIMERS_SEGMENT, 'Primers', primers)
return 1
@ -306,3 +318,37 @@ class SnapGeneWriter(SequenceWriter):
def _write_segment(self, type, data):
self.handle.write(pack('>BI', type, len(data)))
self.handle.write(data)
def _feature_to_snapgene_xml(self, feature):
xml = []
name = 'Unnamed feature'
if 'label' in feature.qualifiers:
name = feature.qualifiers['label'][0]
elif 'gene' in feature.qualifiers:
name = feature.qualifiers['gene'][0]
elif 'note' in feature.qualifiers:
name = feature.qualifiers['note'][0]
directionality = 0
if feature.strand == 1:
directionality = 1
elif feature.strand == -1:
directionality = 2
xml.append('<Feature name="%s" directionality="%d" type="%s">'
% (name, directionality, feature.type))
xml.append('<Segment range="%d-%d" type="standard" />'
% (feature.location.start + 1, feature.location.end))
for name in feature.qualifiers.keys():
xml.append('<Q name="%s"><V text="%s"/></Q>'
% (name, feature.qualifiers[name][0]))
xml.append('</Feature>')
return xml
def _primer_to_snapgene_xml(self, record):
return []
Loading…
Cancel
Save