Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision db3ca8faeecf8697973f803bc05c5a3d0a187145 authored by Arjun Biddanda on 04 June 2020, 18:55:40 UTC, committed by Arjun Biddanda on 04 June 2020, 18:55:40 UTC
added in bugfix of italicization and factor of two
1 parent 2d4b8cc
  • Files
  • Changes
  • eb7458b
  • /
  • src
  • /
  • gen_freq_table.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:db3ca8faeecf8697973f803bc05c5a3d0a187145
directory badge
swh:1:dir:51dc8f21506d29022a61063870940fa7eacebc5c
content badge
swh:1:cnt:3c724581a6e6210151b44489a9e3e0dca07f69d4

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
gen_freq_table.py
#!/usr/local/bin/python3

'''
 Generate a frequency table for use in downstream GeoDist applications
'''

from __future__ import print_function
import sys

import click
import numpy as np 
import pandas as pd
import gzip as gz
import json

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

@click.command()
@click.option('--mac', required=True, help='Minor allele count file')
@click.option('--total', required=True, help='Total samples count file')
def main(mac, total):
    #1. iterating through the files simultaneously
    with gz.open(mac, 'rt') as macfile, gz.open(total, 'rt') as total_file:
      i = 0
      for mac_line, total_line in zip(macfile,total_file):
        if i == 0:
          spltln = mac_line.split()
          header_list = spltln[0:4] + ['MAC','MAF'] + spltln[4:]
          print('\t'.join(header_list))
        else:
          # Splitting each of the lines to compute the allele frequency
          spltlnmac = mac_line.split()
          spltlntotal = total_line.split()
          macs = np.array(spltlnmac[4:], dtype=np.float32)
          totals = np.array(spltlntotal[4:], dtype=np.float32)
          allele_freqs = np.nan_to_num(macs/totals)
          global_maf = np.sum(macs)/np.sum(totals)
          total_mac = np.int64(np.sum(macs))
          total_list = spltlnmac[0:4] + [str(total_mac), str(global_maf)] + [str(f) for f in allele_freqs]
          print('\t'.join(total_list))
        if i % 100000 == 0:
          eprint('%d00 K snps finished' % int(i/100000))
        i += 1

if __name__ =='__main__':
  main()
  
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API