Commits

Mike Steder  committed bbab080

got demuxer working

  • Participants
  • Parent commits 11960c7

Comments (0)

Files changed (3)

File tools/globus/cga_demuxer.xml

     </param>
    </inputs>
    <outputs>
-     <data format="dat" type="data" name="output1"/>
+     <data format="cga" type="data" name="output1"/>
      <change_format>
-       <when input="out_format" value="dat" format="dat" />
+       <when input="out_format" value="cga" format="dat" />
        <when input="out_format" value="sam" format="sam" />
        <when input="out_format" value="bam" format="bam" />
      </change_format>

File tools/globus/demuxer.py

     return lane_number, part_number
 
 
-def extract_file(data, key, lane_number, part_number):
-    parts = data[key]
-    for name in parts:
-        part = parts[name]
-        lane_no, part_no = parse_lane_and_part_numbers(part["reads"])
-        if lane_no == lane_number and part_no == part_number:
-            datapath = parts["reads"]
+def extract_file(data, extension, lane_number, part_number, outpath):
+    filepaths = data["files"]
+    print "lane_number:", lane_number, "part_number:", part_number
+    for path in filepaths:
+        print "path:", path
+        lane_no, part_no = parse_lane_and_part_numbers(path)
+        print "lane_no, part_no:", lane_no, part_no
+        if lane_no == lane_number and part_no == part_number and path.endswith(extension):
+            datapath = path
             print "Creating a symbolic link to the data %s at outpath %s"%(
                 datapath, outpath)
-            os.link(datapath, outpath)
-
+            if not os.path.exists(datapath):
+                print "Some of these tools add another extension (e.g.: samtools sam2bam) .bam extensions..."
+                datapath += ".%s"%(extension,)
+            print "os.path.exists(outpath):", os.path.exists(outpath)
+            os.unlink(outpath)
+            os.symlink(datapath, outpath)
+            return
+    raise Exception("File not found!")
 
 
 def convert_to_dataset(inpath, indir, outpath,
                        output_type, lane_number, part_number):
+    try:
+        lane_number = int(lane_number)
+    except ValueError:
+        print "Invalid lane number!"
+    try:
+        part_number = int(lane_number)
+    except ValueError:
+        print "Invalid part number!"
+
     with open(inpath, "r") as json_file:
         data = json.load(json_file)
         files = data["files"]
         #for f in files:
         #    print f
-        if output_type == "dat":
+        if output_type == "cga":
             parts = data["parts"]
             for name in parts:
                 part = parts[name]
                         datapath, outpath)
                     os.link(datapath, outpath)
         elif output_type == "sam":
-            extract_file(data, "sam", lane_number, part_number)
+            extract_file(data, "sam", lane_number, part_number, outpath)
         elif output_type == "bam":
-            extract_file(data, "bam", lane_number, part_number)
+            extract_file(data, "bam", lane_number, part_number, outpath)
 
                 
 if __name__ == "__main__":

File tools/globus/map2sam_condor_run.xml

       <option value="12">12</option>
     </param>
   </inputs>
-
   <outputs>
-    <data format="cgadata" name="output1" />
+    <data format="cga" name="output1" />
   </outputs>
-
-
   <help>
     The Map2Sam converter takes as input Reads and Mappings files, a library 
     structure file and a crr reference file and generates one SAM file as an 
     mappings and highlight them using the appropriate flag. The negative gaps 
     in CGI mappings are represented using GS/GQ/GC tags.
   </help>
-
 </tool>