Created
May 22, 2015 06:53
-
-
Save soh-i/773e7a8fa930999ea6c4 to your computer and use it in GitHub Desktop.
Link pre- and mature given GFF record
This file contains hidden or 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
| def link_mature_and_pre(pre_dic, mature_dic): | |
| """ | |
| miR-XXX-3p, miR-XXX-5p (mature) are derives from mir-XXX (pre), | |
| then it can be linked following: | |
| {pre: {3p: XXX, 5p: XXX}} | |
| """ | |
| def matID_to_name(q, mature_HTSeq): | |
| # MIRAMTXXXX (transcript_id) to miR-XXX-Xp | |
| matures = [] | |
| for name, attr in mature_HTSeq.items(): | |
| if q == attr.attr["Derives_from"]: | |
| matures.append(attr.attr["Name"]) | |
| return matures | |
| def name_to_matID(q, mature_dic): | |
| # miR-XXX-Xp to MIMATXXXXX (transcript_id) | |
| for name, attr in mature_dic.items(): | |
| if q == attr.attr["Name"]: | |
| return attr | |
| def classify_miRNA(matures, mature_dic): | |
| """ | |
| Define type of 3p or 5p or '' in mature miRNA | |
| Args: | |
| [miR-XXX-3p, miR-XXX-5p] | |
| Returns: | |
| {"3p": miR-XXX-3p, "5p": miR-XXX-5p} | |
| """ | |
| _type = {} | |
| for mat in matures: | |
| if re.match(r"^hsa-(:?miR|let)(?:-[\d\w]+)(-3p$)", mat): | |
| _type["3p"] = name_to_matID(mat, mature_dic) | |
| elif re.match(r"^hsa-(:?miR|let)(?:-[\d\w]+)(-5p$)", mat): | |
| _type["5p"] = name_to_matID(mat, mature_dic) | |
| elif re.match(r"^hsa-(:?miR|let)(?:-[\d\w]+)$", mat): | |
| _type["unknown"] = name_to_matID(mat, mature_dic) | |
| return _type | |
| result = defaultdict(str) | |
| for pre_id, pre_attr in pre_dic.items(): | |
| if pre_id in [mature_dic[_].attr["Derives_from"] for _ in mature_dic]: | |
| # link pre and mature | |
| result[pre_id] = classify_miRNA(matID_to_name(pre_id, mature_dic), mature_dic) | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment