Skip to content
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

Transcriptomics Digestion and Fragmentation #801

Merged
merged 19 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mzLib/Chemistry/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static double ToMass(this double massToChargeRatio, int charge)
return Math.Abs(charge) * massToChargeRatio - charge * Constants.ProtonMass;
}

public static double? RoundedDouble(this double myNumber, int places = 9) => RoundedDouble(myNumber as double?, places);
public static double? RoundedDouble(this double? myNumber, int places = 9)
{
if (myNumber != null)
Expand Down
5 changes: 5 additions & 0 deletions mzLib/MassSpectrometry/Enums/DissociationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public enum DissociationType
/// </summary>
LowCID,

/// <summary>
/// activated ion electron photo detachment dissociation
/// </summary>
aEPD,

Unknown,
AnyActivationType,
Custom,
Expand Down
19 changes: 6 additions & 13 deletions mzLib/Omics/Fragmentation/FragmentationTerminus.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Omics.Fragmentation
namespace Omics.Fragmentation
{
public enum FragmentationTerminus
{
Both, //N- and C-terminus
N, //N-terminus only
C, //C-terminus only
{
Both, //N- and C-terminus
N, //N-terminus only
C, //C-terminus only
None, //used for internal fragments, could be used for top down intact mass?
FivePrime, // 5' for NucleicAcids
ThreePrime, // 3' for NucleicAcids
}

}
}
259 changes: 258 additions & 1 deletion mzLib/Omics/Fragmentation/Oligo/DissociationTypeCollection.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions mzLib/Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@
</None>
<None Update="FileReadingTests\SearchResults\VariantCrossTest.psmtsv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Transcriptomics\TestData\ModomicsUnmodifiedTrimmed.fasta">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Transcriptomics\TestData\ModomicsUnmodifiedTrimmed.fasta.gz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="DataFiles\centroid_1x_MS1_4x_autoMS2.d\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
>id:1|Name:tdbR00000010|SOterm:SO:0000254|Type:tRNA|Subtype:Ala|Feature:VGC|Cellular_Localization:prokaryotic cytosol|Species:Escherichia coli
GGGGCUAUAGCUCAGCUGGGAGAGCGCCUGCUUUGCACGCAGGAGGUCUGCGGUUCGAUCCCGCAUAGCUCCACCA
>id:2|Name:tdbR00000008|SOterm:SO:0000254|Type:tRNA|Subtype:Ala|Feature:GGC|Cellular_Localization:prokaryotic cytosol|Species:Escherichia coli
GGGGCUAUAGCUCAGCUGGGAGAGCGCUUGCAUGGCAUGCAAGAGGUCAGCGGUUCGAUCCCGCUUAGCUCCACCA
>id:3|Name:tdbR00000356|SOterm:SO:0001036|Type:tRNA|Subtype:Arg|Feature:ICG|Cellular_Localization:prokaryotic cytosol|Species:Escherichia coli
GCAUCCGUAGCUCAGCUGGAUAGAGUACUCGGCUACGAACCGAGCGGUCGGAGGUUCGAAUCCUCCCGGAUGCACCA
>id:4|Name:tdbR00000359|SOterm:SO:0001036|Type:tRNA|Subtype:Arg|Feature:CCG|Cellular_Localization:prokaryotic cytosol|Species:Escherichia coli
GCGCCCGUAGCUCAGCUGGAUAGAGCGCUGCCCUCCGGAGGCAGAGGUCUCAGGUUCGAAUCCUGUCGGGCGCGCCA
>id:5|Name:tdbR00000358|SOterm:SO:0001036|Type:tRNA|Subtype:Arg|Feature:UCU|Cellular_Localization:prokaryotic cytosol|Species:Escherichia coli
GCGCCCUUAGCUCAGUUGGAUAGAGCAACGACCUUCUAAGUCGUGGGCCGCAGGUUCGAAUCCUGCAGGGCGCGCCA
Binary file not shown.
149 changes: 149 additions & 0 deletions mzLib/Test/Transcriptomics/TestDbLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using NUnit.Framework;
using Omics.Modifications;
using System;
using System.Collections.Generic;
trishorts marked this conversation as resolved.
Show resolved Hide resolved
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UsefulProteomicsDatabases.Transcriptomics;
using UsefulProteomicsDatabases;
using Transcriptomics;

namespace Test.Transcriptomics
{
[TestFixture]
[ExcludeFromCodeCoverage]
internal class TestDbLoader
{
public static string ModomicsUnmodifedFastaPath => Path.Combine(TestContext.CurrentContext.TestDirectory,
"Transcriptomics/TestData/ModomicsUnmodifiedTrimmed.fasta");

/// <summary>
/// Detect the headertype of the test cases
/// </summary>
private static IEnumerable<(string, RnaFastaHeaderType)> DetectHeaderTestCases =>
new List<(string, RnaFastaHeaderType)>
{
(Path.Combine(TestContext.CurrentContext.TestDirectory, "DoubleProtease.tsv"), RnaFastaHeaderType.Unknown),
(ModomicsUnmodifedFastaPath, RnaFastaHeaderType.Modomics),
(Path.Combine(TestContext.CurrentContext.TestDirectory, "Transcriptomics/TestData/ModomicsUnmodifiedTrimmed.fasta"), RnaFastaHeaderType.Modomics),

};

/// <summary>
/// Test the correctness of checking headertype
/// </summary>
/// <param name="testData"></param>
[Test]
[TestCaseSource(nameof(DetectHeaderTestCases))]
public static void TestDetectHeaderType((string dbPath, RnaFastaHeaderType headerType) testData)
{
string line = File.ReadLines(testData.dbPath).First();
if (char.IsDigit(line.First()))
{
line = File.ReadLines(testData.dbPath).Skip(1).First();
}
var type = RnaDbLoader.DetectRnaFastaHeaderType(line);
Assert.That(testData.headerType, Is.EqualTo(type));
}


[Test]
[TestCase("ModomicsUnmodifiedTrimmed.fasta")]
[TestCase("ModomicsUnmodifiedTrimmed.fasta.gz")]
public static void TestModomicsUnmodifiedFasta(string databaseFileName)
{
var dbPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Transcriptomics", "TestData",
databaseFileName);
var oligos = RnaDbLoader.LoadRnaFasta(dbPath, true, DecoyType.None, false,
out var errors);
Assert.That(errors.Count, Is.EqualTo(0));
Assert.That(oligos.Count, Is.EqualTo(5));
Assert.That(oligos.First().BaseSequence,
Is.EqualTo("GGGGCUAUAGCUCAGCUGGGAGAGCGCCUGCUUUGCACGCAGGAGGUCUGCGGUUCGAUCCCGCAUAGCUCCACCA"));
Assert.That(oligos.First().Name, Is.EqualTo("tdbR00000010"));
Assert.That(oligos.First().Accession, Is.EqualTo("SO:0000254"));
Assert.That(oligos.First().Organism, Is.EqualTo("Escherichia coli"));
Assert.That(oligos.First().DatabaseFilePath, Is.EqualTo(dbPath));
Assert.That(oligos.First().IsContaminant, Is.False);
Assert.That(oligos.First().IsDecoy, Is.False);
Assert.That(oligos.First().AdditionalDatabaseFields!.Count, Is.EqualTo(5));
Assert.That(oligos.First().AdditionalDatabaseFields!["Id"], Is.EqualTo("1"));
Assert.That(oligos.First().AdditionalDatabaseFields!["Type"], Is.EqualTo("tRNA"));
Assert.That(oligos.First().AdditionalDatabaseFields!["Subtype"], Is.EqualTo("Ala"));
Assert.That(oligos.First().AdditionalDatabaseFields!["Feature"], Is.EqualTo("VGC"));
Assert.That(oligos.First().AdditionalDatabaseFields!["Cellular Localization"], Is.EqualTo("prokaryotic cytosol"));
}

[Test]
public static void TestContaminantFollowsThrough()
{
var oligos = RnaDbLoader.LoadRnaFasta(ModomicsUnmodifedFastaPath, true, DecoyType.None, true,
out var errors);
Assert.That(errors.Count, Is.EqualTo(0));
Assert.That(oligos.Count, Is.EqualTo(5));
Assert.That(oligos.First().BaseSequence,
Is.EqualTo("GGGGCUAUAGCUCAGCUGGGAGAGCGCCUGCUUUGCACGCAGGAGGUCUGCGGUUCGAUCCCGCAUAGCUCCACCA"));
Assert.That(oligos.All(p => p.IsContaminant));
Assert.That(oligos.All(p => !p.IsDecoy));
}

[Test]
public static void TestNotGeneratingTargetsOrDecoys()
{
var oligos = RnaDbLoader.LoadRnaFasta(ModomicsUnmodifedFastaPath, false, DecoyType.None, true,
out var errors);
Assert.That(errors.Count, Is.EqualTo(0));
Assert.That(oligos.Count, Is.EqualTo(0));
}

[Test]
public static void TestXmlWriterReader()
{
var rna = RnaDbLoader.LoadRnaFasta(ModomicsUnmodifedFastaPath, true, DecoyType.None, false, out var errors);
Assert.That(errors.Count, Is.EqualTo(0));

var modString = "ID Methylation\r\nMT Biological\r\nPP Anywhere.\r\nTG G\r\nCF C1H2\r\n" + @"//";
var methylG = PtmListLoader.ReadModsFromString(modString, out List<(Modification, string)> modsOut).First();

Dictionary<string, HashSet<Tuple<int, Modification>>> mods = new Dictionary<string, HashSet<Tuple<int, Modification>>>();
mods.Add("SO:0000254", new HashSet<Tuple<int, Modification>>()
{
new Tuple<int, Modification>(1, methylG),
new Tuple<int, Modification>(3, methylG)
});

string outpath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Transcriptomics/TestData/ModomicsUnmodifiedTrimmed.xml");

var xml = ProteinDbWriter.WriteXmlDatabase(mods, rna, outpath);
var temp = RnaDbLoader.LoadRnaXML(outpath, true, DecoyType.None, false,
new List<Modification>() { methylG }, new List<string>(), out var unknownMods);

Assert.That(unknownMods.Count, Is.EqualTo(0));
Assert.That(temp.Count, Is.EqualTo(5));
var first = temp.First();
var loadedMods = first.OneBasedPossibleLocalizedModifications;
Assert.That(loadedMods.Count, Is.EqualTo(2));
Assert.That(loadedMods[1].Count, Is.EqualTo(1));
Assert.That(loadedMods[3].Count, Is.EqualTo(1));
Assert.That(loadedMods[1].First().IdWithMotif, Is.EqualTo(methylG.IdWithMotif));
Assert.That(loadedMods[3].First().IdWithMotif, Is.EqualTo(methylG.IdWithMotif));
}

[Test]
[TestCase("ATCG", "AUCG", true)]
[TestCase("ATCG", "UAGC", false)]
[TestCase("ATCGZ", "AUCGZ", true)]
[TestCase("ATCGZ", "UAGCZ", false)]
[TestCase("ATCGACGAATCACGATCAGTCATGCATTGCTAACT", "AUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACU", true)]
[TestCase("ATCGACGAATCACGATCAGTCATGCATTGCTAACT", "UAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGA", false)]
[TestCase("ATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACT", "AUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACUAUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACUAUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACUAUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACUAUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACUAUCGACGAAUCACGAUCAGUCAUGCAUUGCUAACU", true)]
[TestCase("ATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACTATCGACGAATCACGATCAGTCATGCATTGCTAACT", "UAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGAUAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGAUAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGAUAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGAUAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGAUAGCUGCUUAGUGCUAGUCAGUACGUAACGAUUGA", false)]
public static void TestTranscribe(string input, string expected, bool isCodingStrand)
{
Assert.That(input.Transcribe(isCodingStrand), Is.EqualTo(expected));
}
}
}
Loading
Loading