File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def write_to_file(self, handle):
22
22
handle .write (self .sequence + "\n " )
23
23
24
24
# Functions
25
- def myopen (infile , mode = "r " ):
25
+ def myopen (infile , mode = "rt " ):
26
26
if infile .endswith (".gz" ):
27
27
return gzip .open (infile , mode = mode )
28
28
else :
@@ -69,7 +69,7 @@ def fasta_iterator(input_file):
69
69
70
70
fasta_sequences = fasta_iterator (fasta_file )
71
71
72
- with open (result_file , "w " ) as f :
72
+ with open (result_file , "wt " ) as f :
73
73
for seq in fasta_sequences :
74
74
name = seq .name .split (" " )[0 ]
75
75
if name in wanted and len (seq .sequence ) > 0 :
Original file line number Diff line number Diff line change 6
6
%program input_file output_file
7
7
"""
8
8
9
+ # Modules
10
+ import gzip
9
11
import sys
10
12
11
13
try :
14
16
print ("This program requires the Biopython library" )
15
17
sys .exit (0 )
16
18
19
+ # Defining functions
20
+ def myopen (_file , mode = "rt" ):
21
+ if _file .endswith (".gz" ):
22
+ return gzip .open (_file , mode = mode )
23
+
24
+ else :
25
+ return open (_file , mode = mode )
26
+
27
+ # Parse user input
17
28
try :
18
- in_file = open (sys .argv [1 ], "rU " )
19
- out_file = open (sys .argv [2 ], "w " )
29
+ in_file = myopen (sys .argv [1 ], "rt " )
30
+ out_file = myopen (sys .argv [2 ], "wt " )
20
31
except :
21
32
print (__doc__ )
22
33
sys .exit (0 )
23
34
35
+ # Treat sequences
24
36
sequences = ([seq .id , seq .seq .tostring ()] for seq in SeqIO .parse (in_file , 'fasta' ))
25
37
with open (sys .argv [2 ], "w" ) as out_file :
26
38
for seq in sequences :
You can’t perform that action at this time.
0 commit comments