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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:19:17+00:00 2026-05-29T21:19:17+00:00

I am not a programmer, but I am taking a bioinformatics class as I’m

  • 0

I am not a programmer, but I am taking a bioinformatics class as I’m a molecular genetics major… our assignment is to take a file of multiple entries like this:

77: XP_001929585
PREDICTED: similar to BRCA1 associated protein [Sus scrofa]
gi|194042959|ref|XP_001929585.1| [194042959]

and extract the items I’ve bolded, then save the results into a pipe-delimited file like this:

194042959|Sus scrofa|PREDICTED: similar to BRCA1 associated protein.

We are using the Sublime editor to write our scripts in Ruby. I know how to open the file and then… well, here’s my script so far…

#!/usr/local/bin/ruby
File.open("mmg231_hw5_brca1.txt").each do |file_line|
  if file_line =~ /^(.+)\[([A-Z].+)\]/
    description = $1
    taxon_name = $2
    puts "#{taxon_name}|#{description}" 
  elsif file_line =~ /\[([0-9].+)\]/
    gi_number = $1
    puts "#{gi_number}"
  end
end

I know that it’s wrong… the regular expressions do capture what they need to. the first puts does put out the taxon name and the description properly, but I can’t figure out how to get the gi number in there too, as its on a different line… I can pull out the gi number on its own also, but have no way of linking it to the other two parts. Also, when I pull them out using the regular expressions I developed, they stay in the right order as they were in the file, so I was trying to think of a way to tell the computer to like number each taxon name/description pair 1, 2, 3, etc as in the file, and then do the same with the gi numbers, and then you could just say like taxon name/description 1 goes with gi number 1, etc… or have the computer get the taxon name and description pair, then just look in the next line for the gi number, but I don’t know how to do this…

help? And in plain english would be helpful, most help sites I feel like I would be able to use, but I just don’t understand the language…

first 4 entries:

1: ZP_00239925
BRCA1 [Bacillus cereus G9241]
gi|47569239|ref|ZP_00239925.1||gnl|WGS:NZ_AAEK|BCE_G9241_3679 [47569239]

2: NP_009225
breast cancer 1, early onset isoform 1 [Homo sapiens]
gi|6552299|ref|NP_009225.1| [6552299]

3: NP_033894
breast cancer 1 [Mus musculus]
gi|161016835|ref|NP_033894.3| [161016835]

4: NP_036646
breast cancer 1 [Rattus norvegicus]
gi|6978573|ref|NP_036646.1| [6978573]
  • 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-29T21:19:18+00:00Added an answer on May 29, 2026 at 9:19 pm

    Do the lines always come in pairs?

    If so, why not doing:

    description = taxon_name = gi_number = nil
    first = false
    File.open("mmg231_hw5_brca1.txt").each do |file_line|
    
      if file_line =~ /^(.+)\[([A-Z].+)\]/    
        description = $1
        taxon_name = $2
        first = true #Just to check they are consecutive 
      else
        if file_line =~ /\[([0-9].+)\]/
          gi_number = $1
          if first == true
            puts "#{gi_number}|#{taxon_name}|#{description}"
          end
        end
        first = false
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not generally a GUI programmer but as luck has it, I'm stuck building
I am a hacker not and not a full-time programmer but am looking to
First, let me say I'm not a professional programmer, but an engineer who had
I'm an old (but not too old) Java programmer, that decided to learn C++.
I'm wondering what you do as a programmer that's not programming but necessary for
I am not really a programmer but am asking this out of general curiosity.
I am not the only programmer, but I'm the only .NET developer, everyone else
New to Microsoft Web Developer 2010 Express, and not an accomplished programmer, but I
I am unfortunately not the best Jquery programmer but I thought I would give
I'm new here and I'm also not much of a programmer but I hope

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.