2010-04-26 20:34:04 +08:00
from farm_commands2 import *
2010-07-30 22:59:59 +08:00
import os
2010-04-26 20:34:04 +08:00
import sys
from optparse import OptionParser
from datetime import date
import glob
import operator
import faiReader
import math
import shutil
import string
def main ( ) :
global OPTIONS
usage = " usage: % prog [options] b36VCF hg18VCF "
parser = OptionParser ( usage = usage )
parser . add_option ( " " , " --dry " , dest = " dry " ,
action = ' store_true ' , default = False ,
help = " If provided, nothing actually gets run, just a dry run " )
2010-09-28 22:51:57 +08:00
parser . add_option ( " -r " , " --reverse " , dest = " reverse " , action = " store_true " , default = False , help = " If set, will convert the hg18VCF to a b36VCF (thus reversing the functionality) " )
2010-04-26 20:34:04 +08:00
( OPTIONS , args ) = parser . parse_args ( )
if len ( args ) != 2 :
parser . error ( " incorrect number of arguments " )
b36vcf , hg18vcf = args
2010-07-30 22:59:59 +08:00
temp = open ( " tmp " , ' w ' )
mitotemp = open ( " mtmp " , ' w ' )
2010-09-28 22:51:57 +08:00
if not OPTIONS . reverse :
for line in open ( b36vcf ) :
length = len ( line )
if length > 2 :
if line [ 0 : 2 ] == ' MT ' or line [ 0 ] == " # " :
if line [ 0 ] == " # " :
mitotemp . write ( line )
else :
spline = line . split ( " \t " )
spline [ 0 ] = " chrM "
mitotemp . write ( " \t " . join ( spline ) )
2010-07-31 00:11:16 +08:00
else :
2010-09-28 22:51:57 +08:00
line = ' chr ' + line
temp . write ( line )
temp . close ( )
mitotemp . close ( )
os . system ( " cat mtmp tmp > " + hg18vcf + " ; rm mtmp ; rm tmp " )
else :
for line in open ( hg18vcf ) :
if line . startswith ( " # " ) :
2010-07-31 00:11:16 +08:00
temp . write ( line )
2010-09-28 22:51:57 +08:00
else :
spline = line . split ( " \t " )
if ( spline [ 0 ] == " chrM " ) :
spline [ 0 ] = " MT "
mitotemp . write ( " \t " . join ( spline ) )
else :
spline [ 0 ] = spline [ 0 ] . split ( " chr " ) [ 1 ]
temp . write ( " \t " . join ( spline ) )
temp . close ( )
mitotemp . close ( )
os . system ( " cat tmp mtmp > " + b36vcf + " ; rm mtmp ; rm tmp " )
2010-04-26 20:34:04 +08:00
if __name__ == " __main__ " :
main ( )