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

swh:1:snp:0fa5e44aa9eaf68dc00949be32686577b750591b
  • Code
  • Branches (8)
  • Releases (0)
    • Branches
    • Releases
    • HEAD
    • refs/heads/ahaghani-patch-1
    • refs/heads/main
    • refs/tags/3.1.1
    • refs/tags/v1.0.0
    • refs/tags/v2.0.0
    • refs/tags/v2.1.0
    • refs/tags/v3.0.0
    • refs/tags/v3.1.0
    No releases to show
  • ad54dd7
  • /
  • CMAPS_source
  • /
  • pickProbesInfinium1.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.

  • content
  • directory
  • revision
  • snapshot
content badge Iframe embedding
swh:1:cnt:c273b0c9ca1808337dde010e9e044fca61ae13d2
directory badge Iframe embedding
swh:1:dir:db83229f7017e69c20115f1fd07d9a9dfb14603b
revision badge
swh:1:rev:8575912e5aa73fde6ab54bba4fbaeadc7d8267f4
snapshot badge
swh:1:snp:0fa5e44aa9eaf68dc00949be32686577b750591b

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.

  • content
  • directory
  • revision
  • snapshot
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 ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 8575912e5aa73fde6ab54bba4fbaeadc7d8267f4 authored by Amin Haghani on 20 November 2024, 18:45:15 UTC
Delete MammalianNetworkAnalysis, Amin Haghani/Supplementary Data directory
Tip revision: 8575912
pickProbesInfinium1.py
# Picks 2K Infinium 1 probes

from __future__ import print_function
import sys
import gzip
from collections import defaultdict
import operator

def main():
    if len(sys.argv) != 7:
        print("Usage: python pickProbesInfinium1.py <file of sites already picked> <all probes file> <EPIC manifest file> <num Infinium 1 sites> <output file> <only converted 1/0>")
        exit(1)
    existingSites = gzip.open(sys.argv[1], 'rt')
    allScoresSites = gzip.open(sys.argv[2], 'rt')
    EPICfile = gzip.open(sys.argv[3], 'rt')
    numInfinium1sites = int(sys.argv[4])
    oFile = gzip.open(sys.argv[5], 'wt')
    convertedOnly = int(sys.argv[6])

    print("Parsing file for EPIC probe design . . .")
    EPICdesign = defaultdict(str)
    firstLine = True
    for line in EPICfile:
        splitLine = line.strip().split(",")
        if not firstLine:
            chr = splitLine[1][1:-1]
            coord = int(splitLine[2])
            strand = splitLine[3][1:-1]
            infType = splitLine[9][1:-1]

            EPICdesign[(chr, coord)] = (infType, strand)
        else:
            firstLine = False
    print("Done.")

    pickedSites = defaultdict(bool)
    print("Parsing file for sites already picked . . .")
    firstLine = True
    for line in existingSites:
        if not firstLine:
            splitLine = line.strip().split("\t")
            chr = "chr" + splitLine[3]
            coord = int(splitLine[4])

            pickedSites[(chr, coord)] = line
        else:
            firstLine = False
    print("Done.")

    # Extract Infinium 1 probe numbers
    print("Parsing file for Infinium 1 probes. . .")
    CGsites_Inf1 = defaultdict(int)
    probePicked_Inf1 = defaultdict(str)
    EPICconflict = defaultdict(bool)

    for line in allScoresSites:
        splitLine = line.strip().split("\t")

        if (convertedOnly and splitLine[17] != "C"):
            continue

        if splitLine[15] == "F":
            strand = "+"
        else:
            strand = "-"

        if len(splitLine) > 23: # if we have an infinium 1 for this probe given design score and underlying CG count etc
            species = splitLine[23].split(",")
            if len(species) > 1:
                chr = "chr" + splitLine[3]
                coord = int(splitLine[4])
                SNVlocation = splitLine[27]
                SNVoriginal = splitLine[28]
                SNVchoice = splitLine[29]

                if ((chr, coord) not in pickedSites):
                    if len(species) - 1 > CGsites_Inf1[(chr, coord)]:  # just pick Infinium 1 probe that covers most species
                        CGsites_Inf1[(chr, coord)] = len(species) - 1
                        if ((chr, coord) in EPICdesign): # if this site is on the epic array
                            if (EPICdesign[(chr, coord)][0] == "I") and (splitLine[17] == "C") and (strand == EPICdesign[(chr, coord)][1]): # if we have the same design
                                probePicked_Inf1[(chr, coord)] = "\t".join(splitLine[:23]) + "\t" + str(len(species)) + "\t" + "\t".join(splitLine[23:30]) + "\tInf1\t1\t1\n"
                            else:
                                probePicked_Inf1[(chr, coord)] = "\t".join(splitLine[:23]) + "\t" + str(len(species)) + "\t" + "\t".join(splitLine[23:30]) + "\tInf1\t1\t0\n"
                        else:
                            probePicked_Inf1[(chr, coord)] = "\t".join(splitLine[:23]) + "\t" + str(len(species)) + "\t" + "\t".join(splitLine[23:30]) + "\tInf1\t0\t0\n"
    print("Done.")

    print("Sorting all Infinium 1 sites based on how many species they cover. . .", end = "")
    sorted_CGsites_Inf1 = sorted(CGsites_Inf1.items(), key = operator.itemgetter(1))
    sorted_CGsites_Inf1.reverse()
    print("Done.")

    print("Picking Infinium 1 sites. . .")
    i = 0
    numPicked = 0
    while (numPicked < numInfinium1sites and i < len(sorted_CGsites_Inf1)):
        CGsite = sorted_CGsites_Inf1[i][0]
        if ((CGsite not in pickedSites)):
                pickedSites[CGsite] = True
                oFile.write(probePicked_Inf1[CGsite])
                numPicked += 1
        else:
            print("This shouldn't be happening. We've already picked this site with Infinium 2 but somehow didn't properly check for it.")
        i += 1
    print("Done.")

    oFile.close()
    existingSites.close()
    allScoresSites.close()
    EPICfile.close()

main()

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