2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
11 api = arvados.api('v1')
16 # Look for paired reads
18 inp = arvados.CollectionReader(arvados.getjobparam('reads'))
22 def nextline(reader, start):
25 r = reader.readfrom(start, 128)
28 n = string.find(r, "\n")
35 prog = re.compile(r'(.*?)(_[12])?\.fastq(\.gz)?$')
37 # Look for fastq files
38 for s in inp.all_streams():
39 for f in s.all_files():
40 name_pieces = prog.match(f.name())
41 if name_pieces is not None:
43 # The downstream tool (run-command) only iterates over the top
44 # level of directories so if there are fastq files in
45 # directories in the input, the choice is either to forget
46 # there are directories (which might lead to name conflicts) or
48 print >>sys.stderr, "fastq must be at the root of the collection"
52 if name_pieces.group(2) is not None:
53 if name_pieces.group(2) == "_1":
55 p[0]["reader"] = s.files()[name_pieces.group(0)]
56 p[1]["reader"] = s.files()[name_pieces.group(1) + "_2.fastq" + (name_pieces.group(3) if name_pieces.group(3) else '')]
59 p[0]["reader"] = s.files()[name_pieces.group(0)]
62 for i in xrange(0, len(p)):
63 m = p[i]["reader"].as_manifest().split()
64 m[0] = "./_" + str(piece)
65 manifest_list.append(m)
68 manifest_text = "\n".join(" ".join(m) for m in manifest_list) + "\n"
70 arvados.current_task().set_output(manifest_text)