title: Wrong output when trying to create a manifest-generating script (python) for Rail-RNA. Files do not match
body: <p><strong>What I want:</strong> To create a "manifest" for running rail-RNA (<a href="http://rail.bio/" rel="nofollow noreferrer">http://rail.bio/</a>) on a number of fastq files, that I have in a directory, in the following form:</p>
  
  <pre><code>FASTQ URL 1 (tab) optional MD5 1 (tab) FASTQ URL 2 (tab) optional MD5 2 (tab) sample label
  </code></pre>
  
  <p>like:</p>
  
  <pre><code>/home/data/10080-17_r1.fastq   0   /home/data/10080-17_r2.fastq    0    10080-17_r1
  /home/data/10300-25_r1.fastq   0   /home/data/10300-25_r2.fastq    0    10300-25_r1
  /home/data/40500-72_r1.fastq   0   /home/data/40500-72_r2.fastq    0    10300-25_r2
  </code></pre>
  
  <p>.. and so on</p>
  
  <p><strong>What I have done:</strong> created a python script to generate a manifest from fastq files in a specific directory: </p>
  
  <pre><code>#!/usr/bin/python
  import os
  import csv    
  
  thisdir = os.getcwd()
  
  # Create empty lists
  forward = []
  reverse = []
  zero = []
  names = []
  
  # Extract file-paths for files ending with .fastq and append them to "forward" and "reverse"
  for r, d, f in os.walk(thisdir):    # r=root, d=directories, f = files
      for file in f:
          if "_1.fastq" in file:
              forward.append(os.path.join(r, file))
          if "_2.fastq" in file:
              reverse.append(os.path.join(r, file))
  
  # make a list containing 0 with the length of the forward list
  for i in range(len(forward)):
      zero.append('0')
  
  # extract filenames without extensions:
  l = os.listdir(thisdir)
  li = [x.split('.')[0] for x in l]
  for name in li:
      if "_1" in name:
          names.append(name)
  names = [s.strip('_1') for s in names]
  
  # write the output to a file
  with open('manifest.txt', 'w') as f:
      writer = csv.writer(f, delimiter='\t')
      for path in zip(forward, zero, reverse, zero, names):
          writer.writerow(list(path))
  </code></pre>
  
  <p><strong>What is wrong?</strong>: I get a manifest.txt in the right format, BUT, it does not match the right *_r1.fastq and *_r2.fastq files. It does something like this (the r1's in the first column does not match the r2's of the third column)</p>
  
  <pre><code>/home/data/10080-17_r1.fastq   0   /home/data/40500-72_r2.fastq    0    10080-17_r1
  /home/data/10300-25_r1.fastq   0   /home/data/10080-17_r2.fastq    0    10300-25_r1
  /home/data/40500-72_r1.fastq   0   /home/data/10300-25_r2.fastq    0    10300-25_r2
  </code></pre>
  
  <p>Do some of you, more experienced Python'ers have a solution to fix this? 
  That would be greatly appreciated!</p>
  
  <p>Best wishes, Birgitte</p>