Welcome, guest | Sign In | My Account | Store | Cart

Calculate Area Under Disease Progressive Curve

Python, 48 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#donyo@abv.bg
choice=None
def AUDPC():
      num_ob=input('Enter the number of observations: ')
      di=[0]*num_ob
      tim=[0]*num_ob
      index=0
      while index<num_ob:
                  di[index]=input('Enter the value of the Index of Makkiney: ')
                  index+=1
      index1=0
      while index1<num_ob:
                 tim[index1]=input('Enter the time of the observation in days: ')
                 index1=index1+1
                 meanvec=[0]*(num_ob-1)
                 intvec=[0]*(num_ob-1)

      x=0
      while x<(num_ob-1):
                meanvec[x]=(di[x]+di[x+1])/2
                x+=1

      y=0
      while y<(num_ob-1):
                  intvec[y]=tim[y+1]-tim[y]
                  y+=1

      sumvec=[meanvec[i]*intvec[i] for i in range(len(meanvec))]
      audpc=sum(sumvec)
      print \
            """"
"""
      print "AUDPC in percent-days: ", audpc
      r_audpc=audpc/max(tim)
      print "Relative AUDPC: ", r_audpc

while choice!="0":
      print \
      """
     AUDPC Calculation Program created by Donyo Ganchev
     1 - Begin calculation
     0 - Exit
     """
      choice= raw_input("Choice: ")
      if choice == "0":
                  exit()
      elif choice=="1":
             AUDPC ()





    


    
    

    




      
                      
                      


                      

2 comments

David Lambert 13 years, 1 month ago  # | flag

index, index1, x, y, and i? These variables aren't going anywhere, that's why coders just stick in i.

for this sort of construct:

  y=0
  while y<(num_ob-1):
      intvec[y]=tim[y+1]-tim[y]
      y+=1

use the common idiom, so that it's readable, (and it does matter when the lists get to be a million elements long):

  for i in range(num_ob-1):
      intvec[i]=tim[i+1]-tim[i]

But look, this repetitive question/answer input method reduces your beautiful computer to an antique desk calculator. There's no easy way to correct input errors. Most of the program's output is boring as heck, "Enter this thing-a-ma-bob". Instead, store the input in a file which you can verify in a text editor, then process the file all at once, output of the program then would just then be the important stuff.

donyo Ganchev (author) 13 years, 1 month ago  # | flag

the code:

for i in range(num_ob-1): intvec[i]=tim[i+1]-tim[i]

spend only y=0 and y+=1 and I don't thing that this is more readable. According to " store the input in a file" - the idea of this script is to be converted in binary with py2exe as simple console program. In future will be created a GUI with Tinker

Created by donyo Ganchev on Wed, 29 Oct 2008 (MIT)
Python recipes (4591)
donyo Ganchev's recipes (11)

Required Modules

  • (none specified)

Other Information and Tasks