Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Name: chr_restore_all
- #Autor: Marieke Beltman
- #Date: 11-03-2015
- #Function: reads map files, selects the first column and changes the first column in the selected chromosome (instead of 0), and writes it in a new file. Needed for .map files from PLINK 1.07, because this version of PLINK doesn't recognize other chromosomes than human.
- #For every item in chrList, the map file and a new file will be opened and are send to the function restoreChr.
- import sys, getopt
- outname = sys.argv[1]
- def main(outname):
- chrList = ["27", "28", "1A","25LG1", "25LG2","4A", "LGE22","Z"]
- snpChrList ={}
- for i in chrList:
- snpChrList = openchrFile(i,snpChrList)
- #print(snpChrList)
- mapFile= openFile(outname)
- newMapFile= newFile(outname)
- restoreChr(snpChrList,mapFile,newMapFile)
- def openFile(outname):
- with open(outname+".map","r") as mapFile:
- best = mapFile.readlines()
- return best
- def openchrFile(i,chrom):
- with open("SNPs_per_chr/chr_GT_"+i+".txt","r") as chrFile:
- chrLines = chrFile.readlines()
- for line in chrLines:
- line = line.strip()
- chrom[line]=i
- return chrom
- def newFile(outname):
- new = open(outname+"_2.map","w")
- return new
- #Every line in the map file is splitted up and the first item of the line is changed in the chromosome, then the line is written to the new file
- def restoreChr(snpChrList,mapFile,newMapFile):
- for line in mapFile:
- if line.startswith('0'):
- line = line.strip().split("\t")
- if line[1] in snpChrList.keys():
- line[0]= snpChrList.get(line[1])
- newMapFile.write(("\t".join(line))+"\n")
- elif line[1] not in snpChrList.keys():
- line[0] = 'Un'
- newMapFile.write(("\t".join(line))+"\n")
- else:
- newMapFile.write(line)
- main(outname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement