Skip to content

Commit

Permalink
adding file with non-pysam VCF functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredgk committed Aug 15, 2017
1 parent 755cab1 commit 28f7af6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
30 changes: 30 additions & 0 deletions jared/vcf_func_nopysam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import logging

def getBaseList(la):
base_list = []
for i in range(9,len(la)):
base_list.append(la[i][0])
base_list.append(la[i][2])
return base_list

def vcfToList(vcf_name):
"""Creates two lists: a 2d list with base information like a VCF file,
and a list with position information from a given index.
"""
f = open(vcf_name,'r')
pos_list = []
base_list = []
for line in f:
if line[0] == '#':
continue
la = line.strip().split()
pos = int(la[1])
pos_list.append(pos)
bl = getBaseList(la)
base_list.append(bl)


return base_list, pos_list
9 changes: 5 additions & 4 deletions jared/vcf_to_ima.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ def generateSequence(rec_list, ref_seq, fasta_ref,



def writeHeader(pop_data, gr_len, out_f):
def writeHeader(pop_data, gr_len, out_f, pop_string="(0,1):2"):
out_f.write('Test IMa input\n')
out_f.write(str(len(pop_data))+'\n')
pops = ''
for i in range(len(pop_data)):
pops += (pop_data[i][0]+' ')
out_f.write(pops+'\n')
out_f.write('(0,1):2\n')
out_f.write(pop_string+'\n')
out_f.write(str(gr_len)+'\n')

def getLocusHeader(gener, pop_data, rec_list):
def getLocusHeader(gener, pop_data, rec_list, mut_model="I0", inhet_sc=1):
name = gener.chrom+':'+str(gener.start)+':'+str(gener.end)
gene_len = gener.end-gener.start
for rec in rec_list:
Expand All @@ -203,7 +203,8 @@ def getLocusHeader(gener, pop_data, rec_list):
for i in range(len(pop_data)):
lh += ' '+str(len(pop_data[i][1]))
lh += ' '+str(gene_len)
lh += ' I0 1'
lh += ' '+mut_model
lh += ' '+str(inhet_sc)
return lh

def getOutputFilename(args):
Expand Down

0 comments on commit 28f7af6

Please sign in to comment.