# print lines[:400] lines = lines.split('\n') for line in lines: # print line line = line.strip().split('\t') snp_id = line[0] allele = line[1] assert len(allele) == 1 annotation_dict[snp_id] = allele # print len(annotation_dict.keys()) # READING PLINK input if options.verbose: sys.stderr.write("Reading SNP input...\n") if options.bfile: IN = input.plink(options.bfile, type='b', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) elif options.tfile: IN = input.plink(options.tfile, type='t', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) #elif options.pfile: IN = input.plink(options.pfile,type='p', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype) elif options.emmaFile: IN = input.plink(options.emmaFile, type='emma', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) if not os.path.isfile(options.phenoFile or IN.fbase + '.phenos') and not os.path.isfile(options.emmaPheno): raise Exception( "No .pheno file exist for %s. Please provide a phenotype file using the --phenofile or --emmaPHENO argument." % ( options.phenoFile or IN.fbase + '.phenos')) # Read the emma phenotype file if provided. # Format should be rows are phenotypes and columns are individuals. if options.emmaPheno: f = open(options.emmaPheno, 'r')
sys.exit() outFile = args[0] import sys import os import numpy as np from scipy import linalg from pylmm.lmm import calculateKinship from pylmm import input if not options.tfile and not options.bfile and not options.emmaFile: parser.error("You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP).") if options.verbose: sys.stderr.write("Reading PLINK input...\n") if options.bfile: IN = input.plink(options.bfile,type='b') elif options.tfile: IN = input.plink(options.tfile,type='t') #elif options.pfile: IN = input.plink(options.pfile,type='p') elif options.emmaFile: if not options.numSNPs: parser.error("You must provide the number of SNPs when specifying an emma formatted file.") IN = input.plink(options.emmaFile,type='emma') else: parser.error("You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP).") n = len(IN.indivs) m = options.computeSize W = np.ones((n,m)) * np.nan IN.getSNPIterator() # Annoying hack to get around the fact that it is expensive to determine the number of SNPs in an emma file if options.emmaFile: IN.numSNPs = options.numSNPs i = 0
#if not options.pfile and not options.tfile and not options.bfile: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an EMMA formatted file (--emmaSNP)." ) if not options.kfile: parser.error("Please provide a pre-computed kinship file") numThreads = None if options.numThreads: numThreads = int(options.numThreads) # READING PLINK input if options.verbose: sys.stderr.write("Reading SNP input...\n") if options.bfile: IN = input.plink(options.bfile, type='b', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) elif options.tfile: IN = input.plink(options.tfile, type='t', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) #elif options.pfile: IN = input.plink(options.pfile,type='p', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype) elif options.emmaFile: IN = input.plink(options.emmaFile, type='emma', phenoFile=options.phenoFile, normGenotype=options.normalizeGenotype) else: parser.error("You must provide at least one PLINK input file base")
print "\tldFlag = %s" % ldFlagStr print "\tldThresh = %f" % ldThresh import os import numpy as np from scipy import linalg from pylmm.lmm import calculateKinship from pylmm import input if not options.tfile and not options.bfile and not options.emmaFile: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP)." ) if options.verbose: sys.stderr.write("Reading PLINK input...\n") if options.bfile: IN = input.plink(options.bfile, type='b') elif options.tfile: IN = input.plink(options.tfile, type='t') #elif options.pfile: IN = input.plink(options.pfile,type='p') elif options.emmaFile: if not options.numSNPs: parser.error( "You must provide the number of SNPs when specifying an emma formatted file." ) IN = input.plink(options.emmaFile, type='emma') else: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP)." ) n = len(IN.indivs)
if len(args) != 1: parser.print_help() sys.exit() outFile = args[0] if not options.tfile and not options.bfile and not options.emmaFile: #if not options.pfile and not options.tfile and not options.bfile: parser.error("You must provide at least one PLINK input file base (--tfile or --bfile) or an EMMA formatted file (--emmaSNP).") if not options.kfile: parser.error("Please provide a pre-computed kinship file") # READING PLINK input if options.verbose: sys.stderr.write("Reading SNP input...\n") if options.bfile: IN = input.plink(options.bfile,type='b', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype,impute=options.impute) elif options.tfile: IN = input.plink(options.tfile,type='t', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype,impute=options.impute) #elif options.pfile: IN = input.plink(options.pfile,type='p', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype) elif options.emmaFile: IN = input.plink(options.emmaFile,type='emma', phenoFile=options.phenoFile,normGenotype=options.normalizeGenotype,impute=options.impute) else: parser.error("You must provide at least one PLINK input file base") if not os.path.isfile(options.phenoFile or IN.fbase + '.phenos') and not os.path.isfile(options.emmaPheno): parser.error("No .pheno file exist for %s. Please provide a phenotype file using the --phenofile or --emmaPHENO argument." % (options.phenoFile or IN.fbase + '.phenos')) # Read the emma phenotype file if provided. # Format should be rows are phenotypes and columns are individuals. if options.emmaPheno: f = open(options.emmaPheno,'r') P = [] for line in f: v = line.strip().split()
import multiprocessing as mp # Multiprocessing is part of the Python stdlib import Queue if not options.tfile and not options.bfile and not options.emmaFile: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP)." ) numThreads = None if options.numThreads: numThreads = int(options.numThreads) if options.verbose: sys.stderr.write("Reading PLINK input...\n") if options.bfile: IN = input.plink(options.bfile, type="b") elif options.tfile: IN = input.plink(options.tfile, type="t") # elif options.pfile: IN = input.plink(options.pfile,type='p') elif options.emmaFile: if not options.numSNPs: parser.error("You must provide the number of SNPs when specifying an emma formatted file.") IN = input.plink(options.emmaFile, type="emma") else: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP)." ) def compute_W(job): """
from pylmm import input from numpy.linalg import pinv, inv if len(args) != 1: parser.print_help() sys.exit() outFile = args[0] if not options.tfile and not options.bfile and not options.emmaFIle: parser.error( "You mustprovide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emmaSNP).") if options.verbose: sys.stderr.write("Reading PLINK input...\n") if options.bfile: IN = input.plink(options.bfile, type='b', impute=True) elif options.tfile: IN = input.plink(options.tfile, type='t', impute=True) elif options.emmaFile: if not options.numSNPs: parser.error("You must provide the number of SNPs when specifying an emma formatted file.") IN = input.plink(options.emmaFile, type='emma', impute=True) else: parser.error( "You must provide at least one PLINK input file base (--tfile or --bfile) or an emma formatted file (--emaSNP).") if options.emmaFile: IN.numSNPs = options.numSNPs if options.evaluate: Answer = input.plink(options.answer, type='t', impute=True) if options.evaluate: MeanInpute = input.plink(options.tfile, type='t', impute=False) IN.getSNPIterator() if options.evaluate: Answer.getSNPIterator()