Fix "undefined method `uuid' for nil:NilClass". closes #3576
[arvados.git] / crunch_scripts / split-fastq.py
index 8382eb13f95caeebd1440e9e37eda0afa9863824..be37f043f3859c715f1cfa668173bb2246b7da10 100755 (executable)
@@ -88,7 +88,7 @@ def splitfastq(p):
             if count % 10000 == 0:
                 print >>sys.stderr, "Record %s at %s" % (count, p[i]["end"])
 
-prog = re.compile(r'(.*?)(_12)?\.fastq(\.gz)?$')
+prog = re.compile(r'(.*?)(_[12])?\.fastq(\.gz)?$')
 
 # Look for fastq files
 for s in inp.all_streams():
@@ -101,28 +101,27 @@ for s in inp.all_streams():
                 # directories in the input, the choice is either to forget
                 # there are directories (which might lead to name conflicts) or
                 # just fail.
-                print >>sys.stderr, "fastq must be at the root of the collection")
+                print >>sys.stderr, "fastq must be at the root of the collection"
                 sys.exit(1)
 
+            p = None
             if name_pieces.group(2) != None:
                 if name_pieces.group(2) == "_1":
                     p = [{}, {}]
                     p[0]["reader"] = s.files()[name_pieces.group(0)]
-                    if name_pieces.group(2) != None:
-                        p[1]["reader"] = s.files()[name_pieces.group(1) + "_2.fastq" + name_pieces.group(2)]
-                    else:
-                        p[1]["reader"] = s.files()[name_pieces.group(1) + "_2.fastq"]
+                    p[1]["reader"] = s.files()[name_pieces.group(1) + "_2.fastq" + (name_pieces.group(3) if name_pieces.group(3) else '')]
             else:
                 p = [{}]
                 p[0]["reader"] = s.files()[name_pieces.group(0)]
 
-            if chunking:
-                splitfastq(p)
-            else:
-                for i in xrange(0, len(p)):
-                    m = p[i]["reader"].as_manifest()[1:]
-                    manifest_list.append(["./_" + str(piece), m[:-1]])
-                piece += 1
+            if p != None:
+                if chunking:
+                    splitfastq(p)
+                else:
+                    for i in xrange(0, len(p)):
+                        m = p[i]["reader"].as_manifest()[1:]
+                        manifest_list.append(["./_" + str(piece), m[:-1]])
+                    piece += 1
 
 manifest_text = "\n".join(" ".join(m) for m in manifest_list)