-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RNA Seq normalization methods #136
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6e566e
add empty test
ScheidTo a967c53
rename file ending
ScheidTo 7a3c992
tpkm & rpkm + tests
ScheidTo 2b906ea
with record type
ScheidTo b40fa7a
input as record types
ScheidTo ce12904
Added XML tags
ScheidTo a5382ff
modified axis labelling
ScheidTo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule BioFSharp
added at
92be7c
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,5 @@ | ||
#load "../RNASeq.fs" | ||
open BioFSharp | ||
open BioFSharp.Stats | ||
open BioFSharp.Stats.RNASeq | ||
|
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,71 @@ | ||
namespace BioFSharp.Stats | ||
|
||
open System | ||
open System.Collections.Generic | ||
|
||
/// Contains types and functions needed for RNA-Seq normalization | ||
module RNASeq = | ||
/// Input type for RNA-Seq normalization | ||
type RNASeqInput = { | ||
GeneID : string | ||
GeneLength : float | ||
GeneCount : float | ||
} with static member Create id gl gc = {GeneID=id;GeneLength=gl;GeneCount=gc} | ||
type NormalizationMethod = | ||
| RPKM | ||
| TPM | ||
/// Type with GeneID, normalized data and method of normalization | ||
type NormalizedCounts = { | ||
GeneID : string | ||
NormalizedCount : float | ||
NormalizationMethod: NormalizationMethod | ||
} with static member Create id nc nm = {GeneID=id;NormalizedCount=nc;NormalizationMethod=nm} | ||
/// calculates Reads Per Million | ||
let private calcRPM sumOfAllReadsPerMil counts = | ||
(counts |> float) / sumOfAllReadsPerMil | ||
/// calculates RPKM | ||
let private calcRPKM geneLength rpm = | ||
(float rpm) / ((float geneLength) / 1000.) | ||
///Performs RPKM normalization | ||
let private rpkmsOf (geneIDs:seq<string>) (length:seq<float>) (counts:seq<float>) = | ||
let sumOfAllReads = | ||
counts | ||
|> Seq.sum | ||
let sumOfAllReadsPerMil = | ||
sumOfAllReads / 1000000. | ||
let rpms = | ||
Seq.map (fun counts -> calcRPM sumOfAllReadsPerMil counts) counts | ||
let rpkms = | ||
let rpkm = | ||
Seq.zip length rpms | ||
|> Seq.map (fun (length, rpm) -> calcRPKM length rpm) | ||
rpkm | ||
let rpkmResult = | ||
Seq.map2 (fun ids counts -> {GeneID=ids; NormalizedCount=counts; NormalizationMethod=RPKM}) geneIDs rpkms | ||
rpkmResult | ||
/// Returns RPKM normalized data | ||
let rpkms (idLengthAndCounts:seq<RNASeqInput>) = | ||
rpkmsOf (idLengthAndCounts |> Seq.map (fun x -> x.GeneID)) (idLengthAndCounts |> Seq.map (fun x -> x.GeneLength)) (idLengthAndCounts |> Seq.map (fun x -> x.GeneCount)) | ||
/// Performs TPM normalization | ||
let private tpmsOf (idLengthAndCounts:seq<RNASeqInput>) = | ||
let rpk = | ||
idLengthAndCounts | ||
|> Seq.map (fun idLengthAndCounts -> idLengthAndCounts.GeneCount/idLengthAndCounts.GeneLength/1000.) | ||
let sumOfAllReads = | ||
rpk | ||
|> Seq.sum | ||
let sumOfAllReadsPerMil = | ||
sumOfAllReads / 1000000. | ||
let tpms = | ||
rpk | ||
|> Seq.map (fun rpks -> rpks/sumOfAllReadsPerMil) | ||
let geneID = | ||
idLengthAndCounts | ||
|> Seq.map (fun idLengthAndCounts -> idLengthAndCounts.GeneID) | ||
let tpmResult = | ||
Seq.map2 (fun ids counts -> {GeneID=ids; NormalizedCount=counts; NormalizationMethod=TPM}) geneID tpms | ||
tpmResult | ||
/// Returns TPM normalized data | ||
let tpms (idLengthAndCounts:seq<RNASeqInput>) = | ||
tpmsOf idLengthAndCounts | ||
|
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,37 @@ | ||
module RNASeqTests | ||
|
||
open BioFSharp.Stats | ||
open Expecto | ||
|
||
|
||
let testSeq = seq { for i in 1. .. 2. -> ("stringtest"+ i.ToString(),(i,i))} | ||
let testgeneID = seq { "stringtest1"; "stringtest2"} | ||
let testLength = seq {1.; 2.} | ||
let testCount = seq {1.;2.} | ||
let testInSeq = Seq.map3 (fun id gl gc -> RNASeq.RNASeqInput.Create id gl gc) testgeneID testLength testCount | ||
|
||
let resultRPKM= seq {("stringtest1", 333333333.3333333); ("stringtest2",333333333.3333333)} | ||
let resultTPM= seq {("stringtest1", 500000.); ("stringtest2", 500000.)} | ||
let RPKMres = Seq.map (fun (id,rpkm) -> RNASeq.NormalizedCounts.Create id rpkm RNASeq.NormalizationMethod.RPKM) resultRPKM | ||
let TPMres = Seq.map (fun (id,tpm) -> RNASeq.NormalizedCounts.Create id tpm RNASeq.NormalizationMethod.TPM) resultTPM | ||
[<Tests>] | ||
let RNASeqTests = | ||
|
||
testList "RNASeqTests" [ | ||
testCase "RPKM" (fun _ -> | ||
Expect.sequenceEqual | ||
(RNASeq.rpkms testInSeq) | ||
//|> Array.ofSeq) | ||
(RPKMres) | ||
//|> Array.ofSeq) | ||
"RPKM did not return correct Sequence" | ||
) | ||
testCase "TPM" (fun _ -> | ||
Expect.sequenceEqual | ||
(RNASeq.tpms testInSeq) | ||
//|> Array.ofSeq) | ||
(TPMres) | ||
//|> Array.ofSeq) | ||
"TPM did not return correct Sequence" | ||
) | ||
] |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least the public functions and types should have XML documentation to give context about what they do without the need of browsing the documentation page.