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
  Practice problem using lambda inside the class jagasrik 3 2,107 Sep-12-2020, 03:18 PM
Last Post: deanhystad
  [split] Python Class Problem astral_travel 12 4,823 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 2,230 Apr-28-2020, 06:18 PM
Last Post: buran
  Class code problem from CS Dojo YouTube Dixon 3 2,218 Feb-04-2020, 10:23 PM
Last Post: snippsat
  Class Problem scratchmyhead 3 2,260 Nov-19-2019, 08:28 AM
Last Post: Larz60+
  problem with class method AmirAB 3 3,331 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  A problem with child class Truman 2 2,737 Jul-02-2018, 12:37 AM
Last Post: ichabod801
  problem with simple class code diegoraffo 5 3,618 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