<p>I read the Biopython Genbank record source code carefully and realized I wasn’t using the Qualifier class correctly. </p>

<p>After reading the source code again, I realized I was using the data structure incorrectly.  I need to use the Qualifier class to add a key and feature.  This is formatted correctly and solves the problem.</p>

<pre><code>feature = Feature()
# Strict Genbank format calls non-standard things misc_feature
feature.key = "misc_feature"
#need to add 1 to start list since csv counting is off
feature.location = "{}..{}".format(int(start_list[i]) +1, end_list[i])
liability_qualifier = Qualifier()
liability_qualifier.key = '/note="'
liability_qualifier.value = '\"{}\"'.format(liability).split(":")[1]
feature.qualifiers.append(liability_qualifier)
</code></pre>

CC BY-SA 4.0
2019-09-21T22:24:34.710Z
Thanks for posting back and explaining the answer to the rest of us
M__
CC BY-SA 4.0
2019-09-21T16:28:36.447Z
2019-09-21T16:42:48.730Z
2019-09-21T16:42:48.730Z
JoeT
<p>I am parsing a csv file of annotated sequences and using Biopython to generate Genbank files for each. I want to add annotations of the sequence features.</p>

<p>My output file shows features listed without the correct line breaks. Other software is then unable to parse the names of the features</p>

<pre><code>misc_feature    58..60  /note="Oxidation"
misc_feature    100..102  /note="Oxidation"
misc_feature    241..243  /note="Oxidation"
</code></pre>

<p>It should be formatted like this</p>

<pre><code>misc_feature    58..60  
                /note="Oxidation"
misc_feature    100..102  
                /note="Oxidation"
misc_feature    241..243  
                /note="Oxidation"
</code></pre>

<p>My section of code adds a space between the location and the /note="" but the Biopython writer doesn't add line breaks.</p>

<pre><code>for i in range(len(start_list)):
    feature = Feature()
# Strict Genbank format calls non-standard things misc_feature
    feature.key = "misc_feature"
    liab_type = "{}".format(liability).split(":")[1]
#need to add 1 to start list since csv counting is off
    feature.location = "{}..{}".format(int(start_list[i]) +1, end_list[i]) + "  " + '/note=\"{}\"'.format(liab_type)
    container.features.append(feature)
    i +=1
</code></pre>

<p>The Biopython source is toggling the wrapping of the feature qualifiers on <code>no_space_key</code> and <code>Bio.GenBank._BaseGenBankConsumer.remove_space_keys</code></p>

<p>How do I enable wrapping of text to format output correctly?</p>

<pre><code>    def __str__(self):
    """Return feature as a GenBank format string."""
    output = Record.INTERNAL_FEATURE_FORMAT % self.key
    output += _wrapped_genbank(self.location, Record.GB_FEATURE_INDENT,
                               split_char=',')
    for qualifier in self.qualifiers:
        output += " " * Record.GB_FEATURE_INDENT

        # determine whether we can wrap on spaces
        space_wrap = 1
        for no_space_key in \
                Bio.GenBank._BaseGenBankConsumer.remove_space_keys:
            if no_space_key in qualifier.key:
                space_wrap = 0

        output += _wrapped_genbank(qualifier.key + qualifier.value,
                                   Record.GB_FEATURE_INDENT, space_wrap)
    return output
</code></pre>

CC BY-SA 4.0
2019-09-20T07:14:21.317Z
Glad you found the solution!, The way to signal that the question is solved is posting your own question and selecting it as the one that resulted more helpful. This will unify the style for all questions and answers and make it easier for people to find the solution to your question.
llrs
<python><genbank>
Biopython Genbank writer not splitting long lines
# Biopython Genbank writer not splitting long lines

(Asked by: username_0 on 2019-09-18)

I am parsing a csv file of annotated sequences and using Biopython to generate Genbank files for each. I want to add annotations of the sequence features.
My output file shows features listed without the correct line breaks. Other software is then unable to parse the names of the features
misc_feature    58..60  /note="Oxidation"
misc_feature    100..102  /note="Oxidation"
misc_feature    241..243  /note="Oxidation"

It should be formatted like this
misc_feature    58..60  
                /note="Oxidation"
misc_feature    100..102  
                /note="Oxidation"
misc_feature    241..243  
                /note="Oxidation"

My section of code adds a space between the location and the /note="" but the Biopython writer doesn't add line breaks.
for i in range(len(start_list)):
    feature = Feature()
# Strict Genbank format calls non-standard things misc_feature
    feature.key = "misc_feature"
    liab_type = "{}".format(liability).split(":")[1]
#need to add 1 to start list since csv counting is off
    feature.location = "{}..{}".format(int(start_list[i]) +1, end_list[i]) + "  " + '/note=\"{}\"'.format(liab_type)
    container.features.append(feature)
    i +=1

The Biopython source is toggling the wrapping of the feature qualifiers on no_space_key and Bio.GenBank._BaseGenBankConsumer.remove_space_keys
How do I enable wrapping of text to format output correctly?
    def __str__(self):
    """Return feature as a GenBank format string."""
    output = Record.INTERNAL_FEATURE_FORMAT % self.key
    output += _wrapped_genbank(self.location, Record.GB_FEATURE_INDENT,
                               split_char=',')
    for qualifier in self.qualifiers:
        output += " " * Record.GB_FEATURE_INDENT

        # determine whether we can wrap on spaces
        space_wrap = 1
        for no_space_key in \
                Bio.GenBank._BaseGenBankConsumer.remove_space_keys:
            if no_space_key in qualifier.key:
                space_wrap = 0

        output += _wrapped_genbank(qualifier.key + qualifier.value,
                                   Record.GB_FEATURE_INDENT, space_wrap)
    return output

**Tags:** python, genbank
> **Comments:**
> **username_1**: Glad you found the solution!, The way to signal that the question is solved is posting your own question and selecting it as the one that resulted more helpful. This will unify the style for all questions and answers and make it easier for people to find the solution to your question.  

---

## 1 answers

### Answer by username_0 on 2019-09-21. Score: 1 | Accepted answer

I read the Biopython Genbank record source code carefully and realized I wasn’t using the Qualifier class correctly. 
After reading the source code again, I realized I was using the data structure incorrectly.  I need to use the Qualifier class to add a key and feature.  This is formatted correctly and solves the problem.
feature = Feature()
# Strict Genbank format calls non-standard things misc_feature
feature.key = "misc_feature"
#need to add 1 to start list since csv counting is off
feature.location = "{}..{}".format(int(start_list[i]) +1, end_list[i])
liability_qualifier = Qualifier()
liability_qualifier.key = '/note="'
liability_qualifier.value = '\"{}\"'.format(liability).split(":")[1]
feature.qualifiers.append(liability_qualifier)

> **Comments:**
> **username_2**: Thanks for posting back and explaining the answer to the rest of us  

---

