{"id":189,"date":"2017-12-09T20:08:34","date_gmt":"2017-12-09T12:08:34","guid":{"rendered":"http:\/\/www.wuchangsong.com\/?p=189"},"modified":"2017-12-09T20:25:47","modified_gmt":"2017-12-09T12:25:47","slug":"%e5%a4%9a%e4%b8%aa%e7%9b%b8%e5%90%8c%e8%a1%8c%e5%88%97%e6%96%87%e4%bb%b6%e7%9a%84%e5%90%88%e5%b9%b6","status":"publish","type":"post","link":"http:\/\/www.wuchangsong.com\/?p=189","title":{"rendered":"\u591a\u4e2a\u76f8\u540c\u884c\u5217\u6587\u4ef6\u7684\u5408\u5e76"},"content":{"rendered":"<pre>#\uff01 \/usr\/bin\/python\r\n \r\nimport glob\r\n\r\nout_file1 = open(r\"E:\\\\Git-2.11.1-64-bit\\\\Git\\\\localhost\\\\lianshou\\\\4WGCNA\\\\merge.txt\", \"w\")\r\n \r\nMyDiction = {}\r\n \r\ndef Readfile(File):\r\n    file_obj = open(File)\r\n    try:\r\n        while True:\r\n            line = file_obj.readline().strip(\"\\n\")\r\n            if not line:\r\n                break\r\n            array = line.split(\"\\t\")\r\n            if array[0] in MyDiction:\r\n                MyDiction[array[0]].append(array[1])\r\n            else:\r\n                MyDiction[array[0]] = [array[1]]\r\n    finally:\r\n        file_obj.close()\r\n    return MyDiction\r\n \r\ndef main():\r\n    list_dirs = glob.glob(\".\/*.txt\")\r\n    for i in list_dirs:\r\n        Readfile(i)\r\n    for gene_name in MyDiction:\r\n        #print (\"%s\\t%s\" %(gene_name, \"\\t\".join(MyDiction[gene_name]))) \r\n        out_file1.write(\"%s\\t%s%s\" %(gene_name, \"\\t\".join(MyDiction[gene_name]),\"\\n\"))\r\n \r\nif __name__ == '__main__':\r\n    main()\r\n<\/pre>\n<p>\u811a\u672c\u6765\u81ea\u4e8e<a href=\"http:\/\/www.biotrainee.com:8080\/thread-603-1-1.html\">\u751f\u4fe1\u6280\u80fd\u6811<\/a>\u5f88\u5b9e\u7528\uff0c\u5b66\u4e60\u5230\u4e86glob\u5305\u7684\u5999\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#\uff01 \/usr\/bin\/python import glob out_file1 = open(r&#8221;E:\\\\Git-2.11.1-64-bit\\\\Git\\\\localhost\\\\lianshou\\\\4WGCNA\\\\merge.txt&#8221;, &#8220;w&#8221;) MyDiction = {} def Readfile(File): file_obj = open(File) try: while True: line = file_obj.readline().strip(&#8220;\\n&#8221;) if not line: break array = line.split(&#8220;\\t&#8221;) if array[0] in MyDiction: MyDiction[array[0]].append(array[1]) else: MyDiction[array[0]] = [array[1]] finally: file_obj.close() return MyDiction def main(): list_dirs = glob.glob(&#8220;.\/*.txt&#8221;) for i in list_dirs: Readfile(i) for gene_name in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/189"}],"collection":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":5,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":194,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions\/194"}],"wp:attachment":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}