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

  • Home
  • SEARCH
  • 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 8233813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:15:29+00:00 2026-06-07T18:15:29+00:00

I have a large file which I want to format in a certain manner.

  • 0

I have a large file which I want to format in a certain manner. File input example:

DVL1    03220   NP_004412.2 VANGL2  02758   Q9ULK5  in vitro    12490194
PAX3    09421   NP_852124.1 MEOX2   02760   NP_005915.2 in vitro;yeast 2-hybrid 11423130
VANGL2  02758   Q9ULK5  MAGI3   11290   NP_001136254.1  in vitro;in vivo    15195140

And this is how I want it to become:

DVL1    03220   NP_004412   VANGL2  02758   Q9ULK5
PAX3    09421   NP_852124   MEOX2   02760   NP_005915
VANGL2  02758   Q9ULK5  MAGI3   11290   NP_001136254

To summarize:

  • if the line has 1 dot, that dot is deleted along with the number after it and a \t is added, so the output line will only have 6 tab-separated values
  • if the line has 2 dots, those dots are deleted along with the numbers after them and a \t is added, so the output line will only have 6 tab-separated values
  • if the line has no dots, maintain the first 6 tab-separated values

My idea is currently something like this:

for line in infile:
    if "." in line: # thought about this and a line.count('.') might be better, just wasn't capable to make it work
        transformed_line = line.replace('.', '\t', 2) # only replaces the dot; want to replace dot plus next first character
        columns = transformed_line.split('\t')
        outfile.write('\t'.join(columns[:8]) + '\n') # if i had a way to know the position of the dot(s), i could join only the desired columns
    else:
        columns = line.split('\t')
        outfile.write('\t'.join(columns[:5]) + '\n') # this is fine

Hope I explained myself ok.
Thanks for you guys effort.

  • 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-06-07T18:15:30+00:00Added an answer on June 7, 2026 at 6:15 pm

    you can try something like this:

        with open('data1.txt') as f:
            for line in f:
                line=line.split()[:6]
                line=map(lambda x:x[:x.index('.')] if '.' in x else x,line)  #if an element has '.' then
                                                                             #remove that dot else keep the element as it is
                print('\t'.join(line))
    

    output:

    DVL1    03220   NP_004412   VANGL2  02758   Q9ULK5
    PAX3    09421   NP_852124   MEOX2   02760   NP_005915
    VANGL2  02758   Q9ULK5  MAGI3   11290   NP_001136254
    

    Edit:

    as @mgilson suggested the line line=map(lambda x:x[:x.index('.')] if '.' in x else x,line) can be replaced by simply line=map(lambda x:x.split('.')[0],line)

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

Sidebar

Related Questions

iPad application I have a large text file which I want to divide into
Assume that we have a large file which can be read in chunks of
I have a large 100mb file which I would like to perform about 5000
I have a large XML file which in the middle contains the following: <ArticleName>Article
I have a very large XML file which has like 40000 data, and when
I have a rather large SQL file which starts with the byte order marker
I have a large C++ file (SS.cpp) which I decided to split in smaller
I have a large binary file (700 Mb approximately) which I load to TMemoryStream.
I have a highly formatted file with large amount of data which I used
I have a large file I want to download from a server I have

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.