File tree 3 files changed +17
-11
lines changed
3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Return the total of a file or stream with one number per line
3
+ awk ' {t+=$1} END {print t/NR}'
Original file line number Diff line number Diff line change @@ -49,11 +49,11 @@ def fasta_iterator(input_file):
49
49
yield Fasta (name , "" .join (sequence ))
50
50
51
51
name = line [1 :]
52
- sequence = ""
52
+ sequence = []
53
53
begun = True
54
54
55
55
else :
56
- sequence += line
56
+ sequence . append ( line )
57
57
58
58
if name != "" :
59
59
yield Fasta (name , "" .join (sequence ))
@@ -69,8 +69,7 @@ def fasta_iterator(input_file):
69
69
70
70
fasta_sequences = fasta_iterator (input_file )
71
71
72
- with open (output_file , "wt" ) as outfile :
72
+ with myopen (output_file , "wt" ) as outfile :
73
73
for seq in fasta_sequences :
74
74
if len (seq .sequence ) >= min_length :
75
75
seq .write_to_file (outfile )
76
-
Original file line number Diff line number Diff line change @@ -30,26 +30,30 @@ def myopen(_file, mode="rt"):
30
30
else :
31
31
return open (_file , mode = mode )
32
32
33
- def fasta_iterator (genome_file ):
34
- """Takes a fasta file genome_file and returns a fasta iterator
33
+ def fasta_iterator (input_file ):
34
+ """Takes a fasta file input_file and returns a fasta iterator
35
35
"""
36
- with myopen (genome_file ) as f :
37
- sequence = ""
36
+ with myopen (input_file ) as f :
37
+ sequence = []
38
38
name = ""
39
39
begun = False
40
+
40
41
for line in f :
41
42
line = line .strip ()
43
+
42
44
if line .startswith (">" ):
43
45
if begun :
44
- yield Fasta (name , sequence )
45
- name = line .replace (">" , "" )
46
+ yield Fasta (name , "" .join (sequence ))
47
+
48
+ name = line [1 :]
46
49
sequence = ""
47
50
begun = True
51
+
48
52
else :
49
53
sequence += line
50
54
51
55
if name != "" :
52
- yield Fasta (name , sequence )
56
+ yield Fasta (name , "" . join ( sequence ) )
53
57
54
58
if __name__ == '__main__' :
55
59
# Prevent broken pipe error
You can’t perform that action at this time.
0 commit comments