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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:44:30+00:00 2026-05-27T10:44:30+00:00

def __init__(self,emps=str(),l=[>]): self.str=emps self.bl=l def fromFile(self,seqfile): opf=open(seqfile,’r’) s=opf.read() opf.close() lisst=s.split(>) if s[0]==>: lisst.pop(0) nlist=[]

  • 0
def __init__(self,emps=str(""),l=[">"]):
    self.str=emps
    self.bl=l


def fromFile(self,seqfile):
    opf=open(seqfile,'r')                                       
    s=opf.read()                                              
    opf.close()                                                    
    lisst=s.split(">")                                             
    if s[0]==">":
        lisst.pop(0)                                                    
    nlist=[]
    for x in lisst:
        splitenter=x.split('\n')                                        
        splitenter.pop(0)                                               
        splitenter.pop()                                                
        splitstring="".join(splitenter)                                 
        nlist.append(splitstring)                                       
    nstr=">".join(nlist)                                                
    nstr=nstr.split()
    nstr="".join(nstr)
    for i in nstr:
        self.bl.append(i)
    self.str=nstr
    return nstr

def getSequence(self):
    print self.str
    print self.bl
    return self.str

def GpCratio(self):
    pgenes=[]
    nGC=[]
    for x in range(len(self.lb)):                                   
        if x==">":
            pgenes.append(x)                                           
    for i in range(len(pgenes)):                                        
        if i!=len(pgenes)-1:                                            
            c=krebscyclus[pgenes[i]:pgenes[i+1]].count('c')+0.000       
            g=krebscyclus[pgenes[i]:pgenes[i+1]].count('g')+0.000                                          
            ratio=(c+g)/(len(range(pgenes[i]+1,pgenes[i+1])))
            nGC.append(ratio)                                           
    return nGC  

s = Sequence()
s.fromFile('D:\Documents\Bioinformatics\sequenceB.txt')
print 'Sequence:\n', s.getSequence(), '\n'
print "G+C ratio:\n", s.GpCratio(), '\n'

I dont understand why it gives the error:

in GpCratio     for x in range(len(self.lb)): AttributeError: Sequence instance has no attribute 'lb'. 

When i print the list in def getSequence it prints the correct DNA sequenced list, but i can not use the list for searching for nucleotides. My university only allows me to input 1 file and not making use of other arguments in definitions, but “self”
btw, it is a class, but it refuses me to post it then.. class called Sequence


  • 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-27T10:44:30+00:00Added an answer on May 27, 2026 at 10:44 am

    Looks like a typo. You define self.bl in your __init__() routine, then try to access self.lb.

    (Also, emps=str("") is redundant – emps="" works just as well.)

    But even if you correct that typo, the loop won’t work:

    for x in range(len(self.bl)):   # This iterates over a list like [0, 1, 2, 3, ...]
        if x==">":                  # This condition will never be True
            pgenes.append(x) 
    

    You probably need to do something like

    pgenes=[]
    for x in self.bl:
        if x==">":                  # Shouldn't this be != ?
            pgenes.append(x) 
    

    which can also be written as a list comprehension:

    pgenes = [x for x in self.bl if x==">"]
    

    In Python, you hardly ever need len(x) or for n in range(...); you rather iterate directly over the sequence/iterable.

    Since your program is incomplete and lacking sample data, I can’t run it here to find all its other deficiencies. Perhaps the following can point you in the right direction. Assuming a string that contains the characters ATCG and >:

    >>> gene = ">ATGAATCCGGTAATTGGCATACTGTAG>ATGATAGGAGGCTAG"
    >>> pgene = ''.join(x for x in gene if x!=">")
    >>> pgene
    'ATGAATCCGGTAATTGGCATACTGTAGATGATAGGAGGCTAG'
    >>> ratio = float(pgene.count("G") + pgene.count("C")) / (pgene.count("A") + pgene.count("T"))
    >>> ratio
    0.75
    

    If, however, you don’t want to look at the entire string but at separate genes (where > is the separator), use something like this:

    >>> gene = ">ATGAATCCGGTAATTGGCATACTGTAG>ATGATAGGAGGCTAG"
    >>> genes = [g for g in gene.split(">") if g !=""]
    >>> genes
    ['ATGAATCCGGTAATTGGCATACTGTAG', 'ATGATAGGAGGCTAG']
    >>> nGC = [float(g.count("G")+g.count("C"))/(g.count("A")+g.count("T")) for g in genes]
    >>> nGC
    [0.6875, 0.875]
    

    However, if you want to calculate GC content, then of course you don’t want (G+C)/(A+T) but (G+C)/(A+T+G+C) –> nGC = [float(g.count("G")+g.count("C"))/len(g)].

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

Sidebar

Related Questions

class ClassName(object): def __init__(self, foo, bar): self.foo = foo # read-write property self.bar =
class Num: def __init__(self,num): self.n = num I read that the __init__ method returns
# file1.py class _Producer(self): def __init__(self): self.chunksize = 6220800 with open('/dev/zero') as f: self.thing
class A(): def __init__(self, data=''): self.data = data def __str__(self): return str(self.data) d =
class Foo(object): def __init__(self,x): self.x = x self.is_bar = False def __repr__(self): return str(self.x)
class File(object): def __init__(self, filename): if os.path.isfile(filename): self.filename = filename self.file = open(filename, 'rb')
Code: class MyClass: def __init__(self, aa ): print('aa='+str(aa)+' of type '+str(type(aa))) self.aa = aa,
I have this code: def __init__(self, a, b, c, d...): self.a = a self.b
Normal way: class A: def __init__(self): self.a.b.c = 10 def another_method(self): self.a.b.c = self.a.b.c
class Packagings: def __init__(self): self.length=0 self.deckle=0 self.tmp=0 self.flute=[] self.gsm=[] self.t_weight=0 self.weight=0 def read_values(self): print

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.