-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2d5d8db
Showing
9 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
67 changes: 67 additions & 0 deletions
67
.swiftpm/xcode/xcshareddata/xcschemes/Nucleotide-test.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1340" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Nucleotide" | ||
BuildableName = "Nucleotide" | ||
BlueprintName = "Nucleotide" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Nucleotide" | ||
BuildableName = "Nucleotide" | ||
BlueprintName = "Nucleotide" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1340" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Nucleotide" | ||
BuildableName = "Nucleotide" | ||
BlueprintName = "Nucleotide" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "NucleotideTests" | ||
BuildableName = "NucleotideTests" | ||
BlueprintName = "NucleotideTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "NucleotideTests" | ||
BuildableName = "NucleotideTests" | ||
BlueprintName = "NucleotideTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Nucleotide" | ||
BuildableName = "Nucleotide" | ||
BlueprintName = "Nucleotide" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 RedRimmedBox | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// swift-tools-version: 5.6 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Nucleotide", | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "Nucleotide", | ||
targets: ["Nucleotide"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "Nucleotide", | ||
dependencies: []), | ||
.testTarget( | ||
name: "NucleotideTests", | ||
dependencies: ["Nucleotide"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Nucleotide | ||
|
||
現在開発中です. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// Nucreotide.swift | ||
// | ||
// | ||
// Created by rrbox on 2022/08/13. | ||
// | ||
|
||
public struct Nucleotide: OptionSet { | ||
public var rawValue: UInt8 | ||
public init(rawValue: UInt8) { | ||
self.rawValue = rawValue | ||
} | ||
} | ||
|
||
extension Nucleotide { | ||
static let a = Self.init(rawValue: 0b11) | ||
static let c = Self.init(rawValue: 0b11 << 2) | ||
static let g = Self.init(rawValue: 0b11 << 4) | ||
static let t = Self.init(rawValue: 0b11 << 6) | ||
static let u = Self.init(rawValue: 0b11 << 6) | ||
} | ||
|
||
// fasta 形式 | ||
extension Nucleotide { | ||
static let r: Self = [.a, .g] | ||
static let y: Self = [.t, .c] | ||
static let k: Self = [.g, .t] | ||
static let m: Self = [.a, .c] | ||
} | ||
|
||
extension Nucleotide { | ||
static let s: Self = [.g, .c] | ||
static let w: Self = [.a, .t] | ||
} | ||
|
||
extension Nucleotide { | ||
static let b: Self = [.g, .t, .c] | ||
static let d: Self = [.g, .a, .t] | ||
static let h: Self = [.a, .c, .t] | ||
static let v: Self = [.g, .c, .a] | ||
} | ||
|
||
extension Nucleotide { | ||
static let n: Self = [.a, .g, .c, .t] | ||
static let gap: Self = .init(rawValue: 0) | ||
} | ||
|
||
public protocol BaseType { | ||
static var unicodeToBaseDict: [UnicodeScalar: Nucleotide] { get } | ||
static var baseToUnicodeDict: [UInt8: UnicodeScalar] { get } | ||
} | ||
|
||
extension BaseType { | ||
static func unicodeConvertToBase(_ unicode: UnicodeScalar) -> Nucleotide? { | ||
return Self.unicodeToBaseDict[unicode] | ||
} | ||
|
||
static func baseConvertToUnicode(_ base: Nucleotide) -> UnicodeScalar? { | ||
return Self.baseToUnicodeDict[base.rawValue] | ||
} | ||
} | ||
|
||
|
||
public enum DNA: BaseType { | ||
public static let unicodeToBaseDict: [UnicodeScalar: Nucleotide] = [ | ||
"A": .a, | ||
"C": .c, | ||
"G": .g, | ||
"T": .t, | ||
] | ||
|
||
public static let baseToUnicodeDict: [UInt8: UnicodeScalar] = [ | ||
Nucleotide.a.rawValue: "A", | ||
Nucleotide.t.rawValue: "T", | ||
Nucleotide.c.rawValue: "C", | ||
Nucleotide.g.rawValue: "G", | ||
] | ||
|
||
} | ||
|
||
public enum RNA: BaseType { | ||
public static let unicodeToBaseDict: [UnicodeScalar: Nucleotide] = [ | ||
"A": .a, | ||
"C": .c, | ||
"G": .g, | ||
"U": .u, | ||
] | ||
|
||
public static let baseToUnicodeDict: [UInt8: UnicodeScalar] = [ | ||
Nucleotide.a.rawValue: "A", | ||
Nucleotide.u.rawValue: "U", | ||
Nucleotide.c.rawValue: "C", | ||
Nucleotide.g.rawValue: "G", | ||
] | ||
|
||
} | ||
|
||
public struct BaseSequence<T: BaseType>: ExpressibleByStringLiteral, CustomStringConvertible { | ||
var sequence: [UInt8] | ||
|
||
public init(stringLiteral value: StringLiteralType) { | ||
self.sequence = value.unicodeScalars.reduce(into: []) { partialResult, s in | ||
partialResult.append(T.unicodeConvertToBase(s)!.rawValue) | ||
} | ||
} | ||
|
||
public var description: String { | ||
"\(T.self): \(self.sequence.reduce(into: "") {$0 += String(T.baseConvertToUnicode(Nucleotide(rawValue: $1))!)})" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import XCTest | ||
@testable import Nucleotide | ||
|
||
extension String { | ||
subscript(at: Int) -> Character { self[self.index(self.startIndex, offsetBy: at)] } | ||
} | ||
|
||
final class NucleotideTests: XCTestCase { | ||
var seq: BaseSequence<DNA>? | ||
override func setUp() async throws { | ||
|
||
} | ||
|
||
// 文字列をプログラミング内の配列データに変換する際にかかる時間を計測 | ||
func testStringToSeqData() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
|
||
// 1000万塩基分の文字列を変換する時間を計測します. | ||
self.measure { | ||
self.seq = .init(stringLiteral: String(repeating: "A", count: 10000000)) | ||
} | ||
// 計測結果 | ||
// 10万塩基: 0.009 sec | ||
// 100万塩基: 0.063 sec | ||
// 1000万塩基: 0.611 sec | ||
// 1億塩基: 6.140 sec | ||
|
||
// 予想 | ||
// 10億塩基: 1 min | ||
// 30億塩基: 3 min | ||
|
||
} | ||
} |