{ "data": { "question": { "questionId": "3816", "questionFrontendId": "3475", "categoryTitle": "Database", "boundTopicId": 3593036, "title": "DNA Pattern Recognition ", "titleSlug": "dna-pattern-recognition", "content": "
Table: Samples
\n+----------------+---------+\n| Column Name | Type | \n+----------------+---------+\n| sample_id | int |\n| dna_sequence | varchar |\n| species | varchar |\n+----------------+---------+\nsample_id is the unique key for this table.\nEach row contains a DNA sequence represented as a string of characters (A, T, G, C) and the species it was collected from.\n\n\n
Biologists are studying basic patterns in DNA sequences. Write a solution to identify sample_id
with the following patterns:
3
consecutive G (like GGG or GGGG)Return the result table ordered by sample_id in ascending order.
\n\nThe result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\nSamples table:
\n\n\n+-----------+------------------+-----------+\n| sample_id | dna_sequence | species |\n+-----------+------------------+-----------+\n| 1 | ATGCTAGCTAGCTAA | Human |\n| 2 | GGGTCAATCATC | Human |\n| 3 | ATATATCGTAGCTA | Human |\n| 4 | ATGGGGTCATCATAA | Mouse |\n| 5 | TCAGTCAGTCAG | Mouse |\n| 6 | ATATCGCGCTAG | Zebrafish |\n| 7 | CGTATGCGTCGTA | Zebrafish |\n+-----------+------------------+-----------+\n\n\n
Output:
\n\n\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n| sample_id | dna_sequence | species | has_start | has_stop | has_atat | has_ggg |\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n| 1 | ATGCTAGCTAGCTAA | Human | 1 | 1 | 0 | 0 |\n| 2 | GGGTCAATCATC | Human | 0 | 0 | 0 | 1 |\n| 3 | ATATATCGTAGCTA | Human | 0 | 0 | 1 | 0 |\n| 4 | ATGGGGTCATCATAA | Mouse | 1 | 1 | 0 | 1 |\n| 5 | TCAGTCAGTCAG | Mouse | 0 | 0 | 0 | 0 |\n| 6 | ATATCGCGCTAG | Zebrafish | 0 | 1 | 1 | 0 |\n| 7 | CGTATGCGTCGTA | Zebrafish | 0 | 0 | 0 | 0 |\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n\n\n
Explanation:
\n\nNote:
\n\n表:Samples
\n+----------------+---------+\n| Column Name | Type | \n+----------------+---------+\n| sample_id | int |\n| dna_sequence | varchar |\n| species | varchar |\n+----------------+---------+\nsample_id 是这张表的唯一主键。\n每一行包含一个 DNA 序列以一个字符(A,T,G,C)组成的字符串表示以及它所采集自的物种。\n\n\n
生物学家正在研究 DNA 序列中的基本模式。编写一个解决方案以识别具有以下模式的 sample_id
:
3
个连续 G 的序列(如 GGG 或 GGGG)返回结果表以 sample_id 升序 排序。
\n\n结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\nSamples 表:
\n\n\n+-----------+------------------+-----------+\n| sample_id | dna_sequence | species |\n+-----------+------------------+-----------+\n| 1 | ATGCTAGCTAGCTAA | Human |\n| 2 | GGGTCAATCATC | Human |\n| 3 | ATATATCGTAGCTA | Human |\n| 4 | ATGGGGTCATCATAA | Mouse |\n| 5 | TCAGTCAGTCAG | Mouse |\n| 6 | ATATCGCGCTAG | Zebrafish |\n| 7 | CGTATGCGTCGTA | Zebrafish |\n+-----------+------------------+-----------+\n\n\n
输出:
\n\n\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n| sample_id | dna_sequence | species | has_start | has_stop | has_atat | has_ggg |\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n| 1 | ATGCTAGCTAGCTAA | Human | 1 | 1 | 0 | 0 |\n| 2 | GGGTCAATCATC | Human | 0 | 0 | 0 | 1 |\n| 3 | ATATATCGTAGCTA | Human | 0 | 0 | 1 | 0 |\n| 4 | ATGGGGTCATCATAA | Mouse | 1 | 1 | 0 | 1 |\n| 5 | TCAGTCAGTCAG | Mouse | 0 | 0 | 0 | 0 |\n| 6 | ATATCGCGCTAG | Zebrafish | 0 | 1 | 1 | 0 |\n| 7 | CGTATGCGTCGTA | Zebrafish | 0 | 0 | 0 | 0 |\n+-----------+------------------+-------------+-------------+------------+------------+------------+\n\n\n
解释:
\n\n注意:
\n\n\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Samples\":[\"sample_id\",\"dna_sequence\",\"species\"]},\"rows\":{\"Samples\":[[1,\"ATGCTAGCTAGCTAA\",\"Human\"],[2,\"GGGTCAATCATC\",\"Human\"],[3,\"ATATATCGTAGCTA\",\"Human\"],[4,\"ATGGGGTCATCATAA\",\"Mouse\"],[5,\"TCAGTCAGTCAG\",\"Mouse\"],[6,\"ATATCGCGCTAG\",\"Zebrafish\"],[7,\"CGTATGCGTCGTA\",\"Zebrafish\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"