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 6769661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:13:12+00:00 2026-05-26T15:13:12+00:00

I have a text file (bowtie alignment file) that looks like this: read_1 +

  • 0

I have a text file (bowtie alignment file) that looks like this:

read_1  +   345995|PACid:16033981   599 AGTAGTAATCAGTCACCCGCAAGGTAGACAAGG   qqqqqqqqqqqqqqqqqqqqq!!qqqqqqqqqq   0   
read_2  +   949205|PACid:16054220   338 TACCAGCACTAATGCACCGGATCCCATCAGATC   qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq!!q   0   31:A>T
read_3  +   932004|PACid:16034380   1226    GGCACCTTATGAGAAATCAAAGTTTTTGGGTTC   qqqqqqqqqqqqqqq!!qqqqqqqqqqqqq!!q   3   

I want to subtract one from Column #4 (the position), and print each line with the updated value.

I can read the file, then separated the fields based on tab, and also identify Column #4 as data[3], but then I am stuck with subtracting one from each value in Column #4 and printing all the fields in each line with updated value for Column #4.

How can I do this using Python?

I tried something like this:

in_file = open(sys.argv[1],'r')
out_file = open(sys.argv[2], 'w')
for line in in_file: 
    data = line.rstrip().split('\t') 
    position = int(float(data[3]) -1)

but I am not sure about how to proceed with printing the lines with updated position.

  • 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-26T15:13:12+00:00Added an answer on May 26, 2026 at 3:13 pm

    Use the csv module, informing it your field delimiter is a tab:

    from io import StringIO
    
    indata = StringIO(u"""read_1    +   345995|PACid:16033981   599 AGTAGTAATCAGTCACCCGCAAGGTAGACAAGG   qqqqqqqqqqqqqqqqqqqqq!!qqqqqqqqqq   0
    read_2  +   949205|PACid:16054220   338 TACCAGCACTAATGCACCGGATCCCATCAGATC   qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq!!q   0   31:A>T
    read_3  +   932004|PACid:16034380   1226    GGCACCTTATGAGAAATCAAAGTTTTTGGGTTC   qqqqqqqqqqqqqqq!!qqqqqqqqqqqqq!!q   3
    """)
    
    # that StringIO stuff is just for testing, you should do
    # with open('your_file_name', 'r') as indata:
    # before the 'for' loop, and then indent the rest one level.
    
    from csv import reader
    
    for line in reader(indata, delimiter='\t'):
        if len(line) > 3:
            line[3] = str(int(line[3]) - 1)
        print '\t'.join(line)
    

    Then just convert the position to a number, subtract one, convert it back, and print the line.

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

Sidebar

Related Questions

i have text file that looks like this: 1 \t a 2 \t b
I have a text file that looks something like this where the first column
I have text file looks like that: float a[10] = { 7.100000e+000 , 9.100000e+000
I have a text file that has a list of directory names like this:
I have a text file that looks like: text texttext texttext texttext texttext text
I have a text file that is like this: FOO BAR PIPPO PLUTO 31337
I have text file with a row like this: SendersTimeSeriesIdentification: COMPANY_A/COMPANY_B/REF_7/20090505 I'd like to
I have text file with some stuff that i would like to put into
I have a text file with something like this in it. Tom 1 2
i have text file like this: i am fine how are you what i

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.