counting individuals with the present gene and absent gene for each population
I can show you how I would approach it in R. You'll have to adjust and customize it to your own data of course. I only had two files to play with, from your example. Especially for the merge step you should build a for loop around it so that it will merge every next file automatically, since you have 500 files.

Here an example for the KS2W files:

myFiles &lt;- dir(pattern="KS2W")

myFiles
[1] "HI.3577.005.Index_25.QPG4_KS2W-35_all_PA.txt"
[2] "HI.3577.005.Index_9.QPA2_KS2W-8_all_PA.txt"  

fileNames &lt;- list()

for(i in 1:2){
    fileNames[[i]] &lt;- read.table(myFiles[i], sep = " ")
}  

merged &lt;- merge(fileNames[[1]], fileNames[[2]], by.x = "V1", by.y = "V1", all = F, sort = F)

present &lt;- rowSums(merged[,2:3])

zeros &lt;- rowSums(merged[,2:3] == 0)

output &lt;- cbind(present, zeros)

rownames(output) &lt;- merged[,1]

output
              present zeros
Ha8_00040788        2     0
Ha4_00024045        2     0
Ha4_00025366        2     0
Ha16_00022130       1     1
Ha16_00023451       1     1
Ha8_00040789        2     0
Ha4_00025367        2     0
Ha4_00024046        0     2
Ha16_00022131       2     0
Ha16_00023452       2     0


To add more files with merge, you could add something like this:

merged &lt;- merge(fileNames[[1]], fileNames[[2]], by.x = "V1", by.y = "V1", all = F, sort = F)

for(i in 3:30){
  merged &lt;- merge(merged, fileNames[[i]], by.x = "V1", by.y = "V1", all = F, sort = F)
}


You'll have to adjust all the numbers and coordinates to fit your data.