Skip to content

Commit 0775c76

Browse files
Merge pull request (python3 support) from HyperOdin-master
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)"
1 parent 64c4f18 commit 0775c76

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

bin/CPC2.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import sys
66
import os
77
import re
8-
import commands
8+
import subprocess
99
import time
1010
from optparse import OptionParser,OptionGroup
11-
11+
import six
1212
import numpy as np
1313
from Bio.Seq import Seq
1414
from Bio.SeqUtils import ProtParam
15-
1615
import seqio
1716

1817
def __main():
@@ -85,7 +84,7 @@ def find_longest_in_one(self,myframe,direction,start_codon,stop_codon):
8584
'''
8685
while True:
8786
try:
88-
codon,index = triplet_got.next()
87+
codon,index = next(triplet_got)
8988
except StopIteration:
9089
break
9190
if codon in starts and codon not in stops:
@@ -96,7 +95,7 @@ def find_longest_in_one(self,myframe,direction,start_codon,stop_codon):
9695
end_extension = False
9796
while True:
9897
try:
99-
codon,index = triplet_got.next()
98+
codon,index = next(triplet_got)
10099
except StopIteration:
101100
end_extension = True
102101
integrity = -1
@@ -252,9 +251,12 @@ def calculate_potential(fasta,strand,output_orf,outfile):
252251
'''
253252
strinfoAmbiguous = re.compile("X|B|Z|J|U",re.I)
254253
ptU = re.compile("U",re.I)
255-
ftmp_feat = file(outfile + ".feat","w")
256-
ftmp_svm = file(outfile + ".tmp.1","w")
257-
ftmp_result = file(outfile,"w")
254+
## merged by Yang Ding on 2019-11-23
255+
## 1. all python 2-"file"'s are replaced with python 3-"open"'s
256+
## 2. keep kangyj's check on output_orf
257+
ftmp_feat = open(outfile + ".feat","w")
258+
ftmp_svm = open(outfile + ".tmp.1","w")
259+
ftmp_result = open(outfile,"w")
258260
if output_orf == 1:
259261
my_header = ["#ID","transcript_length","peptide_length","Fickett_score","pI","ORF_integrity","ORF_Start","coding_probability","label"]
260262
else:
@@ -315,7 +317,7 @@ def calculate_potential(fasta,strand,output_orf,outfile):
315317
cmd = cmd + app_svm_predict + ' -b 1 -q ' + outfile + '.tmp.2 ' + data_dir + 'cpc2.model ' + outfile + '.tmp.out'
316318
#cmd = cmd + 'awk -vOFS="\\t" \'{if ($1 == 1){print $2,"coding"} else if ($1 == 0){print $2,"noncoding"}}\' ' + outfile + '.tmp.1 > ' + outfile + '.tmp.2 &&'
317319
#cmd = cmd + 'paste ' + outfile + '.feat ' + outfile + '.tmp.2 >>' + outfile
318-
(exitstatus, outtext) = commands.getstatusoutput(cmd)
320+
(exitstatus, outtext) = subprocess.getstatusoutput(cmd)
319321

320322
'''deal with the output'''
321323
#print outfile + '.tmp.out'
@@ -352,7 +354,7 @@ def calculate_potential(fasta,strand,output_orf,outfile):
352354
if exitstatus == 0:
353355
os.system('rm -f ' + outfile + '.tmp.1 ' + outfile + '.tmp.2 ' + outfile + '.tmp.out ' + outfile)
354356
rm_cmd = "rm -f " + outfile + '.feat'
355-
commands.getstatusoutput(rm_cmd)
357+
subprocess.getstatusoutput(rm_cmd)
356358
sys.stderr.write("[INFO] Running Done!\n")
357359
return 0
358360
else:

bin/compress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def gz_file(fq_file,mode,level=6):
1111
fq_fp = gzip.open(fq_file,mode+"b",level)
1212
else:
1313
sys.stderr.write("[INFO] read file '%s'\n"%fq_file)
14-
fq_fp = file(fq_file,mode)
14+
fq_fp = open(fq_file,mode)
1515
except:
1616
sys.stderr.write("Error: Fail to IO file: %s\n"%(fq_file))
1717
sys.exit(1)

bin/seqio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def gtf_parse(fn,add="chr"):
162162

163163
if __name__ == "__main__":
164164
a = [[1,10],[17,22],[40,44],[42,47],[46,100],[101,408]]
165-
print a
166-
print merge_region(a)
165+
print (a)
166+
print (merge_region(a))
167167

168168

169169

0 commit comments

Comments
 (0)