-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
outsource merging of predicted mhccII alleles
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sys | ||
import re | ||
from pathlib import Path | ||
|
||
|
||
""" | ||
This scripts combines the predicted mhc-II alleles from different `groups` | ||
Usage: | ||
python merge_predicted_mhcII.py '<input>' <output> | ||
""" | ||
|
||
|
||
def main(): | ||
infiles = sys.argv[1] | ||
alleles = {} | ||
|
||
for infile in infiles.split(" "): | ||
filestem = Path(infile).stem | ||
se = re.search(r'^(.+)_(RNA|DNA)', filestem) | ||
group = se.group(1) | ||
|
||
fh = open(infile, "r") | ||
for line in fh: | ||
al = line.strip().split("\t") | ||
for a in al[1:]: | ||
# make sure the alleles were type successfully | ||
if a != "-" and a != "Not typed": | ||
if a not in alleles: | ||
alleles[a] = [] | ||
if group not in alleles[a]: | ||
alleles[a].append(group) | ||
fh.close() | ||
|
||
out = open(sys.argv[2], 'w') | ||
for al in dict(sorted(alleles.items())): | ||
for i,v in enumerate(alleles[al]): | ||
if i == 0: | ||
out.write(v) | ||
else: | ||
out.write(f',{v}') | ||
out.write(f'\t{al}\n') | ||
|
||
main() |