Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class problem
#1
Does anyone help me fix bugs here?
It works well when I type a.seqtosymbols() first and then a.periods().
But what I want to do is to call a.periods() separately without the seqtosymbols() first.

Many thanks,

My link: https://bpaste.net/raw/OUNQ

import numpy
from numpy import array, exp, pi, arange, float64
class ipdft(object):
    def __init__(self, seq, dints,period = None):
        self.seq = seq
        self.length = len(seq)
        self.dints = dints
        
    def seqtosymbols(self):
        self.result = numpy.zeros(self.length, numpy.uint8) #create arrays array([1, 0], dtype=uint8) 
        for i in range(0,self.length-1):
            if self.seq[i:i+2] in self.dints:
                self.result[i] = 1
        return self.result

    def ipdft_inner(self, X, W, ulim, N):
        for p in range(ulim):
            w = 1
            for n in range(N):
                if n != 0:
                    w *= W[p]
                X[p] = X[p] + self.result[n] * w
        return X
    
    def period(self, llim = None, ulim = None):
        self.llim = 2
        self.ulim = self.length - 1
        self.periods = array(range(self.llim, self.ulim + 1))
        self.W = exp(-1j*2*pi/arange(1, self.ulim + 1))
        self.X = array([0 + 0j]*self.length)
        self.X = self.ipdft_inner(self.X, self.W, self.ulim, self.length)
        power = abs(self.X[self.llim-1:self.ulim])
        #if self.period is not None:
            #return power[self.period-2]
        #return array(power), self.period
        return self.periods
 
a = ipdft("ATGTATTGCTAAAAATAGCAATAAATAGCATAATTAAGCTTATTTATTTT","GC")
Reply
#2
you don't have a method named a.periods()
how about a.period()
Reply
#3
If you call a.period() first, it calls a.ipdft_inner() in line 31. If you have not defined a.result, then you will get an attribute error in line 22.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 255 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Practice problem using lambda inside the class jagasrik 3 2,170 Sep-12-2020, 03:18 PM
Last Post: deanhystad
  [split] Python Class Problem astral_travel 12 4,987 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 2,295 Apr-28-2020, 06:18 PM
Last Post: buran
  Class code problem from CS Dojo YouTube Dixon 3 2,272 Feb-04-2020, 10:23 PM
Last Post: snippsat
  Class Problem scratchmyhead 3 2,324 Nov-19-2019, 08:28 AM
Last Post: Larz60+
  problem with class method AmirAB 3 3,392 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  A problem with child class Truman 2 2,791 Jul-02-2018, 12:37 AM
Last Post: ichabod801
  problem with simple class code diegoraffo 5 3,697 Jan-27-2018, 02:31 AM
Last Post: ka06059

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020