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 01aef11a0cc0c7f897c9497126d2ce454108eff1 authored by Williamreay on 13 June 2020, 01:20:04 UTC, committed by GitHub on 13 June 2020, 01:20:04 UTC
Delete .DS_Store
1 parent 1968cd3
  • Files
  • Changes
  • 6c8cfee
  • /
  • PES_scripts
  • /
  • FilterGWAS.py
Raw File Download
Permalinks

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:01aef11a0cc0c7f897c9497126d2ce454108eff1
directory badge Iframe embedding
swh:1:dir:3c52e6b752ad4c2445ecdf14dc7cca201c31e804
content badge Iframe embedding
swh:1:cnt:e234a1d29c4f6976086686bd8a27001dce026457
Citations

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 ...
FilterGWAS.py
import csv
import argparse
import sys
from copy import copy

def check_args(args=None):
    """Parse arguments"""
    parser = argparse.ArgumentParser(description="Filter a GWAS by a list of genomic regions.", formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('-g', '--gwas', help="Tab-separated GWAS summary statistics file containing at least the chromosome and position of the variants. Accepted chromosome codes: 1-22 for autosomal chromosomes, X or 23 for the X chromosome, Y or 24 for the Y chromosome and M, MT or 25 for mitochondrial DNA.", required=True)
    parser.add_argument('-f', '--filter', help="Tab-separated filter list, containing three columns: chromosome, start position and end position. Expects 1-based inclusive coordinates.", required=True)
    parser.add_argument('-c', '--chr', help="Chromosome column number in GWAS file.", required=True)
    parser.add_argument('-b', '--bp', help="Position column number in GWAS file.", required=True)
    parser.add_argument('-o', '--output', help="Output file name for filtered GWAS.", required=True)
    return(parser.parse_args(args))

def filterGwas(gwasFile, filterFile, chrCol, bpCol):
    c = int(chrCol) - 1
    b = int(bpCol) - 1
    filterDict = {}
    for i in range(1, 26):
        filterDict[i] = []
    gwas = []
    with open(filterFile, 'r') as f:
        reader = csv.reader(f, delimiter='\t')
        for line in reader:
            chr = line[0]
            try:
                chr = int(chr)
            except ValueError:
                if chr == 'X':
                    chr = 23
                elif chr == 'Y':
                    chr = 24
                elif chr == 'M' or chr == 'MT':
                    chr = 25
                else:
                    continue
            start = int(line[1])
            end = int(line[2]) + 1
            filterDict[chr].append(range(start, end))
    with open(gwasFile, 'r') as f:
        filteredGwasList = []
        reader = csv.reader(f, delimiter='\t')
        next(reader)
        for line in reader:
            chr = copy(line[c])  # chr column
            try:
                chr = int(chr)
            except ValueError:
                if chr == 'X':
                    chr = 23
                elif chr == 'Y':
                    chr = 24
                elif chr == 'M' or chr == 'MT':
                    chr = 25
                else:
                    continue
            bp = int(line[b])  # bp column
            if any(bp in i for i in filterDict[chr]):
                filteredGwasList.append(line)
    return(filteredGwasList)

arguments = check_args(sys.argv[1:])
newGwas = filterGwas(arguments.gwas, arguments.filter, arguments.chr, arguments.bp)
newGwas = ['\t'.join([str(i) for i in j]) for j in newGwas]
with open(arguments.output, 'w') as o:
    o.write('\n'.join(newGwas) + '\n')
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 ...

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— Contact— JavaScript license information— Web API

back to top