gravelLab / tracts

A set of tools for modelling ancestry patterns along the genome.
GNU General Public License v2.0
22 stars 14 forks source link

Problems of installing tracts and running example files #35

Closed wenyako closed 7 minutes ago

wenyako commented 3 months ago

Dear Prof. Gravel, I am a researcher studying the genetic ancestry of the indigenous Siraya people in Taiwan. I have greatly benefited from your papers working on inferring admixture history based on the information of local genetic ancestry. I want to thank you for your brilliant and invaluable work! We recently attempted to download and install the tracts program but encountered several error messages while running the example files. We are very eager to use tracts to understand the admixture history of the Siraya people (Austronesian-speaking) with the Taiwanese Sino-Tibetan populations. Could you kindly assist us with these issues? Thank you very much for your time and assistance. I really appreciate it.

Best regards, Wen-Ya

As I am not proficient in Python, I will provide a detailed description of my actions. Please forgive the lengthiness of this message.

Running environment: MacBook Pro (Chip:Apple M3 Pro) ; macOS Sonoma Version 14.3.1 Shell:zsh Python: Virtual environment (Python 3.12.4)

Issue description:

  1. The installation went successfully by typing "pip install .". However, error messages appeared when I type: "import tracts" under the python interact console - virtual environment (Python 3.12.4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenko/tracts/tracts/__init__.py", line 9, in <module>
from tracts import logs
ImportError: cannot import name 'logs' from partially initialized module 'tracts' (most likely due to a circular import) (/Users/wenko/tracts/tracts/__init__.py) 

I somehow fixed the problem and executed "import tracts" successfully by the following steps as below. However, I still encountered error messages while running the example files. So I am not sure if I really fixed the problem properly or not.

Here are the steps I did to fix the problem: 1) add the following lines onto the "init.py" file

def initialize():
    from tracts import logs
    logs.setup_logging()

2) created a "tracts/tracts/logs.py" file with the following lines in the file:

def setup_logging():
    from tracts import some_function
    some_function()

def show_INFO():
    # Your show_INFO implementation
    pass

3) created a "tracts/tracts/utlis.py" file with the following lines in the file:

def utility_function():
    pass
  1. I tried to run the examples files stored in the "3Pops" folder, without much success.. here is the error message I got (see the last couple lines at the bottom):
(venv) wenko@Wen-Yas-MacBook-Pro tracts % python taino_ppx_xxp.py
['taino_ppx_xxp.py']
/Users/wenko/tracts/taino_ppx_xxp.py:95: UserWarning: some files in the bed directory were ignored, since they do not end with `.bed`.
  warn("some files in the bed directory were ignored, since they do not "
booted data sample [np.int64(1775), np.int64(1376), np.int64(1108), np.int64(888), np.int64(767), np.int64(630), np.int64(482), np.int64(393), np.int64(344)]
evaluating at params [0.07 0.01]
1       , -4009.37    , array([ 0.07       ,  0.01       ])
evaluating at params [0.07 0.02]
2       , -2865.36    , array([ 0.07       ,  0.02       ])
evaluating at params [0.07 0.03]
3       , -2197.52    , array([ 0.07       ,  0.03       ])
evaluating at params [0.07 0.04]
4       , -1744.82    , array([ 0.07       ,  0.04       ])
evaluating at params [0.07 0.05]
5       , -1417.27    , array([ 0.07       ,  0.05       ])
evaluating at params [0.07 0.06]
6       , -1172.37    , array([ 0.07       ,  0.06       ])
evaluating at params [0.07 0.07]
7       , -1.11762e+32, array([ 0.07       ,  0.07       ])
evaluating at params [0.07 0.08]
/Users/wenko/tracts/tracts/legacy_models/models_3pop.py:151: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  (prop3, prop1) = scipy.optimize.fsolve(fun, (.2, .2)) #(.2,.2) is just the starting point for the optimization function, it should not be sensitive to this, but it's better to start with reasonable parameter values.
8       , -2e+32      , array([ 0.07       ,  0.08       ])
evaluating at params [0.07 0.09]
9       , -2e+32      , array([ 0.07       ,  0.09       ])
evaluating at params [0.07 0.1 ]
10      , -2e+32      , array([ 0.07       ,  0.1        ])
evaluating at params [0.07 0.11]
11      , -2e+32      , array([ 0.07       ,  0.11       ])
evaluating at params [0.08 0.01]
12      , -3460.7     , array([ 0.08       ,  0.01       ])
evaluating at params [0.08 0.02]
13      , -2383.69    , array([ 0.08       ,  0.02       ])
evaluating at params [0.08 0.03]
14      , -1773.48    , array([ 0.08       ,  0.03       ])
evaluating at params [0.08 0.04]
15      , -1370.87    , array([ 0.08       ,  0.04       ])
evaluating at params [0.08 0.05]
16      , -1087.26    , array([ 0.08       ,  0.05       ])
evaluating at params [0.08 0.06]
17      , -881.197    , array([ 0.08       ,  0.06       ])
evaluating at params [0.08 0.07]
18      , -730.392    , array([ 0.08       ,  0.07       ])
evaluating at params [0.08 0.08]
Pulse less than 0
19      , -8.73918e+33, array([ 0.08       ,  0.08       ])
evaluating at params [0.08 0.09]
20      , -2e+32      , array([ 0.08       ,  0.09       ])
evaluating at params [0.08 0.1 ]
21      , -2e+32      , array([ 0.08       ,  0.1        ])
evaluating at params [0.08 0.11]
22      , -2e+32      , array([ 0.08       ,  0.11       ])
evaluating at params [0.09 0.01]
23      , -3031.3     , array([ 0.09       ,  0.01       ])
evaluating at params [0.09 0.02]
24      , -2007.92    , array([ 0.09       ,  0.02       ])
evaluating at params [0.09 0.03]
25      , -1444.52    , array([ 0.09       ,  0.03       ])
evaluating at params [0.09 0.04]
26      , -1083.12    , array([ 0.09       ,  0.04       ])
evaluating at params [0.09 0.05]
27      , -836.049    , array([ 0.09       ,  0.05       ])
evaluating at params [0.09 0.06]
28      , -662.592    , array([ 0.09       ,  0.06       ])
evaluating at params [0.09 0.07]
29      , -541.032    , array([ 0.09       ,  0.07       ])
evaluating at params [0.09 0.08]
30      , -458.784    , array([ 0.09       ,  0.08       ])
evaluating at params [0.09 0.09]
31      , -1.11762e+32, array([ 0.09       ,  0.09       ])
evaluating at params [0.09 0.1 ]
32      , -2e+32      , array([ 0.09       ,  0.1        ])
evaluating at params [0.09 0.11]
33      , -2e+32      , array([ 0.09       ,  0.11       ])
evaluating at params [0.1  0.01]
34      , -2697.2     , array([ 0.1        ,  0.01       ])
evaluating at params [0.1  0.02]
35      , -1717.7     , array([ 0.1        ,  0.02       ])
evaluating at params [0.1  0.03]
36      , -1193.05    , array([ 0.1        ,  0.03       ])
evaluating at params [0.1  0.04]
37      , -866.123    , array([ 0.1        ,  0.04       ])
evaluating at params [0.1  0.05]
38      , -649.87     , array([ 0.1        ,  0.05       ])
evaluating at params [0.1  0.06]
39      , -504.116    , array([ 0.1        ,  0.06       ])
evaluating at params [0.1  0.07]
40      , -407.563    , array([ 0.1        ,  0.07       ])
evaluating at params [0.1  0.08]
41      , -347.986    , array([ 0.1        ,  0.08       ])
evaluating at params [0.1  0.09]
42      , -317.966    , array([ 0.1        ,  0.09       ])
evaluating at params [0.1 0.1]
Pulse less than 0
43      , -8.73918e+33, array([ 0.1        ,  0.1        ])
evaluating at params [0.1  0.11]
44      , -2e+32      , array([ 0.1        ,  0.11       ])
evaluating at params [0.11 0.01]
45      , -2441.44    , array([ 0.11       ,  0.01       ])
evaluating at params [0.11 0.02]
46      , -1498.46    , array([ 0.11       ,  0.02       ])
evaluating at params [0.11 0.03]
47      , -1006.38    , array([ 0.11       ,  0.03       ])
evaluating at params [0.11 0.04]
48      , -708.642    , array([ 0.11       ,  0.04       ])
evaluating at params [0.11 0.05]
49      , -518.684    , array([ 0.11       ,  0.05       ])
evaluating at params [0.11 0.06]
50      , -396.711    , array([ 0.11       ,  0.06       ])
evaluating at params [0.11 0.07]
51      , -321.753    , array([ 0.11       ,  0.07       ])
evaluating at params [0.11 0.08]
52      , -281.85     , array([ 0.11       ,  0.08       ])
evaluating at params [0.11 0.09]
53      , -269.797    , array([ 0.11       ,  0.09       ])
evaluating at params [0.11 0.1 ]
54      , -281.118    , array([ 0.11       ,  0.1        ])
evaluating at params [0.11 0.11]
55      , -1.11762e+32, array([ 0.11       ,  0.11       ])
evaluating at params [0.12 0.01]
56      , -2251.55    , array([ 0.12       ,  0.01       ])
evaluating at params [0.12 0.02]
57      , -1339.4     , array([ 0.12       ,  0.02       ])
evaluating at params [0.12 0.03]
58      , -875.015    , array([ 0.12       ,  0.03       ])
evaluating at params [0.12 0.04]
59      , -602.275    , array([ 0.12       ,  0.04       ])
evaluating at params [0.12 0.05]
60      , -434.962    , array([ 0.12       ,  0.05       ])
evaluating at params [0.12 0.06]
61      , -333.577    , array([ 0.12       ,  0.06       ])
evaluating at params [0.12 0.07]
62      , -277.392    , array([ 0.12       ,  0.07       ])
evaluating at params [0.12 0.08]
63      , -254.657    , array([ 0.12       ,  0.08       ])
evaluating at params [0.12 0.09]
64      , -258.384    , array([ 0.12       ,  0.09       ])
evaluating at params [0.12 0.1 ]
65      , -284.183    , array([ 0.12       ,  0.1        ])
evaluating at params [0.12 0.11]
66      , -329.239    , array([ 0.12       ,  0.11       ])
evaluating at params [0.13 0.01]
67      , -2118.14    , array([ 0.13       ,  0.01       ])
evaluating at params [0.13 0.02]
68      , -1232.3     , array([ 0.13       ,  0.02       ])
evaluating at params [0.13 0.03]
69      , -791.708    , array([ 0.13       ,  0.03       ])
evaluating at params [0.13 0.04]
70      , -540.557    , array([ 0.13       ,  0.04       ])
evaluating at params [0.13 0.05]
71      , -392.901    , array([ 0.13       ,  0.05       ])
evaluating at params [0.13 0.06]
72      , -309.464    , array([ 0.13       ,  0.06       ])
evaluating at params [0.13 0.07]
73      , -269.707    , array([ 0.13       ,  0.07       ])
evaluating at params [0.13 0.08]
74      , -262.046    , array([ 0.13       ,  0.08       ])
evaluating at params [0.13 0.09]
75      , -279.596    , array([ 0.13       ,  0.09       ])
evaluating at params [0.13 0.1 ]
76      , -318.153    , array([ 0.13       ,  0.1        ])
evaluating at params [0.13 0.11]
77      , -375.055    , array([ 0.13       ,  0.11       ])
evaluating at params [0.14 0.01]
78      , -2033.92    , array([ 0.14       ,  0.01       ])
evaluating at params [0.14 0.02]
79      , -1170.75    , array([ 0.14       ,  0.02       ])
evaluating at params [0.14 0.03]
80      , -750.763    , array([ 0.14       ,  0.03       ])
evaluating at params [0.14 0.04]
81      , -518.398    , array([ 0.14       ,  0.04       ])
evaluating at params [0.14 0.05]
82      , -387.916    , array([ 0.14       ,  0.05       ])
evaluating at params [0.14 0.06]
83      , -320.219    , array([ 0.14       ,  0.06       ])
evaluating at params [0.14 0.07]
84      , -294.926    , array([ 0.14       ,  0.07       ])
evaluating at params [0.14 0.08]
85      , -300.604    , array([ 0.14       ,  0.08       ])
evaluating at params [0.14 0.09]
86      , -330.444    , array([ 0.14       ,  0.09       ])
evaluating at params [0.14 0.1 ]
87      , -380.444    , array([ 0.14       ,  0.1        ])
evaluating at params [0.14 0.11]
88      , -447.904    , array([ 0.14       ,  0.11       ])
evaluating at params [0.12 0.08]
89      , -254.657    , array([ 0.12       ,  0.08       ])
evaluating at params [0.126 0.08 ]
90      , -255.175    , array([ 0.126      ,  0.08       ])
evaluating at params [0.12  0.084]
91      , -252.318    , array([ 0.12       ,  0.084      ])
evaluating at params [0.114 0.084]
92      , -260.462    , array([ 0.114      ,  0.084      ])
evaluating at params [0.123 0.081]
93      , -252.852    , array([ 0.123      ,  0.081      ])
evaluating at params [0.123 0.085]
94      , -253.713    , array([ 0.123      ,  0.085      ])
evaluating at params [0.12225 0.08375]
95      , -252.478    , array([ 0.12225    ,  0.08375    ])
evaluating at params [0.11925 0.08675]
96      , -253.775    , array([ 0.11925    ,  0.08675    ])
evaluating at params [0.1220625 0.0824375]
97      , -252.265    , array([ 0.122063   ,  0.0824375  ])
evaluating at params [0.1198125 0.0826875]
98      , -252.57     , array([ 0.119812   ,  0.0826875  ])
evaluating at params [0.12164063 0.08348437]
99      , -252.22     , array([ 0.121641   ,  0.0834844  ])
evaluating at params [0.12370313 0.08192187]
100     , -252.937    , array([ 0.123703   ,  0.0819219  ])
evaluating at params [0.12092578 0.08348047]
101     , -252.159    , array([ 0.120926   ,  0.0834805  ])
evaluating at params [0.12050391 0.08452734]
102     , -252.367    , array([ 0.120504   ,  0.0845273  ])
evaluating at params [0.12167285 0.08295996]
103     , -252.18     , array([ 0.121673   ,  0.08296    ])
evaluating at params [0.12095801 0.08295605]
104     , -252.169    , array([ 0.120958   ,  0.0829561  ])
evaluating at params [0.12021094 0.08347656]
105     , -252.257    , array([ 0.120211   ,  0.0834766  ])
evaluating at params [0.12130737 0.08308911]
106     , -252.15     , array([ 0.121307   ,  0.0830891  ])
evaluating at params [0.12127515 0.08361353]
107     , -252.186    , array([ 0.121275   ,  0.0836135  ])
evaluating at params [0.12103729 0.08312042]
108     , -252.151    , array([ 0.121037   ,  0.0831204  ])
evaluating at params [0.12141888 0.08272906]
109     , -252.174    , array([ 0.121419   ,  0.0827291  ])
evaluating at params [0.12104906 0.08329262]
110     , -252.149    , array([ 0.121049   ,  0.0832926  ])
evaluating at params [0.12131914 0.08326131]
111     , -252.154    , array([ 0.121319   ,  0.0832613  ])
evaluating at params [0.12110775 0.08315564]
112     , -252.148    , array([ 0.121108   ,  0.0831556  ])
evaluating at params [0.12084944 0.08335915]
113     , -252.158    , array([ 0.120849   ,  0.0833591  ])
evaluating at params [0.12119289 0.08315662]
114     , -252.147    , array([ 0.121193   ,  0.0831566  ])
evaluating at params [0.12125159 0.08301965]
115     , -252.151    , array([ 0.121252   ,  0.0830196  ])
evaluating at params [0.12109969 0.08322438]
116     , -252.147    , array([ 0.1211     ,  0.0832244  ])
evaluating at params [0.12118482 0.08322535]
117     , -252.148    , array([ 0.121185   ,  0.0832254  ])
evaluating at params [0.12116556 0.08320793]
118     , -252.147    , array([ 0.121166   ,  0.0832079  ])
evaluating at params [0.12125876 0.08314017]
119     , -252.148    , array([ 0.121259   ,  0.0831402  ])
evaluating at params [0.12113946 0.08320332]
120     , -252.147    , array([ 0.121139   ,  0.0832033  ])
evaluating at params [0.12111212 0.08325463]
121     , -252.148    , array([ 0.121112   ,  0.0832546  ])
evaluating at params [0.1211727  0.08318112]
122     , -252.147    , array([ 0.121173   ,  0.0831811  ])
(array([0.12113946, 0.08320332]), (np.float64(252.14712890712022), array([[[0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07,
         0.07],
        [0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08,
         0.08],
        [0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09,
         0.09],
        [0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 ,
         0.1 ],
        [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11,
         0.11],
        [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12,
         0.12],
        [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13,
         0.13],
        [0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14,
         0.14]],

       [[0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11],
        [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ,
         0.11]]]), array([[4.00937164e+03, 2.86535944e+03, 2.19751656e+03, 1.74481974e+03,
        1.41726543e+03, 1.17236593e+03, 1.11762423e+32, 1.99999999e+32,
        1.99999999e+32, 1.99999999e+32, 1.99999999e+32],
       [3.46069971e+03, 2.38369493e+03, 1.77347622e+03, 1.37087103e+03,
        1.08725574e+03, 8.81197252e+02, 7.30391549e+02, 8.73918033e+33,
        1.99999999e+32, 1.99999999e+32, 1.99999999e+32],
       [3.03129581e+03, 2.00791790e+03, 1.44451546e+03, 1.08312296e+03,
        8.36048848e+02, 6.62592434e+02, 5.41032336e+02, 4.58783952e+02,
        1.11762423e+32, 1.99999999e+32, 1.99999999e+32],
       [2.69720497e+03, 1.71770145e+03, 1.19305416e+03, 8.66123377e+02,
        6.49870230e+02, 5.04115951e+02, 4.07563224e+02, 3.47986448e+02,
        3.17966296e+02, 8.73918033e+33, 1.99999999e+32],
       [2.44144033e+03, 1.49845942e+03, 1.00637807e+03, 7.08642175e+02,
        5.18683935e+02, 3.96711371e+02, 3.21752867e+02, 2.81850080e+02,
        2.69796979e+02, 2.81117640e+02, 1.11762423e+32],
       [2.25155263e+03, 1.33939821e+03, 8.75014534e+02, 6.02274586e+02,
        4.34962250e+02, 3.33576821e+02, 2.77392169e+02, 2.54657012e+02,
        2.58384106e+02, 2.84183226e+02, 3.29238627e+02],
       [2.11814134e+03, 1.23230011e+03, 7.91707774e+02, 5.40557363e+02,
        3.92900964e+02, 3.09464106e+02, 2.69706916e+02, 2.62045757e+02,
        2.79596065e+02, 3.18153383e+02, 3.75054737e+02],
       [2.03392325e+03, 1.17075133e+03, 7.50763045e+02, 5.18398481e+02,
        3.87916310e+02, 3.20218782e+02, 2.94925679e+02, 3.00603943e+02,
        3.30444291e+02, 3.80444099e+02, 4.47904490e+02]])))
Traceback (most recent call last):
  File "/Users/wenko/tracts/taino_ppx_xxp.py", line 183, in <module>
    for line in optmod.mig:
                ^^^^^^^^^^
AttributeError: 'demographic_model' object has no attribute 'mig'
(venv) wenko@Wen-Yas-MacBook-Pro tracts % 
MeiLingKang commented 3 months ago

Hi wenyako,

In my opinion, there is a missing file named logs.py under the tracts/ folder. Therefore, you cannot import logs here. Since we don’t know how this function works, we cannot create a replacement function ourselves. This issue will be resolved once the developer provides the missing file.

sgravel commented 3 months ago

Sorry for the delay. I was able to reproduce the issue. The programmer working on this has moved on, so I will have to do a bit of digging. Thanks for letting me know.

wenyako commented 2 months ago

Thanks a lot for helping us out! Looking forward to running it~

sgravel commented 2 months ago

Thanks for the bug report! I have fixed the issue in the devel branch. I used code recovered from a programmer who has left the lab, so I still need to do some testing before adding this to the main branch, but you can see if that works for you in the meantime.

wenyako commented 2 months ago

Unfortunately, I still encounter the same error messages (as shown above) when running the example files stored in the "3Pops" folder...

Serdiuk-Andrii commented 2 months ago

Hello, @wenyako! I've fixed this issue on the devel branch, could you please try it on your side? I also suggest rerunning pip install . before running the script

MeiLingKang commented 1 month ago

Hi @Serdiuk-Andrii I’m working in the same lab as wenyako. I installed tracts using pip install .. The previous issue with importing 'logs' is now resolved, but a new error has appeared. I’ve attached the error message for your reference.

Screenshot 2024-10-04 130501
Serdiuk-Andrii commented 1 month ago

Hi @MeiLingKang! Could you check if you're using the latest version of the code from the develbranch? Based on the error output, it seems like the code you're using might be a bit outdated

Serdiuk-Andrii commented 2 weeks ago

@MeiLingKang, @wenyako The master branch has been updated. Could you pull the changes and try running them on your side?

MeiLingKang commented 5 hours ago

@Serdiuk-Andrii Thanks for the update! We've pulled the changes from the master branch, and everything is working smoothly. Grateful for your help!