annotate fasta_report_sequence_lengths.py @ 0:4b01f0d7b350 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
author rnateam
date Fri, 06 Jul 2018 09:01:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
1 #!/usr/bin/env python
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
2
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
3 import sys
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
4
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
5 """
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
6 Input: FASTA file
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
7 Output: Print sequence ID and corresponding sequence length
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
8
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
9 Example output:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
10 chr1 248956422
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
11 chr2 242193529
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
12 chr3 198295559
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
13 ...
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
14
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
15 """
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
16
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
17 # Check input.
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
18 if not len(sys.argv) == 2:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
19 exit("Usage: fasta_report_sequence_lengths.py <fasta_file>")
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
20
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
21 fasta_file = sys.argv[1]
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
22
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
23 seq_id = "id"
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
24 seq_len = 0
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
25
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
26 # Go through FASTA file, extract sequence lengths.
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
27 with open(fasta_file) as f:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
28 for line in f:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
29 if line.startswith(">"):
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
30 new_id = line[1:].strip()
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
31 if seq_len:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
32 print("%s\t%i" % (seq_id, seq_len))
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
33 seq_len = 0
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
34 seq_id = new_id
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
35 else:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
36 seq_len += len(line.strip())
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
37
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
38 # Print last sequence length.
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
39 if seq_len:
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
40 print("%s\t%i" % (seq_id, seq_len))
4b01f0d7b350 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sshmm/ commit b578a90031fd7061fbdaef48b6a66d895ac077c3
rnateam
parents:
diff changeset
41