Python40

作者: rong酱 | 来源:发表于2023-09-06 17:29 被阅读0次
    #!/usr/bin/env python
    ##coding=utf-8
    
    import os
    import sys
    import argparse
    import re
    
    parser = argparse.ArgumentParser(description="\n\033[1;32;40m \n python variant_stat.py -i mergy.norm.both.xls -o stat.xls \n")
    parser.add_argument('-i', '--input', help = 'the pathway of the input vcf file ', required = True)
    parser.add_argument('-o', '--output', help = 'the pathway of the output xls file', required = True)
    argv = vars(parser.parse_args())
    ifile = os.path.abspath(argv['input'].strip())
    ofile = os.path.abspath(argv['output'].strip())
    
    def trimfq(inputfile,outfile):
        oc=open(outfile,'w')
        oc.write("CHR\tPOS\tREF\tALT\tCase_Total_num\ttotal_num_pos\tProportion\tHet\tHom")
        with open(inputfile,'r') as v:
            for vi in v:
                num=0
                hetnum=0
                homnum=0
                if str(vi[0:6])=="#CHROM":
                    vih = str(vi).strip().split('\t')
                    lenght = len(vih)
                else:
                    vic = str(vi).strip().split('\t')
                    chr = vic[0]
                    pos = vic[1]
                    ref = vic[2]
                    alt = vic[3]
                    oc.write(chr+"\t"+pos+"\t"+ref+"\t"+alt+"\t")
                    for i in range(4,int(lenght)):
                        icon = vic[i].strip().split(':')
                        if str(icon[0]) != "./.":
                            num+=1
                            if str(icon[0]) == "0/0" or str(icon[0]) == "0|0" or  str(icon[0]) == "1|" or str(icon[0]) == "1|1" or str(icon[0]) == "1/1":
                                homnum+=1
                            elif str(icon[0]) == "0/1" or str(icon[0]) == "0|1":
                                hetnum+=1
                    pro=float('%.5f'%float(float(num)/float(lenght-4)))
                    oc.write(str(num)+"\t"+str(lenght-4)+"\t"+str(pro)+"\t"+str(hetnum)+"\t"+str(homnum))
                oc.write("\n")
    
    trimfq(ifile,ofile)
    
    #!/usr/bin/env python
    ##coding=utf-8
    
    import os
    import sys
    import argparse
    import re
    
    parser = argparse.ArgumentParser(description="\n\033[1;32;40m python vcf_table.py -i mergy.norm.both.vcf -o mergy.norm.both.xls \n \n")
    parser.add_argument('-i', '--input', help = 'the pathway of the input vcf file ', required = True)
    parser.add_argument('-o', '--output', help = 'the pathway of the output xls file', required = True)
    argv = vars(parser.parse_args())
    ifile = os.path.abspath(argv['input'].strip())
    ofile = os.path.abspath(argv['output'].strip())
    
    def trimfq(inputfile,outfile):
        oc=open(outfile,'w')
        with open(inputfile,'r') as v:
            for vi in v:
                if str(vi[0:2])=="##":
                    continue
                elif str(vi[0:6])=="#CHROM":
                    vicon=str(vi).strip().split('\t')
                    length=len(vicon)
                    oc.write(vicon[0]+"\t"+vicon[1]+"\t"+vicon[3]+"\t"+vicon[4]+"\t")
                    for i in range(9,length):
                        oc.write(vicon[i]+"\t")
                else:
                    vic = str(vi).strip().split('\t')
                    chr = vic[0]
                    pos = vic[1]
                    ref = vic[3]
                    alt = vic[4]
                    oc.write(chr+"\t"+pos+"\t"+ref+"\t"+alt+"\t")
                    for i in range(9,length):
                        icon = vic[i].strip().split(':')
                        ic=icon[0]+":"+icon[1]+":"+icon[2]
                        oc.write(ic+"\t")
                oc.write("\n")
    
    trimfq(ifile,ofile)
    
    

    大写无语

    相关文章

      网友评论

          本文标题:Python40

          本文链接:https://www.haomeiwen.com/subject/vzokvdtx.html