plinkio

A small C and Python library for reading PLINK genotype files.

https://github.com/mfranberg/libplinkio

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

A small C and Python library for reading PLINK genotype files.

Basic Info
  • Host: GitHub
  • Owner: mfranberg
  • License: other
  • Language: Shell
  • Default Branch: master
  • Homepage:
  • Size: 5.69 MB
Statistics
  • Stars: 51
  • Watchers: 9
  • Forks: 16
  • Open Issues: 6
  • Releases: 3
Created over 14 years ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

libplinkio

This is a small C and Python library for reading Plink genotype files.

Currently it can: * Read and parse BED, BIM and FAM files. * Transpose BED files. * Write BED, BIM and FAM files.

Libplinkio will reach 1.0 when it can: * Read PED files (i.e. non-binary bed-files).

Project rationales: * Use C to make it as simple as possible to add bindings for other languages. * Focus only on IO-functionality. * Few external dependencies to make it easy to use.

Installing

Installing this library is easy, just configure and make. This will also install Python bindings for the active interpeter.

NEWS The python extension can now be installed by

pip install plinkio

Installing to a standard location

mkdir build
cd build
cmake ../
make && make test && sudo make install

You can also pass the --disable-tests flag to configure to avoid building the unit tests and the dependency to libcmockery. Note howerver, in this case make check will not do anything.

Installing to a custom location

mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/path/to/plinkio ../
make && make test && make install

Linking to your program

To link your own application to libplinkio you can use the following include and library paths after installing it:

   gcc source.c -lplinkio

If you installed libplinkio to a custom location you need to specify the location of libplinkio:

gcc -lplinkio -I/path/to/plinkio/include -L/path/to/plinkio/lib source.c

Genotype coding

The genotypes are coded 0, 1, 2, and 3. The numbers 0-2 represent the number of A2 alleles as specified in the .bim file. The number 3 represents a missing genotype.

Using in C

For specific information look at http://mfranberg.github.com/libplinkio/index.html

The following C program prints the genotypes of all individuals. Note, that it is not recommended to run this program on a big plink file since it will fill your screen with data.

```c

include

include

include

int main(int argc, char *argv[]) {
struct piofilet plinkfile; snpt *snpbuffer; int sampleid; int locus_id;

if( pio_open( &plink_file, argv[ 1 ] ) != PIO_OK )
{
    printf( "Error: Could not open %s\n", argv[ 1 ] );
    return EXIT_FAILURE;
}

if( !pio_one_locus_per_row( &plink_file ) )
{
    printf( "This script requires that snps are rows and samples columns.\n" );
    return EXIT_FAILURE;
}

locus_id = 0;
snp_buffer = (snp_t *) malloc( pio_row_size( &plink_file ) );
while( pio_next_row( &plink_file, snp_buffer ) == PIO_OK )
{
    for( sample_id = 0; sample_id < pio_num_samples( &plink_file ); sample_id++)
    {
        struct pio_sample_t *sample = pio_get_sample( &plink_file, sample_id );
        struct pio_locus_t *locus = pio_get_locus( &plink_file, locus_id );
        printf( "Individual %s has genotype %d for snp %s.\n", sample->iid, snp_buffer[ sample_id ], locus->name );
    }

    locus_id++;
}

free( snp_buffer );
pio_close( &plink_file );

return EXIT_SUCCESS;

} ```

Accessing sample and locus information in C

Information about samples and loci are obtained by referencing directly into the struct. The fields are summarized below.

The piosamplet declaration

```c /** * Data structure that contains the PLINK information about a sample (individual). / struct piosamplet { /* * An internal reference id, so that we can read them in order. */ sizet pioid;

/**
 * Family identifier.
 */
char *fid;

/**
 * Plink individual identifier.
 */
char *iid;

/**
 * Plink individual identifier of father, 0 if none.
 */
char *father_iid;

/**
 * Plink individual identifier of mother, 0 if none.
 */
char *mother_iid;

/**
 * The sex of the individual.
 */
enum sex_t sex;

/**
 * Affection of the individuals, case, control or unkown. Control
 * is always 0 and case always 1.
 */
enum affection_t affection;

/**
 * A continuous phenotype of the individual.
 */
float phenotype;

}; ```

The piolocust declaration

```c /** * Data structure that contains the PLINK information about a locus (SNP). / struct piolocust { /* * An internal reference id, so that we can read them in order. */ sizet pioid;

/**
 * Chromosome number starting from 1.
 */
unsigned char chromosome;

/**
 * Name of the SNP.
 */
char *name;

/**
 * Genetic position of the SNP.
 */
float position;

/**
 * Base pair position of the SNP.
 */
long long bp_position;

/**
 * First allele.
 */
char *allele1;

/**
 * Second allele.
 */
char *allele2;

}; ```

Using in Python

The following script does the same as the above C program, utilizing most of the API.

```python from plinkio import plinkfile

plinkfile = plinkfile.open( "/path/to/plinkfile" ) if not plinkfile.onelocusperrow( ): print( "This script requires that snps are rows and samples columns." ) exit( 1 )

samplelist = plinkfile.getsamples( ) locuslist = plinkfile.getloci( )

for locus, row in zip( locuslist, plinkfile ): for sample, genotype in zip( sample_list, row ): print( "Individual {0} has genotype {1} for snp {2}.".format( sample.iid, genotype, locus.name ) ) ```

Accessing sample and locus information in Python

The file API

```python

Opens the plink file at the given path.

@param path The prefix for a .bed, .fam and .bim without

the extension. E.g. for the files /plink/myfile.fam,

/plink/myfile.bim, /plink/myfile.bed use the path

/plink/myfile

def open(path): pass

Creates a new plink file based on the given samples.

@param path The prefix for a .bed, .fam and .bim without

the extension. E.g. for the files /plink/myfile.fam,

/plink/myfile.bim, /plink/myfile.bed use the path

/plink/myfile

@param samples A list of Sample objects to write to the file.

def create(path, samples): pass ```

The Sample object

```python class Sample: def init(self, fid, iid, fatheriid, motheriid, sex, affection, phenotype = 0.0): ## # Family id. # self.fid = fid

    ##
    # Individual id.
    #
    self.iid = iid

    ##
    # Individual id of father.
    #
    self.father_iid = father_iid

    ##
    # Individual id of mother.
    #
    self.mother_iid = mother_iid

    ##
    # Sex of individual.
    #
    self.sex = sex

    ##
    # Affection of individual, 0/1, control/case
    #
    self.affection = affection

    ##
    # Optional continuous phenotype, will be 0.0/1.0 if control/case
    #
    self.phenotype = phenotype

```

The Locus object

```python class Locus: def init(self, chromosome, name, position, bp_position, allele1, allele2): ## # Chromosome number starting from 1 # self.chromosome = chromosome

    ##
    # Name of the loci, usually rs-number or
    # chrX:pos.
    #
    self.name = name

    ##
    # Genetic position (floating point number).
    #
    self.position = position

    ##
    # Base pair position (integer).
    #
    self.bp_position = bp_position

    ##
    # First allele
    #
    self.allele1 = allele1

    ##
    # Second allele
    #
    self.allele2 = allele2

```

The PlinkFile object

```python class PlinkFile: ## # Returns the prefix path to the plink file, e.g. # without .bim, .bed or .fam. # def get_path(): pass

##
# Returns a list of the Sample objects.
#
def get_samples():
    pass

##
# Returns a list of Locus objects.
#
def get_loci():
    pass

##
# Determines how the snps are stored. It will return
# true if a row contains the genotypes of all individuals
# from a single locus, false otherwise.
#
def one_locus_per_row():
    pass

##
# Closes the file.
#
def close():
    pass

##
# Transposes the file.
#
# @param new_path Prefix of the new plink file.
#
def transpose(new_path):
    pass

```

The WritablePlinkFile object

```python class WritablePlinkFile: ## # Returns a list of Sample objects. # def get_samples(): pass

##
# Returns a list of Locus objects written so far.
#
def get_loci():
    pass

##
# Takes a locus and the corresponding genotypes and
# writes them to the plink file.
# 
# @param locus A Locus object to write.
# @param row An indexable list of genotypes.
#
def write_row(locus, row):
    pass

##
# Closes the file.
#
def close():
    pass

```

Owner

  • Name: Mattias Frånberg
  • Login: mfranberg
  • Kind: user
  • Location: Sweden
  • Company: Spotify

GitHub Events

Total
  • Issues event: 1
  • Delete event: 1
  • Push event: 1
  • Pull request event: 1
Last Year
  • Issues event: 1
  • Delete event: 1
  • Push event: 1
  • Pull request event: 1

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 162
  • Total Committers: 9
  • Avg Commits per committer: 18.0
  • Development Distribution Score (DDS): 0.259
Past Year
  • Commits: 7
  • Committers: 1
  • Avg Commits per committer: 7.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mattias Franberg m****g@g****m 120
Mattias Frånberg m****s@m****m 15
TAKEDA Kazuki K****A 12
Oleksandr Frei o****i@g****m 6
Mattias Frånberg f****n@f****) 4
Jeremy McRae j****e@i****m 2
Hákon j****n@g****m 1
Mattias Frånberg m****g@k****e 1
YeWenting W****e@o****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 25
  • Total pull requests: 23
  • Average time to close issues: 10 months
  • Average time to close pull requests: 30 days
  • Total issue authors: 23
  • Total pull request authors: 8
  • Average comments per issue: 3.0
  • Average comments per pull request: 1.13
  • Merged pull requests: 20
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 3 months
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 1
Top Authors
Issue Authors
  • mfranberg (2)
  • nurfatimaj (2)
  • MboiTui (1)
  • TTTPOB (1)
  • freeseek (1)
  • sn-GT (1)
  • bvilhjal (1)
  • heliziii (1)
  • shadiakiki1986 (1)
  • bunop (1)
  • Wainberg (1)
  • cullenaroberts (1)
  • hakon-jon (1)
  • yakkoroma (1)
  • ofrei (1)
Pull Request Authors
  • Kazuki-TAKEDA (12)
  • ofrei (3)
  • mfranberg (3)
  • dependabot[bot] (2)
  • YeWenting (1)
  • hakon-jon (1)
  • bunop (1)
  • jeremymcrae (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 19,033 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 12
  • Total versions: 8
  • Total maintainers: 1
pypi.org: plinkio

A library for parsing plink genotype files

  • Versions: 8
  • Dependent Packages: 1
  • Dependent Repositories: 12
  • Downloads: 19,033 Last month
  • Docker Downloads: 0
Rankings
Docker downloads count: 3.8%
Dependent repos count: 4.2%
Dependent packages count: 4.7%
Average: 7.9%
Forks count: 9.1%
Stargazers count: 9.6%
Downloads: 15.8%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/build_dist.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • docker/setup-qemu-action v2 composite
  • pypa/cibuildwheel v2.12.0 composite
.github/workflows/cmake.yml actions
  • actions/checkout v2 composite
.github/workflows/pypi.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v2 composite
.github/workflows/pypi_experimental.yml actions
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
.github/workflows/pypi_source.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v2 composite
.github/workflows/tox.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
pyproject.toml pypi
setup.py pypi