人类基因组本地化及简单分析

在NCBI上下载 GRCh38

wget ftp://ftp.ncbi.nlm.nih.gov/refseq/H_sapiens/annotation/GRCh38_latest/refseq_identifiers/GRCh38_latest_genomic.fna.gz

解压文件(.fasta, .fa, .fna, .fsa, .mpfa)

gzip  -d GRCh38_latest_genomic.fna.gz
#人的h38基因组是3G的大小,一个英文字符是一个字节,所以30亿bp的碱基就是3G左右
head GRCh38_latest_genomic.fna

这里写图片描述
查看该文件可以看到,里面有很多的N,这是基因组里面未知的序列,用N占位,但是觉得部分都是A.T.C.G这样的字符,大小写都有,分别代表不同的意思


统计了一下里面这个文件的行数

time wc -l GRCh38_latest_genomic.fna

这里写图片描述


用awk统计行数(效率相比wc –l 慢)

time awk 'END { print NR }' GRCh38_latest_genomic.fna

这里写图片描述


看一下标题行

grep '>' GRCh38_latest_genomic.fna | sed -n 'p'
grep '>' GRCh38_latest_genomic.fna | sed -n 'p' >> list.txt

统计每个标题下基因片段的长度,提取标题和长度写入一个新文件

time python GECh38_title_length.py
fasta_file=open('/home/sunchengquan/GRCh38_latest_genomic.fna','r')
out_file = open('GRCh38_title_length.txt','w')
seq = ''
i = 0
for line in fasta_file:
    if line[0] == '>' and seq == '':
        header = line.strip()
    elif line[0] != '>':
        seq =seq + line.strip()
    elif line[0] == '>' and seq != '':
        num = len(seq)
        out_file.write(header +'\n'+ str(num)+ '\n')
        i += 1
        print('writing:',i)
        seq = ''
        header = line.strip()
 out_file.close()


看一下GRCh38_title_length.txt里面的内容

这里写图片描述


提取标题行,添加到列表,并打印

time python GECh38_title.py
input_file=open("/home/sunchengquan/GRCh38_latest_genomic.fna","r")
title_list = []
for line in input_file:
    if line[0] == '>':
        field = line
        title_list.append(field)
        print(field)
类似于
grep '>' GRCh38_latest_genomic.fna | sed -n 'p' > list.txt


这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值