-
Notifications
You must be signed in to change notification settings - Fork 1
/
16-structure.py
executable file
·84 lines (70 loc) · 2.47 KB
/
16-structure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env python
# PBS cluster job submission in Python
# Use picard to merge realigned-around-indel BAM files then makes index
# Then call SNPs with GATK-3.3.0
# By Jean P. Elbers
# Last modified 3 Feb 2015
###############################################################################
Usage = """
16-structure.py - version 1.0
Command:
cd InDir = /work/jelber2/immunome_2014/combined/popgen
1.Run structure
~/bin/structure/structure_kernel_src/structure \
-m Sample \
-e ~/bin/structure/structure_kernel_src/extraparams
File Info:
InDir = /work/jelber2/immunome_2014/combined/popgen
Input Files = mainparams.test.0*
OutDir = InDir
Output Files = structure-results-001-k1_f
structure-results-001-k2_f
etc.
Usage (execute following code in InDir):
~/scripts/immunome_2014/16-structure.py mainparams.test.0*
"""
###############################################################################
import os, sys, subprocess #imports os, sys, subprocess modules
if len(sys.argv)<2:
print Usage
else:
FileList = sys.argv[1:]
RefDir = "/work/jelber2/reference"
InDir = "/work/jelber2/immunome_2014/combined/popgen"
OutDir = InDir
# Customize your options here
for InFileName in FileList:
FilePrefix = "mainparams.test."
Samplepre = InFileName.replace(FilePrefix,'') # creates Sample string
Sample = Samplepre.replace(".","-") # creates Sample string
Queue = "single"
Allocation = "hpc_gopo02"
Processors = "nodes=1:ppn=1"
WallTime = "12:00:00"
LogOut = InDir
LogMerge = "oe"
JobName = "run-structure-%s" % (Sample)
Command ="""
~/bin/structure/structure_kernel_src/structure \
-m %s \
-e ~/bin/structure/structure_kernel_src/extraparams""" % (InFileName)
JobString = """
#!/bin/bash
#PBS -q %s
#PBS -A %s
#PBS -l %s
#PBS -l walltime=%s
#PBS -o %s
#PBS -j %s
#PBS -N %s
cd %s
%s\n""" % (Queue, Allocation, Processors, WallTime, LogOut, LogMerge, JobName, InDir, Command)
#Create pipe to qsub
proc = subprocess.Popen(['qsub'], shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
(child_stdout, child_stdin) = (proc.stdout, proc.stdin)
#Print JobString
JobName = proc.communicate(JobString)[0]
print JobString
print JobName