Esempio n. 1
0
def main(options):
    """
    read and convert. 
    """

    if options["msmc"] and len(options["individuals"]) not in [2,4]:
        raise Exception("msmc output needs either 2 or 4 individuals")
    if options["psmc"] and len(options["individuals"]) not in [1,2]:
        raise Exception("psmc output needs either 1 or 2 individuals")
    
    index=read_sample(options["shapeit"]+".sample", options["individuals"])
    index=index_to_index(index)
    
    try:
        hap_file=gzip.open(options["shapeit"]+".haps.gz", "r")
    except IOError:
        hap_file=open(options["shapeit"]+".haps", "r")

    chr=np.genfromtxt(hap_file, dtype=str, usecols=0)
    hap_file.seek(0)
    pos=np.genfromtxt(hap_file, dtype=int, usecols=2)
    hap_file.seek(0)
    alleles=np.genfromtxt(hap_file, dtype=str, usecols=(3,4))
    hap_file.seek(0)
    haps=np.genfromtxt(hap_file, dtype=int, usecols=5+index)

    if options["msmc"]:
        gdc.output_msmc(haps, chr, pos, alleles, options)

    if options["psmc"]:
        gdc.output_psmc(haps, chr[0], pos, options)   #Assumes all on the same chromosome
Esempio n. 2
0
def main(options):
    """
    read and convert. 
    """

    length,pos,haps=read_macs(options["macs"])

    npos,nhaps=haps.shape
    if nhaps not in [2,4,8]:
        raise Exception("Must have 2,4 or 8 haplotypes")
    
    if options["switch_rate"]>0 or options["flip_rate"]>0:
        site_switch_rate=options["switch_rate"]*length/len(pos)
        site_flip_rate=options["flip_rate"]*length/len(pos)        
        for i in range(int(nhaps/2)):
            haps[:,[2*i,2*i+1]]=add_phasing_errors(haps[:,[2*i,2*i+1]], site_switch_rate, site_flip_rate)

    alleles=np.zeros( (npos,2), dtype=str)
    alleles[:,0]="A"
    alleles[:,1]="T"
            
    if options["msmc"]:
        chrs=np.zeros(npos, dtype=str,)
        chrs[:]=options["chr"]
        gdc.output_msmc(haps, chrs, pos, alleles, options)

    if options["psmc"]:
        gdc.output_psmc(haps, options["chr"], pos, options)   #Assumes all on the same chromosome
Esempio n. 3
0
def main(options):
    """
    read and convert. 
    """

    length, pos, haps = read_ms(options["ms"], options)

    npos, nhaps = haps.shape
    if nhaps not in [2, 4, 8]:
        raise Exception("Must have 2,4 or 8 haplotypes")

    if options["switch_rate"] > 0 or options["flip_rate"] > 0:
        site_switch_rate = options["switch_rate"] * length / len(pos)
        site_flip_rate = options["flip_rate"] * length / len(pos)
        for i in range(int(nhaps / 2)):
            haps[:, [2 * i, 2 * i + 1]] = add_phasing_errors(
                haps[:, [2 * i, 2 * i + 1]], site_switch_rate, site_flip_rate)

    alleles = np.zeros((npos, 2), dtype=str)
    alleles[:, 0] = "A"
    alleles[:, 1] = "T"

    if options["msmc"]:
        chrs = np.zeros(
            npos,
            dtype=str,
        )
        chrs[:] = options["chr"]
        gdc.output_msmc(haps, chrs, pos, alleles, options)

    if options["psmc"]:
        gdc.output_psmc(haps, options["chr"], pos,
                        options)  #Assumes all on the same chromosome
Esempio n. 4
0
def main(options):
    """
    read and convert. 
    """

    if options["msmc"] and len(options["individuals"]) not in [2, 4]:
        raise Exception("msmc output needs either 2 or 4 individuals")
    if options["psmc"] and len(options["individuals"]) not in [1, 2]:
        raise Exception("psmc output needs either 1 or 2 individuals")

    index = read_sample(options["shapeit"] + ".sample", options["individuals"])
    index = index_to_index(index)

    try:
        hap_file = gzip.open(options["shapeit"] + ".haps.gz", "r")
    except IOError:
        hap_file = open(options["shapeit"] + ".haps", "r")

    chr = np.genfromtxt(hap_file, dtype=str, usecols=0)
    hap_file.seek(0)
    pos = np.genfromtxt(hap_file, dtype=int, usecols=2)
    hap_file.seek(0)
    alleles = np.genfromtxt(hap_file, dtype=str, usecols=(3, 4))
    hap_file.seek(0)
    haps = np.genfromtxt(hap_file, dtype=int, usecols=5 + index)

    if options["msmc"]:
        gdc.output_msmc(haps, chr, pos, alleles, options)

    if options["psmc"]:
        gdc.output_psmc(haps, chr[0], pos,
                        options)  #Assumes all on the same chromosome