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

population vector in pcadapt #93

Open
abilska opened this issue Oct 14, 2024 · 1 comment
Open

population vector in pcadapt #93

abilska opened this issue Oct 14, 2024 · 1 comment

Comments

@abilska
Copy link

abilska commented Oct 14, 2024

Hello, we would like to analyze SNPs under selection across different populations (in our case, we have six), and the sample sizes (belove) provided are just examples. Unfortunately, we keep encountering an error, and it seems that the term related to different populations (pop_vector) has been deleted from the program.
Could you please help us understand what we might be doing wrong? Is this population selection option available in another feature/version?

Best regards,

################
Load required libraries
library(pcadapt)

# Load your SNP data (ensure it's in a suitable format)
# Assuming the file 'snp_data.csv' is structured with samples as rows and SNPs as columns
snp_data <- read.csv("snp_data.csv", row.names = 1)

# Create a population vector based on the specified sizes
pop_vector <- c(rep(1, 20),  # Population 1
                rep(2, 30),  # Population 2
                rep(3, 10),  # Population 3
                rep(4, 40),  # Population 4
                rep(5, 8),   # Population 5
                rep(6, 11))  # Population 6

# Run pcadapt analysis
pcadapt_result <- pcadapt(snp_data, K = 6)  # K is the number of populations

# Plot the results
plot(pcadapt_result)

# Extract SNPs under selection based on a defined threshold
# Set an appropriate threshold; this example uses a placeholder
threshold <- 0.05  # Adjust this value based on your criteria
snp_selection <- which(pcadapt_result$loadings[,1] > threshold)

# Print SNPs under selection
print(snp_selection)

# If you want to visualize the loadings
plot(pcadapt_result, type = "scores")
@privefl
Copy link
Member

privefl commented Oct 14, 2024

What is the error you get exactly?

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