Bottom Page

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")
Yoriz wrote Feb-10-2020, 07:31 PM:
Please post all code, output and errors (in its entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
you don't have a method named a.periods()
how about a.period()
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [split] Python Class Problem astral_travel 12 318 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 272 Apr-28-2020, 06:18 PM
Last Post: buran
  Class code problem from CS Dojo YouTube Dixon 3 280 Feb-04-2020, 10:23 PM
Last Post: snippsat
  Class Problem scratchmyhead 3 340 Nov-19-2019, 08:28 AM
Last Post: Larz60+
  problem with class method AmirAB 3 637 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  A problem with child class Truman 2 786 Jul-02-2018, 12:37 AM
Last Post: ichabod801
  problem with simple class code diegoraffo 5 1,293 Jan-27-2018, 02:31 AM
Last Post: ka06059

Forum Jump:


Users browsing this thread: 1 Guest(s)