-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevCompSampleSheet.py
More file actions
38 lines (31 loc) · 1.11 KB
/
Copy pathrevCompSampleSheet.py
File metadata and controls
38 lines (31 loc) · 1.11 KB
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
#Take the input sample sheet and generate a file with the reverse complement of
#the barcodes.
import sys
import os
import string
#A 10 second google is better than writing
#http://edwards.sdsu.edu/labsite/index.php/robs/396-reverse-complement-dna-sequences-in-python
def rc(dna):
complements = string.maketrans('acgtrymkbdhvACGTRYMKBDHV', 'tgcayrkmvhdbTGCAYRKMVHDB')
rcseq = dna.translate(complements)[::-1]
return rcseq
#loads the samplesheet
sampleSheet = sys.argv[1]
try:
openSheet = open(sampleSheet)
sampleLines = openSheet.readlines()
except:
print("Failed to load file")
#parse the input name and open the output file
sampleSheetBase = os.path.splitext(sampleSheet)
outputFileName = sampleSheetBase[0] + "_revComp" + sampleSheetBase[1]
openOutputFile = open(outputFileName,"w")
#write the header line
openOutputFile.write(sampleLines[0])
#loop over the other lines and replace the barcode with the rev complement
for line in sampleLines[1:]:
splitLine = line.split(",")
splitLine[4] = rc(splitLine[4])
openOutputFile.write( ",".join(splitLine))
#Closey McFinished
openOutputFile.close()