Skip to content

Conversation

@radioactive17
Copy link

This pull request introduces updates to handle genotype data from a vcf format

Please review the readVcfData function in the snpdt.cpp file. This function reads data from a VCF file and aims to store it in a format similar to BFILE data (.bim, .bed, .fam).

The primary difference between VCF and BFILE formats lies in how missing genotype data is represented and handled:

In VCF, missing data is explicitly marked with a "."
For example:

  1. 0/. indicates one allele is present (reference) and the other is missing.
  2. ./. indicates both alleles are missing.

In BFILE, missing data is encoded in a binary format (e.g., "01"), which does not specify whether the reference or alternate allele is missing.

This distinction in handling missing data could be introducing discrepancies in statistical calculations, particularly in variants where missing genotypes are prevalent.

I’d like your insights on whether the handling of missing data in this function could be improved to mitigate potential discrepancies. Let me know if further clarification is needed!

// std::cout << "Processing sample " << indx << ", SNP " << s << std::endl;

if (field[0] == '0' || field[0] == '.')
snp->one[indx] = 0; // Reference allele (0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to make this part of the logic consistent

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, this is the logic we should follow:

void snpdt::writeIntToGenotype(int indi, int snp, int code)

Copy link
Author

@radioactive17 radioactive17 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the logic you suggested. It's still giving me a different output in comparison to the bfile.
I also want to confirm if you run the program with a --bfile and --file flag for the same data would it give the same output?

Below is the code I wrote:
int code = -9; if (field[0] == '.' || field[2] == '.') { code = -9; } else if (field[0] == '0' && field[2] == '0') { code = 0; // Homozygous reference (0/0) } else if ((field[0] == '0' && field[2] == '1') || (field[0] == '1' && field[2] == '0')) { code = 1; // Heterozygous (0/1) } else if (field[0] == '1' && field[2] == '1') { code = 2; // Homozygous alternate (1/1) } else { std::cerr << "Error: unrecognized genotype format: " << field << std::endl; exit(1); }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add your code as a commit to this PR?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radioactive17 the internal representatino neends to be changed as well. meaning this part of the code needs to be changed as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I haven't changed that part of the code. I'll do that and add the updated code. Thanks.

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

Successfully merging this pull request may close these issues.

2 participants