Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5847997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:47:52+00:00 2026-05-22T12:47:52+00:00

I am having an issue with writing a list to a file. I am

  • 0

I am having an issue with writing a list to a file. I am annotating certain files to change them into a certain format, so I read sequence alignment files, store them in lists, do necessary formatting, and then write them to a new file. The problem is that while my list, containing sequence alignments is structured correctly, the output produced when it writes them to new files is incorrect (it does not replicate my list structure). I include only a section of my output and what it should look like because the list itself if far too long to post.

OUTPUT WRITTEN TO FILE:

>
TRFE_CHICK 

From XALIGN

MKLILCTVLSLGIAAVCFAAP (seq spans multiple lines) ...

ADYIKAVSNLRKCS--TSRLLEAC*> (end of sequence, * should be on a newline, followed by > on a newline as well)

OUTPUT IS SUPPOSED TO BE WRITTEN AS:

>

TRFE_CHICK

From XALIGN

MKLILCTVLSLGIAAVCFAAP (seq spans many lines) ...

ADYIKAVSNLRKCS--TSRLLEAC

*

>

It does this misformatting multiple times over. I have tried pickling and unpickling the list but that misformats it further.

My code for producing the list and writing to file:

new = []
for line in alignment1:
    if line.endswith('*\n'):
        new.append(line.strip('*\n'))
        new.append('*')
   else:
        new.append(line)

new1 = []
for line in new:
    if line.startswith('>'):
        twolines = line[0] + '\n' + line[1:]
        new1.append(twolines)
        continue
    else:
        new1.append(line)

for line in new1:
     alignfile_annot.write(line)

Basically, I have coded it so that it reads the alignment file, inserts a line between the end of the sequence and the * character and also so that > followed by the ID code are always on new lines. This is the way my list is built but not the way it is written to file. Anyone know why the misformatting?
Apologies for the long text, I tried to keep it as short as possible to make my issue clear
I’m running Python 2.6.5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:47:53+00:00Added an answer on May 22, 2026 at 12:47 pm
    new.append(line.strip('*\n'))
    new.append('*')
    

    You have a list of lines (with newline terminators each), so you need to include \n for these two lines, too:

    new.append(line[:-2] + "\n")  # slice as you just checked line.endswith("*\n")
    new.append("*\n")
    

    Remember the strip (or slice, as I’ve changed it to) will remove the newline, so splitting a single item in the list with a value of “…*\n” into two items of “…” and “*” actually removes a newline from what you had originally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue writing a tough query. I have the following table (as
I'm writing an app in MonoMac and its having an issue where if I
Rrom C#, reading/writing over SOCKET to JAVA and having some concurrency/socket issue. I am
I'm having an issue with writing back to my Access Database (.accdb) through using
I'm writing a unit test for some simple methods. The issue I am having
I'm writing an IRC client in C++ and currently I'm having an issue where,
I'm currently having an issue with a trigger I'm writing. I want to do
I've run into another issue while writing this code (with MUCH help from programmers
I have a car rental application I am writing. I am having some issue.
This might be a simple answer, but I am having some issues writing this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.