Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions scripts/write-snps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you using getopt and not argparse?

except getopt.GetoptError:
print 'write-snps.py -o <outputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'write-snps.py -o <outputfile>'
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(sys.argv[1], '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"
Expand All @@ -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
Expand Down