首页 > 编程语言 >python中统计人类基因组的外显子总长度(部分测试序列)

python中统计人类基因组的外显子总长度(部分测试序列)

时间:2022-08-16 23:35:46浏览次数:48  
标签:Identical temp 外显子 python PC1 基因组 cds test home

 

001、方法1

root@PC1:/home/test# ls
a.txt  test.py
root@PC1:/home/test# cat a.txt                                            ## 测试数据
#chromosome     nc_accession    gene    gene_id ccds_id ccds_status     cds_strand      cds_from        cds_to  cds_locations   match_type
1       NC_000001.8     LINC00115       79854   CCDS1.1 Withdrawn       -       801942  802433  [801942-802433] Identical
1       NC_000001.11    SAMD11  148398  CCDS2.2 Public  +       925941  944152  [925941-926012, 930154-930335, 931038-931088, 935771-935895, 939039-939128, 939274-939459, 941143-941305, 942135-942250, 942409-942487, 942558-943057, 943252-943376, 943697-943807, 943907-944152]       Identical
1       NC_000001.11    NOC2L   26155   CCDS3.1 Public  -       944693  959239  [944693-944799, 945056-945145, 945517-945652, 946172-946285, 946401-946544, 948130-948231, 948489-948602, 951126-951237, 951999-952138, 952411-952599, 953174-953287, 953781-953891, 954003-954081, 955922-956012, 956094-956214, 956893-957024, 957098-957272, 958928-959080, 959214-959239]     Identical
1       NC_000001.11    PLEKHN1 84069   CCDS4.1 Public  +       966531  974574  [966531-966613, 966703-966802, 970276-970422, 970520-970600, 970685-970757, 970878-971005, 971112-971207, 971323-971403, 972074-972149, 972287-972423, 972860-973009, 973185-973325, 973499-973639, 973832-974050, 974315-974363, 974441-974574]  Identical
root@PC1:/home/test# cat test.py                                          ## 测试程序
#!/usr/bin/python
in_file = open("a.txt", "r")
dict1 = {}
head = 1

for i in in_file:
    if head:
        head -= 1
        continue
    temp = i.strip().split("\t")
    if temp[9].startswith("[") and temp[9].endswith("]"):
        temp = temp[9].lstrip("[").rstrip("]").split(", ")
        for j in range(len(temp)):
            key = temp[j].split('-')[0]
            dict1[key] = temp[j].split('-')[1]
length = 0
for i,j in dict1.items():
    length += ((int(j) - int(i) + 1))
print(length)
root@PC1:/home/test# python test.py                                   ## 运行程序
6624

 

002、方法2

root@PC1:/home/test# cat a.txt                                        ## 测试数据
#chromosome     nc_accession    gene    gene_id ccds_id ccds_status     cds_strand      cds_from        cds_to  cds_locations   match_type
1       NC_000001.8     LINC00115       79854   CCDS1.1 Withdrawn       -       801942  802433  [801942-802433] Identical
1       NC_000001.11    SAMD11  148398  CCDS2.2 Public  +       925941  944152  [925941-926012, 930154-930335, 931038-931088, 935771-935895, 939039-939128, 939274-939459, 941143-941305, 942135-942250, 942409-942487, 942558-943057, 943252-943376, 943697-943807, 943907-944152]       Identical
1       NC_000001.11    NOC2L   26155   CCDS3.1 Public  -       944693  959239  [944693-944799, 945056-945145, 945517-945652, 946172-946285, 946401-946544, 948130-948231, 948489-948602, 951126-951237, 951999-952138, 952411-952599, 953174-953287, 953781-953891, 954003-954081, 955922-956012, 956094-956214, 956893-957024, 957098-957272, 958928-959080, 959214-959239]     Identical
1       NC_000001.11    PLEKHN1 84069   CCDS4.1 Public  +       966531  974574  [966531-966613, 966703-966802, 970276-970422, 970520-970600, 970685-970757, 970878-971005, 971112-971207, 971323-971403, 972074-972149, 972287-972423, 972860-973009, 973185-973325, 973499-973639, 973832-974050, 974315-974363, 974441-974574]  Identical
root@PC1:/home/test# cat test.py                                      ## 测试序列
#!/usr/bin/pyton

in_file = open("a.txt", "r")
list1 = list()
list2 = list()

lines = in_file.readlines()[1:]

for i in lines:
    i = i.strip().split("\t")
    if i[9].startswith("[") and i[9].endswith("]"):
        temp = i[9].replace("[", "").replace("]", "").split(", ")
        for j in temp:
            list1.append(j.split("-")[0])
            list2.append(j.split("-")[1])
length = 0
for i in range(len(list1)):
    length += (int(list2[i]) - int(list1[i]) +1)
print(length)

in_file.close()
root@PC1:/home/test# python test.py     ## 执行程序
6624

 

 

003、shell验证

root@PC1:/home/test# awk -F "\t" '{print $10}' a.txt | sed 1d | sed 's/\[\|\]//g' | sed 's/, /\n/g' | awk -F "-" '{sum += ($2 - $1 + 1)} END {print sum}'
6624

 

参考:https://www.jianshu.com/p/a7b20c2af042

 

标签:Identical,temp,外显子,python,PC1,基因组,cds,test,home
From: https://www.cnblogs.com/liujiaxin2018/p/16593382.html

相关文章

  • Python3项目初始化5-->面向对象
    18、面向对象--类和实例属性创建一个类classPerSon(object):  def__init__(self,name,age):    self.name=name    self.age=age  def......
  • python带你实现任意下载AcFun视频数据~
    前言......
  • Codility CountBoundedSlices Python
    捣鼓了挺久总算整出一个可行解点击查看代码classQueue(object):def__init__(self):super(Queue,self).__init__()self.max_index=-1......
  • 学习:python 文件的读写
    文件作用文件把一些数据存放起来,可以让程序下一次执行的时候直接使用,而不必重新制作一份,省时省力。文件读写也称为IO流,分为读文件和写文件两个方法读文件Inputstream......
  • 学习python-Day40
    今日学习内容约束条件主键单纯从约束角度上主键等价于非空唯一notnull、uniquecreatetablet1( idintprimarykey, namevarchar(32));mysql>desct......
  • python 中 如何提取或者删除列表的最后几个元素(适用于元组、字符串序列)
     001、>>>test=["a","b","c","d","e","f","g","h","i","j"]##测试列表>>>test['a','b','c'......
  • python不输出warning信息和多线程
    python 不输出warning信息 加入-Wignore参数Python -Wignore XXX.pyPython多线程1同一函数执行多线程,使用apply_async函数参考https://www.cnblogs.com/ai......
  • python-map()函数基本用法
    最近经常遇到一个问题:输入端在同一行输入两个整型数字,并用空格间隔,问如何方便快捷的将这两个变量分别赋予给x1,x2?新手小白,由于不知道map()函数的用法,便想要用仅有的知识去解......
  • python 爬虫
    1.手写第一个python爬虫#爬虫:用程序来获取网站上的资源#常用encoding='utf-8'encoding='gbk'#1.导入urllib.requesturlopen第三方库fromurllib.requ......
  • python数据结构学习整理-集合
    """集合的定义-无序的唯一对象集合-用大括号{}包围,对象相互之间使用逗号分隔-集合是动态的,可以随时添加或删除元素-集合是异构的,可以包含不同类型的数据"""集合的使......