-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-fn2-convertTranscript-exampleRun.py
36 lines (32 loc) · 1.16 KB
/
06-fn2-convertTranscript-exampleRun.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
#!/usr/bin/env python3
import pathlib
sampleList = [
{
"from" : "userData/06-gr-exportTranscript/speciesTreatment/speciesDatabase-trimQ30-transcript.fn",
"toFolder" : "userData/06-gr-exportTranscript/speciesTreatment/",
"toFile" : "speciesDatabase-trimQ30-transcript.tsv",
}
]
sampleDict = sampleList[0]
fromStr = sampleDict["from"]
toFolderStr = sampleDict["toFolder"]
toFileStr = sampleDict["toFile"]
pairDict =dict()
keyStr = str()
valueList = list()
for lineStr in open(fromStr).read().splitlines():
if lineStr[0] == ">" and valueList == list():
keyStr = lineStr[1:]
elif lineStr[0] == ">" and valueList != list():
pairDict[keyStr] = valueList
keyStr = lineStr[1:]
valueList = list()
else:
valueList.append(lineStr)
pairDict = { x : "".join(y) for x,y in pairDict.items() }
pathlib.Path( toFolderStr ).mkdir(parents=True,exist_ok=True)
with open( toFolderStr+toFileStr, 'w') as targetHandle:
targetHandle.write("transcript\tsequence\n")
for keyStr,valueStr in pairDict.items():
targetStr=keyStr.split(" ")[0]
targetHandle.write("{}\t{}\n".format(targetStr,valueStr))