readalignment.proto 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Copyright 2016 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.genomics.v1;
  16. import "google/api/annotations.proto";
  17. import "google/genomics/v1/cigar.proto";
  18. import "google/genomics/v1/position.proto";
  19. import "google/protobuf/struct.proto";
  20. option cc_enable_arenas = true;
  21. option java_multiple_files = true;
  22. option java_outer_classname = "ReadAlignmentProto";
  23. option java_package = "com.google.genomics.v1";
  24. // A linear alignment can be represented by one CIGAR string. Describes the
  25. // mapped position and local alignment of the read to the reference.
  26. message LinearAlignment {
  27. // The position of this alignment.
  28. Position position = 1;
  29. // The mapping quality of this alignment. Represents how likely
  30. // the read maps to this position as opposed to other locations.
  31. //
  32. // Specifically, this is -10 log10 Pr(mapping position is wrong), rounded to
  33. // the nearest integer.
  34. int32 mapping_quality = 2;
  35. // Represents the local alignment of this sequence (alignment matches, indels,
  36. // etc) against the reference.
  37. repeated CigarUnit cigar = 3;
  38. }
  39. // A read alignment describes a linear alignment of a string of DNA to a
  40. // [reference sequence][google.genomics.v1.Reference], in addition to metadata
  41. // about the fragment (the molecule of DNA sequenced) and the read (the bases
  42. // which were read by the sequencer). A read is equivalent to a line in a SAM
  43. // file. A read belongs to exactly one read group and exactly one
  44. // [read group set][google.genomics.v1.ReadGroupSet].
  45. //
  46. // For more genomics resource definitions, see [Fundamentals of Google
  47. // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics)
  48. //
  49. // ### Reverse-stranded reads
  50. //
  51. // Mapped reads (reads having a non-null `alignment`) can be aligned to either
  52. // the forward or the reverse strand of their associated reference. Strandedness
  53. // of a mapped read is encoded by `alignment.position.reverseStrand`.
  54. //
  55. // If we consider the reference to be a forward-stranded coordinate space of
  56. // `[0, reference.length)` with `0` as the left-most position and
  57. // `reference.length` as the right-most position, reads are always aligned left
  58. // to right. That is, `alignment.position.position` always refers to the
  59. // left-most reference coordinate and `alignment.cigar` describes the alignment
  60. // of this read to the reference from left to right. All per-base fields such as
  61. // `alignedSequence` and `alignedQuality` share this same left-to-right
  62. // orientation; this is true of reads which are aligned to either strand. For
  63. // reverse-stranded reads, this means that `alignedSequence` is the reverse
  64. // complement of the bases that were originally reported by the sequencing
  65. // machine.
  66. //
  67. // ### Generating a reference-aligned sequence string
  68. //
  69. // When interacting with mapped reads, it's often useful to produce a string
  70. // representing the local alignment of the read to reference. The following
  71. // pseudocode demonstrates one way of doing this:
  72. //
  73. // out = ""
  74. // offset = 0
  75. // for c in read.alignment.cigar {
  76. // switch c.operation {
  77. // case "ALIGNMENT_MATCH", "SEQUENCE_MATCH", "SEQUENCE_MISMATCH":
  78. // out += read.alignedSequence[offset:offset+c.operationLength]
  79. // offset += c.operationLength
  80. // break
  81. // case "CLIP_SOFT", "INSERT":
  82. // offset += c.operationLength
  83. // break
  84. // case "PAD":
  85. // out += repeat("*", c.operationLength)
  86. // break
  87. // case "DELETE":
  88. // out += repeat("-", c.operationLength)
  89. // break
  90. // case "SKIP":
  91. // out += repeat(" ", c.operationLength)
  92. // break
  93. // case "CLIP_HARD":
  94. // break
  95. // }
  96. // }
  97. // return out
  98. //
  99. // ### Converting to SAM's CIGAR string
  100. //
  101. // The following pseudocode generates a SAM CIGAR string from the
  102. // `cigar` field. Note that this is a lossy conversion
  103. // (`cigar.referenceSequence` is lost).
  104. //
  105. // cigarMap = {
  106. // "ALIGNMENT_MATCH": "M",
  107. // "INSERT": "I",
  108. // "DELETE": "D",
  109. // "SKIP": "N",
  110. // "CLIP_SOFT": "S",
  111. // "CLIP_HARD": "H",
  112. // "PAD": "P",
  113. // "SEQUENCE_MATCH": "=",
  114. // "SEQUENCE_MISMATCH": "X",
  115. // }
  116. // cigarStr = ""
  117. // for c in read.alignment.cigar {
  118. // cigarStr += c.operationLength + cigarMap[c.operation]
  119. // }
  120. // return cigarStr
  121. message Read {
  122. // The server-generated read ID, unique across all reads. This is different
  123. // from the `fragmentName`.
  124. string id = 1;
  125. // The ID of the read group this read belongs to. A read belongs to exactly
  126. // one read group. This is a server-generated ID which is distinct from SAM's
  127. // RG tag (for that value, see
  128. // [ReadGroup.name][google.genomics.v1.ReadGroup.name]).
  129. string read_group_id = 2;
  130. // The ID of the read group set this read belongs to. A read belongs to
  131. // exactly one read group set.
  132. string read_group_set_id = 3;
  133. // The fragment name. Equivalent to QNAME (query template name) in SAM.
  134. string fragment_name = 4;
  135. // The orientation and the distance between reads from the fragment are
  136. // consistent with the sequencing protocol (SAM flag 0x2).
  137. bool proper_placement = 5;
  138. // The fragment is a PCR or optical duplicate (SAM flag 0x400).
  139. bool duplicate_fragment = 6;
  140. // The observed length of the fragment, equivalent to TLEN in SAM.
  141. int32 fragment_length = 7;
  142. // The read number in sequencing. 0-based and less than numberReads. This
  143. // field replaces SAM flag 0x40 and 0x80.
  144. int32 read_number = 8;
  145. // The number of reads in the fragment (extension to SAM flag 0x1).
  146. int32 number_reads = 9;
  147. // Whether this read did not pass filters, such as platform or vendor quality
  148. // controls (SAM flag 0x200).
  149. bool failed_vendor_quality_checks = 10;
  150. // The linear alignment for this alignment record. This field is null for
  151. // unmapped reads.
  152. LinearAlignment alignment = 11;
  153. // Whether this alignment is secondary. Equivalent to SAM flag 0x100.
  154. // A secondary alignment represents an alternative to the primary alignment
  155. // for this read. Aligners may return secondary alignments if a read can map
  156. // ambiguously to multiple coordinates in the genome. By convention, each read
  157. // has one and only one alignment where both `secondaryAlignment`
  158. // and `supplementaryAlignment` are false.
  159. bool secondary_alignment = 12;
  160. // Whether this alignment is supplementary. Equivalent to SAM flag 0x800.
  161. // Supplementary alignments are used in the representation of a chimeric
  162. // alignment. In a chimeric alignment, a read is split into multiple
  163. // linear alignments that map to different reference contigs. The first
  164. // linear alignment in the read will be designated as the representative
  165. // alignment; the remaining linear alignments will be designated as
  166. // supplementary alignments. These alignments may have different mapping
  167. // quality scores. In each linear alignment in a chimeric alignment, the read
  168. // will be hard clipped. The `alignedSequence` and
  169. // `alignedQuality` fields in the alignment record will only
  170. // represent the bases for its respective linear alignment.
  171. bool supplementary_alignment = 13;
  172. // The bases of the read sequence contained in this alignment record,
  173. // **without CIGAR operations applied** (equivalent to SEQ in SAM).
  174. // `alignedSequence` and `alignedQuality` may be
  175. // shorter than the full read sequence and quality. This will occur if the
  176. // alignment is part of a chimeric alignment, or if the read was trimmed. When
  177. // this occurs, the CIGAR for this read will begin/end with a hard clip
  178. // operator that will indicate the length of the excised sequence.
  179. string aligned_sequence = 14;
  180. // The quality of the read sequence contained in this alignment record
  181. // (equivalent to QUAL in SAM).
  182. // `alignedSequence` and `alignedQuality` may be shorter than the full read
  183. // sequence and quality. This will occur if the alignment is part of a
  184. // chimeric alignment, or if the read was trimmed. When this occurs, the CIGAR
  185. // for this read will begin/end with a hard clip operator that will indicate
  186. // the length of the excised sequence.
  187. repeated int32 aligned_quality = 15;
  188. // The mapping of the primary alignment of the
  189. // `(readNumber+1)%numberReads` read in the fragment. It replaces
  190. // mate position and mate strand in SAM.
  191. Position next_mate_position = 16;
  192. // A map of additional read alignment information. This must be of the form
  193. // map<string, string[]> (string key mapping to a list of string values).
  194. map<string, google.protobuf.ListValue> info = 17;
  195. }