Mercurial > repos > devteam > tabular_to_fastq
annotate tabular_to_fastq.py @ 5:78fb18899c99 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit bb5df9e62585e12f08dfc0a9f86eec8e205b4845
author | iuc |
---|---|
date | Fri, 04 Oct 2024 10:35:38 +0000 |
parents | 2dcfbbf9071a |
children |
rev | line source |
---|---|
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
1 # Dan Blankenberg |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
2 from __future__ import print_function |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
3 |
0 | 4 import sys |
5 | |
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
6 |
0 | 7 def main(): |
8 input_filename = sys.argv[1] | |
9 output_filename = sys.argv[2] | |
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
10 identifier_col = int(sys.argv[3]) - 1 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
11 sequence_col = int(sys.argv[4]) - 1 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
12 quality_col = int(sys.argv[5]) - 1 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
13 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
14 max_col = max(identifier_col, sequence_col, quality_col) |
0 | 15 num_reads = None |
16 skipped_lines = 0 | |
4
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
17 with open(output_filename, 'w') as out: |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
18 for num_reads, line in enumerate(open(input_filename)): |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
19 fields = line.rstrip('\n\r').split('\t') |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
20 if len(fields) > max_col: |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
21 out.write("@%s\n%s\n+\n%s\n" % (fields[identifier_col], fields[sequence_col], fields[quality_col])) |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
22 else: |
2dcfbbf9071a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit d4ced60a941c4c4a2fe95de9c09a10086810b387"
iuc
parents:
2
diff
changeset
|
23 skipped_lines += 1 |
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
24 |
0 | 25 if num_reads is None: |
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
26 print("Input was empty.") |
0 | 27 else: |
2
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
28 print("%i tabular lines were written as FASTQ reads. Be sure to use the FASTQ Groomer tool on this output before further analysis." % (num_reads + 1 - skipped_lines)) |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
29 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
30 |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
31 if __name__ == "__main__": |
b8cdc0507586
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
devteam
parents:
0
diff
changeset
|
32 main() |