python17
2021-08-19 本文已影响0人
rong酱
./cufflinks-2.2.1/gffread GCF_000331145.1_ASM33114v1_genomic.gff -T -F -o GCF_000331145.1_ASM33114v1_genomic.gtf
./cufflinks-2.2.1/gffread GCF_000331145.1_ASM33114v1_genomic.gtf -F -o- >GCF_000331145.1_ASM33114v1_genomic.gff3
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import sys
import argparse
import numpy as np
parser = argparse.ArgumentParser(description="trim data , change geneid to genename")
parser.add_argument('--infile',help=" inputfile ",required=True)
parser.add_argument('--outfile',help="output file",required=True)
argv = vars(parser.parse_args())
infile = argv['infile']
outfile =argv['outfile']
idname = {}
with open('genename',"r") as nameliness:
namelines = nameliness.readlines()
for nameline in namelines:
namelin = nameline.strip().split("\t")
idname[namelin[0]]=namelin[1]
outcon = open(outfile,"w")
with open(infile,"r") as inputliness:
inputlines = inputliness.readlines()
header = inputlines[0].strip().split("\t")
outcon.write(header[0]+"\tgenename\t"+header[2]+"\t"+header[3]+"\tlog2FoldChange\t"+header[5]+"\tpadj\n")
for inputline in inputlines[1:]:
inputlin = inputline.strip().split("\t")
geneid = inputlin[0]
genename = idname[geneid]
controlvalue = inputlin[2]
treatvalue = inputlin[3]
FCvalue = float(inputlin[4])
# print(FCvalue)
# print(type(FCvalue))
Pvalue = inputlin[5]
padj = inputlin[6]
if FCvalue == 0:
log2FCvalue == 0
elif FCvalue > 0:
log2FCvalue = np.log2(FCvalue)
elif FCvalue < 0:
FCvalue1= -FCvalue
log2FCvalue = -np.log2(FCvalue1)
outcon.write(str(geneid)+"\t"+str(genename)+"\t"+str(controlvalue)+"\t"+str(treatvalue)+"\t"+str(log2FCvalue)+"\t"+str(Pvalue)+"\t"+str(padj)+"\n")
完美,半个小时搞定