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
25 changes: 25 additions & 0 deletions exercise8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import pandas
import numpy

vcffile = open("Cflorida.vcf","r")
outfile = open("CfloridaCounts.txt","w")


for line in vcffile:

line = line.rstrip()

var=re.match('[CFcf]\.[Aa]*?\.', line)
var.replace('var','Cf.Sfa')
outfile.write(var)
var2=re.match('[CFcf]\.[Gg][Aa]?[Ii]?\.', line)
var2.replace('var2','Cf.Sfa')
outfile.write(var2)

var3=re.match([0-9],[0-9],line)
outfile.write(var3)


@lyy005 lyy005 Nov 2, 2017

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

for line in vcffile:
line = line.strip()
# if the line starts with "##", skip
if line[0:1] == "##":
outfile.write(line + "\n")
#if the line starts with "#", replace names with fixed names
elif line[0] == "#":
# apply all substitutions
names = re.sub("[Cc]Ff?.[Aa]2?","Cf.Sfa",line)
names = re.sub("[Cc][Ff].(G2|GAI|gai)","Cf.Gai",names)
# write line
outfile.write(names + "\n")
else:
#grab allele
sub = re.sub("[01.]/[01.]:([0-9,.]+):[0-9.]+:[0-9.]+:[0-9,.]+",r"\1",line)
#if allele counts . replace with NA
sub = re.sub(".","NA",sub)
#write line to new file
outfile.write(sub + "\n")

-0.5 points