/// <summary> /// Writes the reads to StandardOutput. /// </summary> /// <param name="reads">Reads to write.</param> private static void WriteOutput(IEnumerable <ISequence> reads) { foreach (ISequence seq in reads) { Console.WriteLine(FastAFormatter.FormatString(seq)); } }
/// <summary> /// Get the blast service request object with all the request parameter set /// </summary> /// <param name="sequence">Input sequece</param> /// <param name="parameters">Blast parameters</param> /// <returns>Blast service request object</returns> private static BlastSerivceRequest GetRequestParameter( ISequence sequence, BlastParameters parameters) { BlastSerivceRequest blastParameter = new BlastSerivceRequest(); // Sets the format of output expected from Azure Blast service blastParameter.OptionM = OPTIONMVALUE; // Sets the name of Job owner blastParameter.Owner = Resources.OWNERVALUE; blastParameter.ParitionNumber = PARTITIONVALUE; // Convert string to byte string inputContent = FastAFormatter.FormatString(sequence); ASCIIEncoding asciiEncoding = new ASCIIEncoding(); blastParameter.InputContent = asciiEncoding.GetBytes(inputContent); // Other parameters // Set the Title of Job blastParameter.Title = sequence.ID; // Name of the database to be searched in blastParameter.DatabaseName = parameters.Settings[PARAMETERDATABASE]; // Type of search program to be executed blastParameter.ProgramName = parameters.Settings[PARAMETERPROGRAM]; return(blastParameter); }
/// <summary> /// CreateJob() to get job id and control id and Submit job /// using input sequence with job id and control id /// </summary> /// <param name="sequence">input sequences</param> /// <param name="parameters">input params</param> /// <returns>result params with job id and control id</returns> public ServiceParameters SubmitRequest(IList <ISequence> sequence, ClustalWParameters parameters) { ServiceParameters result = new ServiceParameters(); if (null == sequence) { throw new ArgumentNullException("Sequence"); } if (null == parameters) { throw new ArgumentNullException("Parameters"); } // ClusterOption = biosim cbsum1 cbsum2k8 cbsusrv05 cbsum2 or Auto string[] output = _baseClient.CreateJob(tAppId.P_CLUSTALW, "test_BioHPC_Job", "1", parameters.Values[ClustalWParameters.Email].ToString(), string.Empty, parameters.Values[ClustalWParameters.ClusterOption].ToString()); if (!output[0].Contains(ERROR)) { result.JobId = output[1]; result.Parameters.Add(CONTROLID, output[2]); AppInputData inputData = _baseClient.InitializeApplicationParams(tAppId.P_CLUSTALW, "test_BioHPC_Job"); StringBuilder inputSequence = new StringBuilder(); foreach (ISequence seq in sequence) { inputSequence.AppendLine(FastAFormatter.FormatString(seq)); } inputData.clustalw.inputsource = QuerySrcType.paste; inputData.clustalw.inputstring = inputSequence.ToString(); inputData.clustalw.isDNA = false; inputData.clustalw.action = (ClwActions)Enum.Parse(typeof(ClwActions), parameters.Values[ClustalWParameters.ActionAlign].ToString()); inputData.clustalw.email_notify = true; _baseClient.SubmitJob(result.JobId, result.Parameters[CONTROLID].ToString(), inputData); result.Parameters.Add(SUBMISSONRESULT, SUCCESS); // Only if the event is registered, invoke the thread if (null != RequestCompleted) { // Start the BackGroundThread to check the status of job _workerThread = new BackgroundWorker(); _workerThread.WorkerSupportsCancellation = true; _workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); _workerThread.RunWorkerAsync(result); } } else { result.Parameters.Add(SUBMISSONRESULT, output[0]); } return(result); }
/// <summary> /// Writes delta for query sequences. /// </summary> /// <param name="delta">The Deltas.</param> private void WriteDelta( IList<List<IEnumerable<DeltaAlignment>>> delta) { TextWriter textWriterConsoleOutSave = Console.Out; if (!string.IsNullOrEmpty(this.OutputFile)) { FileStream fileStreamConsoleOut = new FileStream(this.OutputFile, FileMode.Create); StreamWriter streamWriterConsoleOut = new StreamWriter(fileStreamConsoleOut); Console.SetOut(streamWriterConsoleOut); streamWriterConsoleOut.AutoFlush = true; } foreach (var alignment in delta) { foreach (IEnumerable<DeltaAlignment> align in alignment) { foreach (DeltaAlignment deltaAlignment in align) { Console.WriteLine( ">" + deltaAlignment.ReferenceSequenceId); if (deltaAlignment.QuerySequence != null) { Console.WriteLine(FastAFormatter.FormatString(deltaAlignment.QuerySequence).Substring(1)); } else { //To provide empty lines in place of query sequence id and query sequence Console.WriteLine(); Console.WriteLine(); } Console.WriteLine( deltaAlignment.FirstSequenceStart + " " + deltaAlignment.FirstSequenceEnd + " " + deltaAlignment.SecondSequenceStart + " " + deltaAlignment.SecondSequenceEnd + " " + deltaAlignment.Errors + " " + deltaAlignment.SimilarityErrors + " " + deltaAlignment.NonAlphas); foreach (long deltas in deltaAlignment.Deltas) { Console.WriteLine(deltas); } Console.WriteLine("*"); } Console.WriteLine("--"); } } Console.SetOut(textWriterConsoleOutSave); }
public void FastAFormatterInvalidateFormatString() { ISequence iSeq = null; try { string formattedString = FastAFormatter.FormatString(iSeq); Assert.Fail(); } catch (ArgumentNullException ex) { ApplicationLog.Write("Fasta P2 : ArgumentNullException caught successfully. " + ex.Message); } }
/// <summary> /// Submit the search request with the user supplied configuration parameters and sequence /// Implementation should make use of the Bio.IO formatters to convert the sequence into /// the web interface compliant sequence format /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequences">List of sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Request Identifier</returns> public string SubmitRequest(IList <ISequence> sequences, BlastParameters parameters) { if (null == parameters) { throw new ArgumentNullException("parameters"); } if (null != sequences) { StringBuilder sb = new StringBuilder(); foreach (ISequence seq in sequences) { sb.Append(FastAFormatter.FormatString(seq)); sb.Append("\n"); } parameters.Add("Query", sb.ToString()); } if (!string.IsNullOrEmpty(Configuration.EmailAddress)) { if (!parameters.Settings.ContainsKey(PARAMETEREMAIL)) { parameters.Add(PARAMETEREMAIL, Configuration.EmailAddress); } } string requestIdentifier = string.Empty; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } parameters.Add(PARAMETERCOMMAND, COMMANDPUT); WebAccessor accessor = new WebAccessor(); WebAccessorResponse webAccessorResponse; if (Configuration.UseBrowserProxy) { accessor.GetBrowserProxy(); } webAccessorResponse = accessor.SubmitHttpRequest( ServiceUri, true, // do POST parameters.Settings); // request parameters if (!webAccessorResponse.IsSuccessful) { // failed accessor.Close(); throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.HTTPSUBMITFAILED, webAccessorResponse.StatusDescription)); } string info = ExtractInfoSection(webAccessorResponse.ResponseString); if (!String.IsNullOrEmpty(info)) { int ridStart = info.IndexOf("RID = ", StringComparison.OrdinalIgnoreCase); if (ridStart >= 0) { ridStart += "RID = ".Length; int ridEnd = info.IndexOf('\n', ridStart); if (ridEnd >= 0) { requestIdentifier = info.Substring(ridStart, ridEnd - ridStart); } } } accessor.Close(); if (string.IsNullOrEmpty(requestIdentifier)) { string message = String.Format(CultureInfo.InvariantCulture, Resources.RIDEXTRACTFAILED, ExtractError(webAccessorResponse.ResponseString)); throw new Exception(message); } // Only if the event is registered, invoke the thread if (null != RequestCompleted) { BlastThreadParameter threadParameter = new BlastThreadParameter( requestIdentifier, null, // Sequence parameter is not used any where, hence passing null. parameters); // Start the BackGroundThread to check the status of job workerThread = new BackgroundWorker(); workerThread.WorkerSupportsCancellation = true; workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }
/// <summary> /// Submit the search request with the user supplied configuration parameters and sequence list. /// Implementation should make use of the Bio.IO formatters to convert the sequence into /// the web interface compliant sequence format /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequences">List of sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Unique Search ID generated by Bio</returns> public string SubmitRequest(IList <ISequence> sequences, BlastParameters parameters) { if (sequences == null) { throw new Exception(Resources.BIOHPCNOSEQUENCE); } if (parameters == null) { throw new ArgumentNullException("parameters"); } string requestIdentifier; // Start of BioHPC-specific code // we are submitting BLAST and give the job a name tAppId appID = tAppId.P_BLAST; string jobname = BlastParameters.Parameters["JobName"].DefaultValue; if (parameters.Settings.ContainsKey(PARAMETERJOBNAME)) { if (!String.IsNullOrEmpty(parameters.Settings[PARAMETERJOBNAME])) { jobname = parameters.Settings[PARAMETERJOBNAME]; } } if (parameters.Settings.ContainsKey(PARAMETEREMAIL)) { if (string.IsNullOrEmpty(Configuration.EmailAddress)) { Configuration.EmailAddress = parameters.Settings[PARAMETEREMAIL]; } } // initialize input parameters with defaults AppInputData pars = blastClient.InitializeApplicationParams(appID, jobname); // Retrieve database names for easy access by parameter validator dnaDatabases = GetServiceMetadata(MetadataDatabasesDna); protDatabases = GetServiceMetadata(MetadataDatabasesProt); // Validate the parameter ParameterValidationResult valid = ValidateParameters(parameters, pars); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } // ValidateParameters updated some of the entries in pars and put them // into its ParametersObject - we need to fetch the updated pars pars = valid.ParametersObject as AppInputData; // Set some remaining parameters... pars.blast.querysource = QuerySrcType.paste; // We request XML as format, since this is what we can parse... pars.blast.options.format = OutputFormat.XML; // Query sequence should be in full Fasta format. // We concatenate all the sequences from the list into a single string. pars.blast.query = String.Empty; foreach (ISequence auxseq in sequences) { pars.blast.query += FastAFormatter.FormatString(auxseq) + "\n"; } pars.blast.query = pars.blast.query.Substring(0, pars.blast.query.Length - 1); // remobe trailing newline... // Run parameters and query string are ready. Submit the job to server: // Create a new BLAST job. string jobid = String.Empty; string cntrl = String.Empty; try { string[] outtab = blastClient.CreateJob(appID, jobname, "1", Configuration.EmailAddress, Configuration.Password, "Auto"); if (outtab[0].IndexOf(MsgError, StringComparison.Ordinal) != -1) { throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.BIOHPCJOBNOTCREATED, outtab[0])); } jobid = outtab[1]; cntrl = outtab[2]; requestIdentifier = jobid + "_" + cntrl; } catch { throw new Exception(Resources.BIOHPCSERVERABSENT); } // Finally, we can submit the job try { string result = blastClient.SubmitJob(jobid, cntrl, pars); if (result.IndexOf(MsgError, StringComparison.Ordinal) != -1) { throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.BIOHPCJOBNOTSUBMITTED, jobid, result)); } } catch { throw new Exception(Resources.BIOHPCSERVERABSENT); } // end of BioHPC-specific code // Only if the event is registered, invoke the thread if (null != RequestCompleted) { // ThreadParameter wants a single sequence - nor sure what this is for. // We'll give it the first sequence from the list, i.e., sequence[0] BlastThreadParameter threadParameter = new BlastThreadParameter( requestIdentifier, sequences[0], parameters); // Start the BackGroundThread to check the status of job workerThread = new BackgroundWorker(); workerThread.WorkerSupportsCancellation = true; workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }
/// <summary> /// Submit the search request with the user supplied configuration parameters /// and sequence. Implementation should make use of the Bio.IO formatters /// to convert the sequence into the web interface compliant sequence format. /// This method performs parameter validation and throw Exception on invalid input. /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequence">The sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Request Identifier</returns> public string SubmitRequest(ISequence sequence, BlastParameters parameters) { if (null == sequence) { throw new ArgumentNullException("sequence"); } if (null == parameters) { throw new ArgumentNullException("parameters"); } if (!string.IsNullOrEmpty(Configuration.EmailAddress)) { if (!parameters.Settings.ContainsKey(ParameterEmail)) { parameters.Add(ParameterEmail, Configuration.EmailAddress); } } string requestIdentifier = string.Empty; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } // Submit the job to server inputParams blastRequest = GetRequestParameter(parameters); blastRequest.appxml = AppXmlYes; blastRequest.async = true; data[] mydata = new data[1]; mydata[0] = new data(); mydata[0].type = SequenceType; mydata[0].content = FastAFormatter.FormatString(sequence); requestIdentifier = blastClient.runWUBlast(blastRequest, mydata); // Only if the event is registered, invoke the thread if (null != RequestCompleted) { BlastThreadParameter threadParameter = new BlastThreadParameter( requestIdentifier, sequence, parameters); // Start the BackGroundThread to check the status of job workerThread = new BackgroundWorker(); workerThread.WorkerSupportsCancellation = true; workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }