Skip to content

Instantly share code, notes, and snippets.

@johandahlberg
Created November 21, 2012 13:43
Show Gist options
  • Save johandahlberg/4124889 to your computer and use it in GitHub Desktop.
Save johandahlberg/4124889 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
def get_immediate_subdirectories(dir):
return [name for name in os.listdir(dir)
if os.path.isdir(os.path.join(dir, name))]
# Get runfolder name from file and return as list.
def get_runfolders_already_run(file):
runfolders = list()
file = open(file)
for line in file:
runfolders.append(line.rstrip())
return runfolders
def print_sample_folder_entries(runFolder):
for dir in get_immediate_subdirectories(runFolder):
if ("Sample_" in dir):
sampleName = dir.replace("Sample_","")
samplePath = runFolder + "/" + dir
print ("\t\t<SampleFolder Name=\"%s\" Path=\"%s/\" Reference=\"reference/Homo_sapiens.GRCh37.57.dna.concat.fa\"></SampleFolder>" % (sampleName, samplePath))
#------------------------------------------------------------------
# Make a list of all runfolders which have already been processed.
#------------------------------------------------------------------
# Read a file of with the runfolder names and add them to a hash
#-> define function to get this hash
runFoldersAlreadyRunFile = "runFoldersAlreadyRun.txt"
runFoldersAlreadyRun = get_runfolders_already_run(runFoldersAlreadyRunFile)
rootDir = "../../"
#------------------------------------------------------------------
#
#------------------------------------------------------------------
print """<Project Name="Some project" SequencingCenter="SnqSeq - Uppsala" Platform="Illumina" UppmaxProjectId="a2009002">"""
for runFolder in get_immediate_subdirectories(rootDir):
if "_" in runFolder.lower() and runFolder not in runFoldersAlreadyRun:
print("\t<RunFolder Report=\"%s%s/report.xml\">" % (rootDir, runFolder))
print_sample_folder_entries(rootDir + runFolder)
print("\t</RunFolder>")
with open(runFoldersAlreadyRunFile,"a") as f:
f.write("\n" + runFolder)
print "</Project>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment