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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:24:23+00:00 2026-06-02T18:24:23+00:00

I have a list of rules for a given input file for my function.

  • 0

I have a list of rules for a given input file for my function. If any of them are violated in the file given, I want my program to return an error message and quit.

  • Every gene in the file should be on the same chromosome

Thus for a lines such as:

NM_001003443 chr11 + 5997152 5927598 5921052 5926098 1 5928752,5925972, 5927204,5396098,
NM_001003444 chr11 + 5925152 5926098 5925152 5926098 2 5925152,5925652, 5925404,5926098,
NM_001003489 chr11 + 5925145 5926093 5925115 5926045 4 5925151,5925762, 5987404,5908098,
etc.

Each line in the file will be variations of this line

Thus, I want to make sure every line in the file is on chr11

Yet I may be given a file with a different list of chr(and any number of numbers). Thus I want to write a function that will make sure whatever number is found on chr in the line is the same for every line.

Should I use a regular expression for this, or what should I do? This is in python by the way.

Such as: chr\d+ ?
I am unsure how to make sure that whatever is matched is the same in every line though…

I currently have:

from re import *
for line in file:
    r = 'chr\d+'
    i = search(r, line)
    if i in line:

but I don’t know how to make sure it is the same in every line…

In reference to sajattack’s answer

fp = open(infile, 'r')
for line in fp:
        filestring = ''
        filestring +=line
        chrlist = search('chr\d+', filestring)
        chrlist = chrlist.group()
        for chr in chrlist:
            if chr != chrlist[0]:
                print('Every gene in file not on same chromosome')
  • 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-02T18:24:28+00:00Added an answer on June 2, 2026 at 6:24 pm

    Just read the file and have a while loop check each line to make sure it contains chr11. There are string functions to search for substrings in a string. As soon as you find a line that returns false (does not contain chr11) then break out of the loop and set a flag valid = false.

    import re
    
    fp = open(infile, 'r')
    fp.readline()
    tar = re.findall(r'chr\d+', fp.readline())[0]
    for line in fp:
        if (line.find(tar) == -1):
            print("Not valid")
            break
    

    This should search for a number in the line and check for validity.

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

Sidebar

Related Questions

I have a list of rules for a given input file for my function.
I have a list of rewrite rules, but one of the rules is applying
I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule
I have a make rule which generates a dependencies file for a list of
I have List I want to sort Desc by Priority, which is int and
I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy
I want to refine the raw text by using regular expression, given a list
I have the following rules in my htaccess: RewriteRule ^([^/.]+)/?$ list.php?categoryShortForm=$1&locationShortForm=world [QSA] RewriteRule ^([^/.]+)/([^/.]+)/?$
I have a table that is storing a list of rules. In my code,
Does anyone have a list of rough rule-of-thumb estimators for the various data structures?

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.