Skip to content

Commit

Permalink
Merge pull request (python3 support) from HyperOdin-master
Browse files Browse the repository at this point in the history
Changes:

1. all usages of python 2-"file"'s are replaced with python 3-
   "open"'s
2. import six for python 2 and 3 compatibility
3. replace python 2-commands module with python 3-subprocess
   module
4. replace python 2-"print x" with python 3-"print (x)"
  • Loading branch information
yangdingyangding committed Nov 23, 2019
1 parent 64c4f18 commit 0775c76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 12 additions & 10 deletions bin/CPC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,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 Down Expand Up @@ -85,7 +84,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 @@ -96,7 +95,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 @@ -252,9 +251,12 @@ def calculate_potential(fasta,strand,output_orf,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")
## merged by Yang Ding on 2019-11-23
## 1. all python 2-"file"'s are replaced with python 3-"open"'s
## 2. keep kangyj's check on output_orf
ftmp_feat = open(outfile + ".feat","w")
ftmp_svm = open(outfile + ".tmp.1","w")
ftmp_result = open(outfile,"w")
if output_orf == 1:
my_header = ["#ID","transcript_length","peptide_length","Fickett_score","pI","ORF_integrity","ORF_Start","coding_probability","label"]
else:
Expand Down Expand Up @@ -315,7 +317,7 @@ def calculate_potential(fasta,strand,output_orf,outfile):
cmd = cmd + app_svm_predict + ' -b 1 -q ' + outfile + '.tmp.2 ' + data_dir + 'cpc2.model ' + outfile + '.tmp.out'
#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)

'''deal with the output'''
#print outfile + '.tmp.out'
Expand Down Expand Up @@ -352,7 +354,7 @@ def calculate_potential(fasta,strand,output_orf,outfile):
if exitstatus == 0:
os.system('rm -f ' + outfile + '.tmp.1 ' + outfile + '.tmp.2 ' + outfile + '.tmp.out ' + outfile)
rm_cmd = "rm -f " + outfile + '.feat'
commands.getstatusoutput(rm_cmd)
subprocess.getstatusoutput(rm_cmd)
sys.stderr.write("[INFO] Running Done!\n")
return 0
else:
Expand Down
2 changes: 1 addition & 1 deletion bin/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def gz_file(fq_file,mode,level=6):
fq_fp = gzip.open(fq_file,mode+"b",level)
else:
sys.stderr.write("[INFO] read file '%s'\n"%fq_file)
fq_fp = file(fq_file,mode)
fq_fp = open(fq_file,mode)
except:
sys.stderr.write("Error: Fail to IO file: %s\n"%(fq_file))
sys.exit(1)
Expand Down
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))



0 comments on commit 0775c76

Please sign in to comment.