diff --git a/mzLib/Test/TestPrideProjectRetriever.cs b/mzLib/Test/TestPrideProjectRetriever.cs new file mode 100644 index 000000000..962d2fac4 --- /dev/null +++ b/mzLib/Test/TestPrideProjectRetriever.cs @@ -0,0 +1,71 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UsefulProteomicsDatabases; +using NUnit.Framework; + +namespace Test +{ + [TestFixture] + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public class TestPrideProjectRetriever + { + [Test] + public void TestProjectRetrieve() + { + string projectAccession = "PXD048176"; + string outputFullFilePath = @"E:\junk\junk.txt"; + + //UP000008595 is Uukuniemi virus (strain S23) (Uuk) which only has 4 proteins + string returnedFilePath = PrideRetriever.RetrieveMassSpecProject("", outputFullFilePath); + + Assert.AreEqual(outputFullFilePath, returnedFilePath); + } + [Test] + public void TestRetrieveProjectFileByName() + { + string projectAccession = "PXD048176"; + string filename = "d_atg1_d_atg11_proteome_data_analysis.7z"; + string outputDirectory = @"E:\junk"; + + //UP000008595 is Uukuniemi virus (strain S23) (Uuk) which only has 4 proteins + string returnedFilePath = PrideRetriever.RetrieveProjectFileByFilename(projectAccession,filename, outputDirectory); + + Assert.AreEqual(outputDirectory, returnedFilePath); + } + [Test] + public void TestRetrieveProjectFileListByProjectAccession() + { + string projectAccession = "PXD048176"; + string outputDirectory = @"E:\junk"; + + //UP000008595 is Uukuniemi virus (strain S23) (Uuk) which only has 4 proteins + string returnedFilePath = PrideRetriever.RetrieveProjectFileListByProjectAccession(projectAccession, outputDirectory); + + Assert.AreEqual(outputDirectory, returnedFilePath); + } + [Test] + public void TestPrideFtp() + { + PrideRetriever.PrideFtp(); + } + + [Test] + public void TestSimpleWebClientDownload() + { + string uri = "ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2023/12/PXD048176/d_atg1_d_atg11_proteome_data_analysis.7z"; + string fullFilePath = @"E:\junk\PXD048176\d_atg1_d_atg11_proteome_data_analysis.7z"; + PrideRetriever.SimpleWebClientDownload(uri,fullFilePath); + } + + [Test] + public void DownloadUniProtProteomes() + { + var j = ProteinDbRetriever.DownloadAvailableUniProtProteomes(@"E:\junk"); + } + } +} diff --git a/mzLib/UsefulProteomicsDatabases/PrideRetriever.cs b/mzLib/UsefulProteomicsDatabases/PrideRetriever.cs new file mode 100644 index 000000000..123a1cb77 --- /dev/null +++ b/mzLib/UsefulProteomicsDatabases/PrideRetriever.cs @@ -0,0 +1,88 @@ +using Easy.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace UsefulProteomicsDatabases +{ + public class PrideRetriever + { + private string b = "https://www.ebi.ac.uk/pride/ws/archive/v2/status/PXD048177"; + + + public static string RetrieveMassSpecProject(string PrideProjectAccession, string outputFullFilePath) + { + string htmlQueryString = "https://www.ebi.ac.uk/pride/ws/archive/v2/status/" + PrideProjectAccession; + + if (htmlQueryString.Length > 0) + { + Loaders.DownloadContent(htmlQueryString, outputFullFilePath); + return outputFullFilePath; + } + + return ""; + } + public static string RetrieveProjectFileByFilename(string prideProjectAccession, string prideFilename, string outputFileDirectory) + { + string htmlQueryString = + "https://www.ebi.ac.uk/pride/ws/archive/v2/files/fileByName?fileName=" + prideFilename + "&projectAccession=" + prideProjectAccession; + + if (htmlQueryString.Length > 0) + { + Loaders.DownloadContent(htmlQueryString, Path.Join(outputFileDirectory,prideFilename)); + return outputFileDirectory; + } + + return ""; + } + public static string RetrieveProjectFileListByProjectAccession(string prideProjectAccession, string outputFileDirectory) + { + string htmlQueryString = + "https://www.ebi.ac.uk/pride/private/ws/archive/v2/" + "projects/" + prideProjectAccession + "/files"; + + if (htmlQueryString.Length > 0) + { + Loaders.DownloadContent(htmlQueryString, Path.Join(outputFileDirectory, prideProjectAccession + ".json")); + return outputFileDirectory; + } + + return ""; + } + public static void PrideFtp() + { + // Get the object used to communicate with the server. + FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2023/12/PXD048176/d_atg1_d_atg11_proteome_data_analysis.7z"); + request.Method = WebRequestMethods.Ftp.DownloadFile; + + // This example assumes the FTP site uses anonymous logon. + request.Credentials = new NetworkCredential("anonymous", "anonymous"); + + request.KeepAlive = true; + request.UsePassive = true; + request.UseBinary = true; + + //// Read the file from the server & write to destination + //using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) // Error here + //using (Stream responseStream = response.GetResponseStream()) + //using (StreamReader reader = new StreamReader(responseStream)) + //using (StreamWriter destination = new StreamWriter(destinationFile)) + //{ + // destination.Write(reader.ReadToEnd()); + // destination.Flush(); + //} + + } + + public static void SimpleWebClientDownload(string url, string fullFilePath) + { + WebClient client = new WebClient(); + client.Credentials = new NetworkCredential("anonymous", "anonymous"); + client.DownloadFile( + url, fullFilePath); + } + } +}