annotate tabular_to_fastq.py @ 4:1f75d46e55f5 draft

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit 31edb920789fbd080260f853bc856be72fa7cfa8"
author devteam
date Fri, 01 Nov 2019 13:22:35 -0400
parents 643018aa1435
children e8ca9af08774
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
643018aa1435 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
643018aa1435 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
643018aa1435 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
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
4 import sys
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
5
3
643018aa1435 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
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
7 def main():
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
8 input_filename = sys.argv[1]
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
9 output_filename = sys.argv[2]
3
643018aa1435 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
643018aa1435 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
643018aa1435 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
643018aa1435 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
643018aa1435 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
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
15 num_reads = None
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
16 skipped_lines = 0
3
643018aa1435 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
17 out = open(output_filename, 'w')
643018aa1435 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
18 for num_reads, line in enumerate(open(input_filename)):
643018aa1435 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
19 fields = line.rstrip('\n\r').split('\t')
643018aa1435 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
20 if len(fields) > max_col:
643018aa1435 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
21 out.write("@%s\n%s\n+\n%s\n" % (fields[identifier_col], fields[sequence_col], fields[quality_col]))
0
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
22 else:
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
23 skipped_lines += 1
3
643018aa1435 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
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
25 out.close()
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
26 if num_reads is None:
3
643018aa1435 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
27 print("Input was empty.")
0
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
28 else:
3
643018aa1435 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 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))
643018aa1435 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
643018aa1435 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
643018aa1435 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 if __name__ == "__main__":
643018aa1435 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
33 main()