Guest User

Untitled

a guest
Nov 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. # usage:
  2. # python 3reads.py /batch/dir1/ /batch/dir2/ # run all steps on two batches
  3. # python 3reads.py -2 -3 -loadAndKeep /batch/dir # run steps 2 and 3 and use STAR --loadAndKeep
  4. # python 3reads.py /batch/dir1 /batch/dir2/ -13 # run steps 1 and 3 on two batches
  5. import sys, os
  6.  
  7. base_dir = '/home/sxv/code/s7s/'
  8. MAKE_FASTQ = '%s/make_fastq.sh' % base_dir
  9. ALIGN = '%s/align_smart-3seq.sh' % base_dir
  10. MAKE_EXPRESSION_TABLE = '%s/make_expression_table.R' % base_dir
  11.  
  12. steps = '123'
  13. batch_dirs = []
  14.  
  15. for arg in sys.argv[1:]:
  16. if arg[0] == '-':
  17. if arg == '-loadAndKeep' or arg == '-keep':
  18. ALIGN = '%s/align_smart-3seq.loadAndKeep.sh' % base_dir
  19. else:
  20. if steps == '123':
  21. steps = arg[1:]
  22. else:
  23. steps += arg[1:]
  24. else:
  25. batch_dirs.append(arg)
  26.  
  27. def make_fastq():
  28. os.system("bash -c 'cp %s %s'" % (MAKE_FASTQ, batch_dir))
  29. os.system("bash -c 'cd %s && bash %s .'" % (batch_dir, MAKE_FASTQ))
  30. os.system("bash -c 'cd %s && mkdir -p fastq && mv *gz fastq'" % batch_dir)
  31.  
  32. def align():
  33. os.system("bash -c 'cp %s %s/fastq/'" % (ALIGN, batch_dir))
  34. os.system("bash -c 'cd %s/fastq && bash %s /media/stroma-common/genome/hg38/star/dbsnp147_gencode25-68/ *fastq.gz'" % (batch_dir, ALIGN))
  35. os.system("bash -c 'cd %s && mkdir -p bam && mv fastq/*ba? fastq/*log bam/'" % batch_dir)
  36.  
  37. def make_expression_table():
  38. os.system("bash -c 'cp %s %s/bam'" % (MAKE_EXPRESSION_TABLE, batch_dir))
  39. os.system("bash -c 'cd %s/bam && Rscript %s --no-rlog /media/stroma-common/genome/hg38/gencode.v25.annotation.gtf *bam'" % (batch_dir, MAKE_EXPRESSION_TABLE))
  40. os.system("bash -c 'cd %s/bam && xlsx2csv -s 1 gene_expression.xlsx raw_reads.csv'" % batch_dir)
  41. project_name = batch_dir.split('/')[-1] or batch_dir.split('/')[-2]
  42. os.system("bash -c 'cd %s/bam && cp raw_reads.csv %s.raw_reads.csv && cp raw_reads.csv %sresults/%s.raw_reads.csv'" % (batch_dir, project_name, base_dir, project_name))
  43.  
  44. for batch_dir in batch_dirs:
  45. if '1' in steps: make_fastq()
  46. if '2' in steps: align()
  47. if '3' in steps: make_expression_table()
  48. # if 'o' in steps: optional_step()
Add Comment
Please, Sign In to add comment