生信算法9 - 正則表達式匹配氨基酸序列、核型和字符串

1. 使用正則表達式匹配指定的氨基酸序列

import re# 氨基酸序列
seq = 'VSVLTMFRYAGWLDRLYMLVGTQLAAIIHGVALPLMMLI'# 正則表達式匹配
match = re.search(r'[A|G]W', seq)# 打印match及匹配到開始位置和結束位置
print(match)
# <re.Match object; span=(10, 12), match='GW'>
print(match.start())
print(match.end())if match:# 打印匹配到氨基酸print(match.group())# GW
else:print("no match!")

2. 使用正則表達式查找全部的氨基酸序列

import reseq = 'RQSAMGSNKSKPKDASQRRRSLEPAENVHGAGGGAFPASQRPSKP'# 匹配R開頭、第二個氨基酸為任意、第三個氨基酸為S或T、第四個氨基酸不為P的連續4個氨基酸徐磊
matches = re.findall(r'R.[ST][^P]', seq)
print(matches)
# ['RQSA', 'RRSL', 'RPSK']# finditer 匹配對象迭代器
match_iter = re.finditer(r'R.[ST][^P]', seq)# 遍歷
for match in match_iter:# 打印group和spanprint(match.group(), match.span())print(match.start(), match.end())# RQSA (0, 4)# 0 4# RRSL (18, 22)# 18 22# RPSK (40, 44)# 40 44

3. 使用正則表達式匹配多個特殊字符,分割字符串

import re# 匹配特殊字符|和;,并分割字符串
annotation = 'ATOM:CA|RES:ALA|CHAIN:B;NUMRES:166'
split_string = re.split(r'[|;]', annotation)print(split_string)
# ['ATOM:CA', 'RES:ALA', 'CHAIN:B', 'NUMRES:166']

4. 正則表達式獲取核型染色體數量,區帶和CNV大小

karyotype1 = '46,XY; -11{p11.2-p13, 48.32Mb}'
karyotype2 = '47,XXX; +X{+3};-11{p11.2-p13.2, 48.32Mb}'#### 匹配染色體數量 ####
match = re.search(r'(\d+,\w+);', karyotype1)
print(match)
# <re.Match object; span=(0, 6), match='46,XY;'>chr = match.group(1)
print(chr)
# 46,XY#### 匹配染色體開始和結束區帶和CNV大小 ####
match2 = re.search(r'([p|q|pter]\d+.?\d+)-([p|q|qter]\d+.?\d+), (\d+.?\d+)Mb', karyotype2)
print(match2)cyto_start = match2.group(1)
cyto_end = match2.group(2)
size = match2.group(3)print(cyto_start)
# p11.2
print(cyto_end)
# p13.2
print(size)
# 48.32

5. 正則表達式獲取指定格式的字符串內容

# 結果變異VCF文件描述信息
string = """##ALT=<ID=DEL,Description="Deletion">##ALT=<ID=DUP,Description="Duplication">##ALT=<ID=INV,Description="Inversion">##ALT=<ID=INVDUP,Description="InvertedDUP with unknown boundaries">##ALT=<ID=TRA,Description="Translocation">##ALT=<ID=INS,Description="Insertion">##FILTER=<ID=UNRESOLVED,Description="An insertion that is longer than the read and thus we cannot predict the full size.">##INFO=<ID=CHR2,Number=1,Type=String,Description="Chromosome for END coordinate in case of a translocation">##INFO=<ID=END,Number=1,Type=Integer,Description="End position of the structural variant">##INFO=<ID=MAPQ,Number=1,Type=Integer,Description="Median mapping quality of paired-ends">##INFO=<ID=RE,Number=1,Type=Integer,Description="read support">##INFO=<ID=IMPRECISE,Number=0,Type=Flag,Description="Imprecise structural variation">##INFO=<ID=PRECISE,Number=0,Type=Flag,Description="Precise structural variation">##INFO=<ID=SVLEN,Number=1,Type=Integer,Description="Length of the SV">##INFO=<ID=SVMETHOD,Number=1,Type=String,Description="Type of approach used to detect SV">##INFO=<ID=SVTYPE,Number=1,Type=String,Description="Type of structural variant">##INFO=<ID=SEQ,Number=1,Type=String,Description="Extracted sequence from the best representative read.">##INFO=<ID=STRANDS2,Number=4,Type=Integer,Description="alt reads first + ,alt reads first -,alt reads second + ,alt reads second -.">##INFO=<ID=REF_strand,Number=.,Type=Integer,Description="plus strand ref, minus strand ref.">##INFO=<ID=Strandbias_pval,Number=A,Type=Float,Description="P-value for fisher exact test for strand bias.">##INFO=<ID=STD_quant_start,Number=A,Type=Float,Description="STD of the start breakpoints across the reads.">##INFO=<ID=STD_quant_stop,Number=A,Type=Float,Description="STD of the stop breakpoints across the reads.">##INFO=<ID=Kurtosis_quant_start,Number=A,Type=Float,Description="Kurtosis value of the start breakpoints across the reads.">##INFO=<ID=Kurtosis_quant_stop,Number=A,Type=Float,Description="Kurtosis value of the stop breakpoints across the reads.">##INFO=<ID=SUPTYPE,Number=.,Type=String,Description="Type by which the variant is supported.(SR,AL,NR)">##INFO=<ID=STRANDS,Number=A,Type=String,Description="Strand orientation of the adjacency in BEDPE format (DEL:+-, DUP:-+, INV:++/--)">##INFO=<ID=AF,Number=A,Type=Float,Description="Allele Frequency.">##INFO=<ID=ZMW,Number=A,Type=Integer,Description="Number of ZMWs (Pacbio) supporting SV.">##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">##FORMAT=<ID=DR,Number=1,Type=Integer,Description="# high-quality reference reads">##FORMAT=<ID=DV,Number=1,Type=Integer,Description="# high-quality variant reads">"""import re# 創建空dataframe
df_output = pd.DataFrame()list_type = []
list_id = []
list_description = []# 遍歷字符串內容,內容拷貝至結構變異VCF文件
for str in string.split('\n'):# 去除末尾\n和字符串內空格str = str.strip().replace(' ', '')# 內容為空或字符串為空則跳過if not str and str == '':continue# 正則表達式匹配##后的英文字符match = re.search(r'##(\w+)', str)type = match.group(1) if match else 'ERORR'# 匹配ID內容match = re.search(r'ID=(\w+)', str)id = match.group(1) if match else 'ERORR'# 匹配Description內容match = re.search(r'Description=\"(.*?)\"', str)description = match.group(1) if match else 'ERORR'# 加入列表list_type.append(type)list_id.append(id)list_description.append(description)print(list_description)
# 加入dataframe
df_output['Type'] = list_type
df_output['ID'] = list_id
df_output['Description'] = list_description# 保存至excel
df_output.to_excel('結構變異描述信息說明.xlsx', index=False)

生信算法文章推薦

生信算法1 - DNA測序算法實踐之序列操作

生信算法2 - DNA測序算法實踐之序列統計

生信算法3 - 基于k-mer算法獲取序列比對索引

生信算法4 - 獲取overlap序列索引和序列的算法

生信算法5 - 序列比對之全局比對算法

生信算法6 - 比對reads堿基數量統計及百分比統計

生信算法7 - 核酸序列Fasta和蛋白PDB文件讀寫與檢索

生信算法8 - HGVS轉換與氨基酸字母表

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/40694.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/40694.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/40694.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

DP學習——觀察者模式

學而時習之&#xff0c;溫故而知新。 2個角色 分為啥主題和觀察者角色。 我覺得主題就是干活的&#xff0c;打工仔&#xff0c;為觀察者干活。 一對多。一個主題&#xff0c;多個觀察者——就像一個開發人員對多個項目經理——項目經理拿小皮鞭抽呀抽呀&#xff0c;受不了。 …

代碼隨想錄算法訓練營第70天圖論9[1]

代碼隨想錄算法訓練營第70天:圖論9 ? 拓撲排序精講 卡碼網&#xff1a;117. 軟件構建(opens new window) 題目描述&#xff1a; 某個大型軟件項目的構建系統擁有 N 個文件&#xff0c;文件編號從 0 到 N - 1&#xff0c;在這些文件中&#xff0c;某些文件依賴于其他文件的…

5款軟件讓電腦更方便,更快,更好看

? 你有沒有想過&#xff0c;有些軟件能讓你的電腦用起來更方便&#xff0c;更快&#xff0c;更好看&#xff1f; 1. 屏幕動畫創作——Screen To Gif ? Screen To Gif是一款功能強大的屏幕錄制軟件&#xff0c;專注于將屏幕上的動態內容轉換為高質量的GIF動畫。它不僅支持自…

《ClipCap》論文筆記(下)

原文出處 [2111.09734] ClipCap: CLIP Prefix for Image Captioning (arxiv.org) 原文翻譯 接上篇 《ClipCap》論文筆記&#xff08;上&#xff09;-CSDN博客 4. Results Datasets.我們使用 COCO-captions [7,22]、nocaps [1] 和 Conceptual Captions [33] 數據集。我們根…

自動化設備上位機設計 一

目錄 一 設計原型 二 后臺代碼 一 設計原型 二 后臺代碼 namespace 自動化上位機設計 {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}} }namespace 自動化上位機設計 {partial class Fo…

Pyqt5中如何讓label里面的圖片進行更換,避免出現黑圖

在Pyqt5的界面開發過程中&#xff0c;發現一個label的圖片怎么都添加不上&#xff0c;而且出現黑色&#xff0c;主要原因就是在進行顯示的時候需要加一行清除的代碼&#xff1a; label.clear()如果不加這行代碼&#xff0c;當里面的圖片發生變化時&#xff0c;顯示出來的就是黑…

miniprogram-to-uniapp-微信小程序轉換成uniapp項目

文章目錄 參考:miniprogram-to-uniapp使用指南第一步第二步第三步第四步【miniprogram-to-uniapp】轉換微信小程序”項目為uni-app項目(新版本工具已經支持各種小程序轉換) 參考: 小程序技能樹 uni-app基礎知識總結 miniprogram-to-uniapp使用指南 第一步 win + R 輸入…

Openwrt路由器部分ipv6公網地址無法訪問的問題

路由器是Openwrt&#xff0c;終端訪問ipv6地址經常有些能訪問&#xff0c;有些不能訪問&#xff0c;一開始以為是運營商問題&#xff0c;后面ssh到openwrt發現所有訪問都正常。 查閱資料后才知道是MTU設置問題&#xff0c;Openwrt 默認MTU是1492&#xff0c;使用IPV6應減少60個…

微信小程序遮罩層顯示

效果展示&#xff1a; wxml頁面&#xff1a; <view classmodal-mask wx:if{{showModal}}><view class"modal-container"><view classmodal-content></view><view classmodal-footer bindtap"closeImage">//這個/images/ind…

Java 基礎查漏補缺

1.深入解讀&#xff1a;JDK與JRE的區別 JDK提供了完整的Java開發工具和資源&#xff0c;包括編譯器、調試器和其他開發工具&#xff0c;滿足開發人員的各種需求。 JRE則相對更為基礎&#xff0c;它只提供了Java程序運行所需的環境&#xff0c;包含了Java虛擬機&#xff08;JVM&…

數字類型<整數、復數>

Python 中&#xff0c;數字類型 Number&#xff0c; 包括整數 int、浮點 float 數和復數 complex 三個子類型。 用來表示程序中不同的數字類型的數據。 整數 整數類型&#xff1a;用來表示整數數值&#xff0c;即沒有小數部分的數值&#xff0c;在 Python 中&#xff0c;沒有…

Nettyの網絡聊天室擴展序列化算法

1、網絡聊天室綜合案例 客戶端初始代碼&#xff1a; Slf4j public class ChatClient {public static void main(String[] args) {NioEventLoopGroup group new NioEventLoopGroup();LoggingHandler LOGGING_HANDLER new LoggingHandler(LogLevel.DEBUG);MessageCodecSharabl…

使用c++函數式編程實現Qt信號槽機制

問題背景 在下面的代碼中&#xff0c;Input輸入器 輸入數據&#xff0c;希望A和B 接收數據。但使用的賦值&#xff0c;導致in.a和a只是拷貝數據&#xff0c;而不是同一個對象&#xff0c;使得數據不同步。 #include <iostream> struct A {int age 32; }; struct B {int …

searchForm自適應布局 + 按鈕插槽

收起 展開 代碼&#xff1a; useResizeObserverHooks.js import { useEffect, useLayoutEffect } from "react";export const useResizeObserver (containerDom, domClass, callback) > {useLayoutEffect(() > {let resizeObserver null;let dom null;if …

Qt Json詳細介紹

一.概念介紹 JSON&#xff08;JavaScript Object Notation&#xff09;是一種輕量級的數據交換格式&#xff0c;常用于前后端數據傳輸和存儲。它具有以下特點&#xff1a; 易讀性&#xff1a;JSON 使用人類可讀的文本格式表示數據&#xff0c;采用鍵值對的方式組織數據&#x…

eth0設備繁忙

當您遇到 ifconfig eth0 hw ether 20:24:07:04:18:00 命令執行后顯示 ifconfig: SIOCSIFHWADDR: Device or resource busy 錯誤時&#xff0c;這意味著您嘗試更改的網絡設備&#xff08;在這個例子中是 eth0&#xff09;目前正被占用&#xff0c;無法進行硬件地址的更改。 為了…

Map Set(Java篇詳解)

&#x1f341; 個人主頁&#xff1a;愛編程的Tom&#x1f4ab; 本篇博文收錄專欄&#xff1a;Java專欄&#x1f449; 目前其它專欄&#xff1a;c系列小游戲 c語言系列--萬物的開始_ 等 &#x1f389; 歡迎 &#x1f44d;點贊?評論?收藏&#x1f496;三連支持…

【每日一練】python列表

1、輸入一個整數列表&#xff0c;將列表中的元素按照逆序輸出。 list1[5,4,5,6] list1.reverse() print(list1)[6, 5, 4, 5]2、輸入一個字符串列表&#xff0c;輸出其中長度大于等于5的字符串&#xff0c;并且將它們轉換為大寫形式。 list1[hello,lol,ak47,aliang] for i in …

211.xv6——3(page tables)

在本實驗室中&#xff0c;您將探索頁表并對其進行修改&#xff0c;以簡化將數據從用戶空間復制到內核空間的函數。 開始編碼之前&#xff0c;請閱讀xv6手冊的第3章和相關文件&#xff1a; kernel/memlayout.h&#xff0c;它捕獲了內存的布局。kernel/vm.c&#xff0c;其中包含…

代謝組數據分析(十二):嶺回歸、Lasso回歸、彈性網絡回歸構建預測模型

歡迎大家關注全網生信學習者系列: WX公zhong號:生信學習者Xiao hong書:生信學習者知hu:生信學習者CDSN:生信學習者2介紹 在代謝物預測模型的構建中,我們采用了三種主流的回歸分析方法:嶺回歸、Lasso回歸以及彈性網絡回歸。這三種方法各有其獨特的原理和適用場景,因此在…