Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements according to Python 3.6 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 13 additions & 14 deletions bin/CPC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import sys
import os
import re
import commands
import subprocess
import time
from optparse import OptionParser,OptionGroup

import six
import numpy as np
from Bio.Seq import Seq
from Bio.SeqUtils import ProtParam

import seqio

def __main():
Expand All @@ -29,7 +28,7 @@ def __main():
return -1
else:
if not os.path.isfile(options.fasta):
sys.stderr.write("\n[ERROR] %s is not a file\n"%options.fasta)
sys.stderr.write("[ERROR] %s is not a file\n"%options.fasta)
return -1
if options.reverse:
strand = "-"
Expand Down Expand Up @@ -78,7 +77,7 @@ def find_longest_in_one(self,myframe,direction,start_codon,stop_codon):
'''
while True:
try:
codon,index = triplet_got.next()
codon,index = next(triplet_got)
except StopIteration:
break
if codon in starts and codon not in stops:
Expand All @@ -89,7 +88,7 @@ def find_longest_in_one(self,myframe,direction,start_codon,stop_codon):
end_extension = False
while True:
try:
codon,index = triplet_got.next()
codon,index = next(triplet_got)
except StopIteration:
end_extension = True
integrity = -1
Expand Down Expand Up @@ -245,9 +244,9 @@ def calculate_potential(fasta,strand,outfile):
'''
strinfoAmbiguous = re.compile("X|B|Z|J|U",re.I)
ptU = re.compile("U",re.I)
ftmp_feat = file(outfile + ".feat","w")
ftmp_svm = file(outfile + ".tmp.1","w")
ftmp_result = file(outfile,"w")
ftmp_feat = open(outfile + ".feat","w")
ftmp_svm = open(outfile + ".tmp.1","w")
ftmp_result = open(outfile,"w")
ftmp_result.write("\t".join(map(str,["#ID","transcript_length","peptide_length","Fickett_score","pI","ORF_integrity","coding_probability","label"]))+"\n")
ftmp_result.close()
fickett_obj = Fickett()
Expand Down Expand Up @@ -280,7 +279,7 @@ def calculate_potential(fasta,strand,outfile):
'''
calculate the coding probability using LIBSVM
'''
sys.stderr.write("\n[INFO] Predicting coding potential, please wait ...")
sys.stderr.write("[INFO] Predicting coding potential, please wait ...\n")

'''
set directories and check depending tools existance
Expand All @@ -297,18 +296,18 @@ def calculate_potential(fasta,strand,outfile):
cmd = cmd + app_svm_predict + ' -b 1 -q ' + outfile + '.tmp.2 ' + data_dir + 'cpc2.model ' + outfile + '.tmp.1 &&'
cmd = cmd + 'awk -vOFS="\\t" \'{if ($1 == 1){print $2,"coding"} else if ($1 == 0){print $2,"noncoding"}}\' ' + outfile + '.tmp.1 > ' + outfile + '.tmp.2 &&'
cmd = cmd + 'paste ' + outfile + '.feat ' + outfile + '.tmp.2 >>' + outfile
(exitstatus, outtext) = commands.getstatusoutput(cmd)
(exitstatus, outtext) = subprocess.getstatusoutput(cmd)
os.system('rm -f ' + outfile + '.tmp.1 ' + outfile + '.tmp.2')
# subprocess.call("Rscript " + outfile + '.r', shell=True)
#except:
# pass
if exitstatus == 0:
rm_cmd = "rm -f " + outfile + '.feat'
commands.getstatusoutput(rm_cmd)
sys.stderr.write("\n[INFO] Running Done!\n")
subprocess.getstatusoutput(rm_cmd)
sys.stderr.write("[INFO] Running Done!\n")
return 0
else:
sys.stderr.write("\n[ERROR] Prediction error!\n")
sys.stderr.write("[ERROR] Prediction error!\n")
return -1

if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions bin/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def gz_file(fq_file,mode,level=6):
if fq_file.endswith("gz"):
fq_fp = gzip.open(fq_file,mode+"b",level)
else:
sys.stderr.write("\n[INFO] read file '%s'"%fq_file)
fq_fp = file(fq_file,mode)
sys.stderr.write("[INFO] read file '%s'\n"%fq_file)
fq_fp = open(fq_file,mode)
except:
sys.stderr.write("\nError: Fail to IO file: %s\n"%(fq_file))
sys.stderr.write("Error: Fail to IO file: %s\n"%(fq_file))
sys.exit(1)
return fq_fp

Expand All @@ -23,7 +23,7 @@ def bz2file(f):
if f.endswith("bz2"):
fz = bz2.BZ2File(f)
else:
sys.stderr.write("\nError: Fail to IO file: %s\n"%(f))
sys.stderr.write("Error: Fail to IO file: %s\n"%(f))
sys.exit(1)
return fz

4 changes: 2 additions & 2 deletions bin/seqio.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def gtf_parse(fn,add="chr"):

if __name__ == "__main__":
a = [[1,10],[17,22],[40,44],[42,47],[46,100],[101,408]]
print a
print merge_region(a)
print(a)
print(merge_region(a))