Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting the Python code of RobustPCA (rpca.py) #106

Closed
magibc opened this issue Nov 21, 2024 · 2 comments
Closed

Extracting the Python code of RobustPCA (rpca.py) #106

magibc opened this issue Nov 21, 2024 · 2 comments

Comments

@magibc
Copy link

magibc commented Nov 21, 2024

Good morning Cameron @cameronmartino

Sorry to write you again.

The rclr transformation (step 1 of 2 of Gemelli) is yet implemented on vegan R package (https://www.rdocumentation.org/packages/vegan/versions/2.6-8/topics/decostand) . In future I know that step 2 (robust PCA) in vegan will be available as you mentioned in a previous issue.

During this time, to replicate the second part of Gemelli is it possible to extract the Python code only for the robust PCA step? I can code in R and bash but not in Python. Nevertheless I have tried. I do not have a phylogenetic lineage.

I attach you the Python code proposed if you could correct/comment it: code_proposed.zip

Nevertheless the output of sample loadings for example is not identical (see below), but the values are near. But it should be the same value not?

Data A to Gemelli software:
(3 principal components)

Sample_A,-0.021039700647923043,-0.11949826649297793,0.07588936873993962
Sample_B,0.04313255203566821,-0.10362935029631481,-0.034744651184218434
Sample_C,-0.03708052690981596,-0.001413017769371805,-0.17880637336062355

Data A + rclr transf. in vegan (decostand function) + extracting Python code from Gemelli for applying robust PCA:
(3 principal components)

Sample_A,-0.02102901847957217,-0.11951470159554187,0.07586051736337403
Sample_B,0.04316312185654794,-0.10361457762752269,-0.03481512250446939
Sample_C,-0.03708771483481108,-0.0013531041022976642,-0.17872210130215027

Thanks again,

Magí (David)

@magibc magibc closed this as completed Nov 24, 2024
@cameronmartino
Copy link
Collaborator

Hi @magibc,

It looks like you closed the problem but I came here to say we have a PR here in vegan that should solve this problem.

I also took a look at your code and you could just import optspace_helper with from gemelli.rpca inmport optspace_helper which would be much easier. As you found in your notebook that function does take in a transposed rclr_table - see here. Keep in mind that you must do all proped filtering of the table yourself this way - I can't garuntee everything will be correct when run this way - I have not really done full testing of this code. Nonetheless, See attached for your updated code (simplified).

Best,

Cameron

code_proposed_cm.ipynb.zip

@magibc
Copy link
Author

magibc commented Dec 2, 2024

Many thanks Cameron @cameronmartino

In my Python code also I have obtained the same results from your proposed code but I will use your Python code because it is more clear.

Thank you for incorporating in the BR of vegan package also!

All the vegan users we will be more happy now!!!

Best regards,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants