From bc81b7f77823fdafc419faac7d11cf0cecc52573 Mon Sep 17 00:00:00 2001 From: "Sherine.Awad" Date: Fri, 27 Feb 2015 11:18:46 -0500 Subject: [PATCH 1/2] fox chromosome bug --- scripts/write-snps.py | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/scripts/write-snps.py b/scripts/write-snps.py index 47f5364..7874e1f 100644 --- a/scripts/write-snps.py +++ b/scripts/write-snps.py @@ -9,49 +9,54 @@ import glob from collections import defaultdict import numpy -import argparse def main(argv): - - parser=argparse.ArgumentParser() - parser.add_argument("outfile", help="Enter output file name") - args=parser.parse_args() - outfp=args.outfile + try: + opts, args = getopt.getopt(argv,"hi:o:",["ofile="]) + except getopt.GetoptError: + print 'write-snps.py -o ' + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + print 'write-snps.py -o ' + sys.exit() + elif opt in ("-o", "--ofile"): + outfp = arg nones=0 snps=0 index=1 vcfs=list() filelist = glob.glob('*.vcf') dic={} - outfp=open(sys.argv[1], 'w') + outfp=open("snps.txt",'w') j=0 for every in filelist: name=every.split('.') vcf=name[0] vcfs.append(vcf) mat=numpy.zeros((2000000,len(vcfs)+2),int) - indeces= [] - indeces.append('zero') for r1 in filelist: print 'processing', r1, index + lines = open(r1, "r" ).readlines() + j=j+1 i=0 - j=j+1 - for line in open(r1): - i=i+1 - rec=line.split('\t') - if line.startswith('#'): - continue - - else: - ivalue=str(rec[0])+'-'+str(rec[1]) - if(ivalue in indeces): - oldindex=indeces.index(ivalue) + lines = tuple(lines) + while i < len(lines): + rec=lines[i].split('\t') + if lines[i][0] in '#': + i+=1 + pass + else: + i+=1 + if str(rec[1]) in dic: + oldindex=dic.get(rec[1]) mat[oldindex][j]=1 else: + mat[index][0]=str(rec[1]) mat[index][j]=1 - indeces.append(ivalue) + dic[str(rec[1])]=index index+=1 - print len(indeces) + snps=index deli=" " zero="0" one="1" @@ -62,11 +67,11 @@ def main(argv): outfp.write(str(deli).rstrip('\n')) print >> outfp ,'\n' itr1=1 - while itr1 < len(indeces) : + while itr1 <= snps: itr2=1 - outfp.write(str(indeces[itr1]).rstrip('\n')) + outfp.write(str(mat[itr1][0]).rstrip('\n')) outfp.write(str(deli).rstrip('\n')) - while itr2 <= j: + while itr2 <= 11: outfp.write(str(mat[itr1][itr2]).rstrip('\n')) outfp.write(str(deli).rstrip('\n')) itr2+=1 From d3002b299195e56a52816001449671e42cbc1651 Mon Sep 17 00:00:00 2001 From: "Sherine.Awad" Date: Fri, 27 Feb 2015 11:46:41 -0500 Subject: [PATCH 2/2] Fix bug --- scripts/write-snps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/write-snps.py b/scripts/write-snps.py index 7874e1f..754b460 100644 --- a/scripts/write-snps.py +++ b/scripts/write-snps.py @@ -28,7 +28,7 @@ def main(argv): vcfs=list() filelist = glob.glob('*.vcf') dic={} - outfp=open("snps.txt",'w') + outfp=open(sys.argv[1], 'w') j=0 for every in filelist: name=every.split('.')