回答編集履歴

2

投稿者様の結果?に近くなるように直しました

2018/12/03 01:28

投稿

kiwibird
kiwibird

スコア105

test CHANGED
@@ -12,8 +12,6 @@
12
12
 
13
13
  seq = ""
14
14
 
15
-
16
-
17
15
  for line in f.readlines():
18
16
 
19
17
  if line.startswith(">"):
@@ -26,20 +24,48 @@
26
24
 
27
25
  count.append(len(seq))
28
26
 
29
- print(len(seq), end='')
27
+ print(len(seq))
30
28
 
31
29
 
32
30
 
31
+
32
+
33
- >実行結果
33
+ >> 実行結果
34
34
 
35
35
  >YP_009518834.1 putative uncharacterized protein YjiT [Escherichia coli str. K-1
36
36
 
37
37
  2 substr. MG1655]
38
38
 
39
- 070140210280350420490505505505>YP_009518833.1 uncharacterized protein YtiA [Esch
39
+ 0
40
40
 
41
- erichia coli str. K-12 substr. MG1655]
41
+ 70
42
42
 
43
+ 140
44
+
45
+ 210
46
+
47
+ 280
48
+
49
+ 350
50
+
51
+ 420
52
+
53
+ 490
54
+
55
+ 505
56
+
57
+ 505
58
+
59
+ 505
60
+
61
+ >YP_009518833.1 uncharacterized protein YtiA [Escherichia coli str. K-12 substr.
62
+
43
- 505575590
63
+ MG1655]
64
+
65
+ 505
66
+
67
+ 575
68
+
69
+ 590
44
70
 
45
71
  ```

1

仕様がよくわからないのであれですが、とりあえず質問者さんの動かしたいと思われるコードに直しました

2018/12/03 01:28

投稿

kiwibird
kiwibird

スコア105

test CHANGED
@@ -1,87 +1,45 @@
1
- すでに宣言している`count`変数を、forループ内部で再定義しているため、すでに`count`変数は`list`ではありません。なので`append()`も失敗するのでしょう
1
+ あまり良くわかっていませんが...
2
2
 
3
-
4
-
5
- 察するに、以下のよ動作を作りたのだと思います
3
+ いう動作であっていますか?
6
4
 
7
5
 
8
6
 
9
7
  ```python
10
8
 
11
- >>> count = []
9
+ with open("short.sequ.txt", 'rt', encoding='utf-8') as f:
12
10
 
13
- >>> f = (1, 2, 3, 4, 5, 6, 7, 8, 9)
11
+ count = []
14
12
 
15
- >>> for line in f:
13
+ seq = ""
16
14
 
17
- ... count.append(line)
15
+
18
16
 
19
- ... count
17
+ for line in f.readlines():
20
18
 
21
- ...
19
+ if line.startswith(">"):
22
20
 
23
- [1]
21
+ print(line, end='')
24
22
 
25
- [1, 2]
23
+ else:
26
24
 
27
- [1, 2, 3]
25
+ seq += "".join(line.split())
28
26
 
29
- [1, 2, 3, 4]
27
+ count.append(len(seq))
30
28
 
31
- [1, 2, 3, 4, 5]
32
-
33
- [1, 2, 3, 4, 5, 6]
34
-
35
- [1, 2, 3, 4, 5, 6, 7]
36
-
37
- [1, 2, 3, 4, 5, 6, 7, 8]
38
-
39
- [1, 2, 3, 4, 5, 6, 7, 8, 9]
29
+ print(len(seq), end='')
40
30
 
41
31
 
42
32
 
43
- ```
33
+ >実行結果
44
34
 
35
+ >YP_009518834.1 putative uncharacterized protein YjiT [Escherichia coli str. K-1
45
36
 
37
+ 2 substr. MG1655]
46
38
 
47
- 現在の質問者さんの動作はこんな感じです
39
+ 070140210280350420490505505505>YP_009518833.1 uncharacterized protein YtiA [Esch
48
40
 
41
+ erichia coli str. K-12 substr. MG1655]
49
42
 
50
-
51
- ```python
43
+ 505575590
52
-
53
- >>> count = []
54
-
55
- >>> f = (1,2,3,4,5,6,7,8,9)
56
-
57
- >>> for line in f:
58
-
59
- ... count = 0
60
-
61
- ... count += line
62
-
63
- ... count
64
-
65
- ...
66
-
67
- 1
68
-
69
- 2
70
-
71
- 3
72
-
73
- 4
74
-
75
- 5
76
-
77
- 6
78
-
79
- 7
80
-
81
- 8
82
-
83
- 9
84
-
85
- >>>
86
44
 
87
45
  ```