public void TestMissingDirectory() { string filepath = @"NoDirectoryHere\NoFileHere.fa"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.Fail("Should not get here!"); }
public void TestMissingFile() { string filepath = @"TestUtils\NoFileHere.fa"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.AreEqual(SequenceParsers.Fasta, foundParser); }
public void TestMissingFile() { string filepath = @"TestUtils\NoFileHere.fa"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.Fail("Should not get here!"); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFile(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (Helper.IsGenBank(fileName)) { parser = new GenBankParser(); } else if (fileName.EndsWith(Resource.GFF_FILEEXTENSION, StringComparison.OrdinalIgnoreCase)) { parser = new GffParser(); } else if (Helper.IsFasta(fileName)) { parser = new FastaParser(); } else if (Helper.IsFastQ(fileName)) { parser = new FastQParser(); } else { parser = null; } } return(parser); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <param name="parserName">Name of the parser to use.</param> /// <returns>If found returns the open parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByName(string fileName, string parserName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(parserName)) { if (parserName == Properties.Resource.FastAName) { parser = new FastAParser(fileName); } else if (parserName == Properties.Resource.FastQName) { parser = new FastQParser(fileName); } else if (parserName == Properties.Resource.GENBANK_NAME) { parser = new GenBankParser(fileName); } else { // Do a search through the known parsers to pick up custom parsers added through add-in. parser = All.FirstOrDefault(p => p.Name == parserName); // If we found a match based on extension, then open the file - this // matches the above behavior where a specific parser was created for // the passed filename - the parser is opened automatically in the constructor. if (parser != null) { parser.Open(fileName); } } } return(parser); }
public void TestMissingDirectory() { string filepath = @"NoDirectoryHere\NoFileHere.fa"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.AreEqual(SequenceParsers.Fasta, foundParser); }
public void ReturnNoParser() { string dummyFileName = "dummy.abc"; ISequenceParser parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.AreEqual(parser, null); }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override IEnumerable <ISequence> Execute(CodeActivityContext context) { string filename = Filename.Get(context); ISequenceParser parser = SequenceParsers.FindParserByFileName(filename); if (parser == null) { throw new ArgumentException("Could not determine parser for " + filename); } string alphaName = DesiredAlphabet; if (!string.IsNullOrEmpty(alphaName)) { alphaName = alphaName.ToLowerInvariant(); IAlphabet alphabet = Alphabets.All.FirstOrDefault(a => a.Name.ToLowerInvariant() == alphaName); if (alphabet == null) { throw new ArgumentException("Unknown alphabet name"); } parser.Alphabet = alphabet; } if (LogOutput) { var tw = context.GetExtension <TextWriter>() ?? Console.Out; tw.WriteLine("Reading sequences from " + filename); } return(parser.Parse()); }
/// <summary> /// Alternative constructor for performing quality score-level QC when /// read length max and count is not available and needs to be determined. /// </summary> /// <param name="sequences">Sequence parser</param> /// <param name="format">FastQ Format Type.</param> /// <param name="filename">the input filename</param> public QualityScoreAnalyzer(ISequenceParser sequences, FastQFormatType format, string filename) : base(sequences, filename) { List <long> lengths = this.DetermineReadLengths(); this.Count = lengths.Count; Initialize(format); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <param name="parserName">Name of the parser to use.</param> /// <returns>If found returns the parser as IParser else returns null.</returns> public static ISequenceParser FindParserByName(string fileName, string parserName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (parserName == Properties.Resource.FastAName) { parser = new FastAParser(fileName); } else if (parserName == Properties.Resource.FastQName) { parser = new FastQParser(fileName); } else if (parserName == Properties.Resource.GENBANK_NAME) { parser = new GenBankParser(fileName); } else if (parserName == Properties.Resource.GFF_NAME) { parser = new GffParser(fileName); } else { parser = null; } } return(parser); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <param name="parserName">Name of the parser to use.</param> /// <returns>If found returns the open parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByName(string fileName, string parserName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(parserName)) { if (parserName == Properties.Resource.FastAName) { parser = fasta; } else if (parserName == Properties.Resource.FastQName) { parser = new SequenceParserDecorator <FastQParser, IQualitativeSequence>(fastq); } else if (parserName == Properties.Resource.GENBANK_NAME) { parser = genBank; } else if (parserName == Properties.Resource.GFF_NAME) { parser = gff; } else { // Do a search through the known parsers to pick up custom parsers added through add-in. parser = All.FirstOrDefault(p => p.Name == parserName); } } return(parser); }
/// <summary> /// Finds a suitable parser that supports the specified file, opens the file and returns the parser. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFileName(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (IsFasta(fileName)) { parser = new FastAParser(fileName); } else if (IsFastQ(fileName)) { parser = new FastQParser(fileName); } else if (IsGenBank(fileName)) { parser = new GenBankParser(fileName); } else if (fileName.EndsWith(Properties.Resource.GFF_FILEEXTENSION, StringComparison.InvariantCultureIgnoreCase)) { parser = new GffParser(fileName); } else { parser = null; } } return(parser); }
public void FindGenBankParser() { string dummyFileName = "dummy.gb"; ISequenceParser parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(GenBankParser), parser); }
public void FindFastaParser() { string dummyFileName = "dummy.fasta"; ISequenceParser parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.fa"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.mpfa"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.fna"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.faa"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.fsa"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); dummyFileName = "dummy.fas"; parser = SequenceParsers.FindParserByFile(dummyFileName); Assert.IsInstanceOf(typeof(FastaParser), parser); }
/// <summary> /// Finds a suitable parser that supports the specified file, opens the file and returns the parser. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the open parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFileName(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (IsFasta(fileName)) { parser = fasta; } else if (IsFastQ(fileName)) { parser = new SequenceParserDecorator <FastQParser, IQualitativeSequence>(fastq); } else if (IsGenBank(fileName)) { parser = genBank; } else if (fileName.EndsWith(Properties.Resource.GFF_FILEEXTENSION, StringComparison.OrdinalIgnoreCase)) { parser = gff; } else { // Do a search through the known parsers to pick up custom parsers added through add-in. string fileExtension = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(fileExtension)) { parser = All.FirstOrDefault(p => p.SupportedFileTypes.Contains(fileExtension)); } } } return(parser); }
public void TestUnknownFileExtension() { string filepath = @"Test.ukn"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.IsNull(foundParser); }
/// <summary> /// Constructor when called from GUI. Used when read length max and count is not available and needs to be determined. /// </summary> /// <param name="sequences">Sequence parser</param> /// <param name="format">FastQ Format Type.</param> /// <param name="filename">the input filename</param> /// <param name="worker">Background worker</param> /// <param name="e">Background Worker event args</param> public QualityScoreAnalyzer(ISequenceParser sequences, FastQFormatType format, string filename, BackgroundWorker worker, DoWorkEventArgs e) : base(sequences, filename, worker, e) { List <long> lengths = this.DetermineReadLengths(); this.Count = lengths.Count; Initialize(format); }
/// <summary> /// Constructor for discarding reads based on minimum length. /// </summary> /// <param name="parser">Input sequence parser</param> /// <param name="filtered">Output sequence formatter</param> /// <param name="discarded">Output discarded sequences formatter</param> /// <param name="length">The minimum length that reads must satisfy in /// order to not be discarded.</param> public DiscardByLength(ISequenceParser parser, ISequenceFormatter filtered, ISequenceFormatter discarded, long length) : base(parser, filtered, discarded) { if (length <= 0) { throw new ArgumentOutOfRangeException("Minimum length must be > 0."); } minLengthThreshold = length; }
private void btnOK_Click(object sender, EventArgs e) { ISequenceParser foundParser = (ISequenceParser)cbParserList.SelectedItem; if (foundParser != null) { SelectedParser = SequenceParsers.FindParserByName(FileName, foundParser.Name); } }
/// <summary> /// Parses a file containing a sequence in .NET Bio supported formats. /// </summary> /// <param name="file">Path to a parsed file.</param> /// <returns>Fragment sequence.</returns> private ISequence ParseFile(String file) { parser = SequenceParsers.FindParserByFileName(file); if (parser == null) { throw new FileFormatException("Parser for " + file + " not found."); } return(ParseFragment(parser, file)); }
public void TestTxtFileExtension() { string filepath = @"TestUtils\BLOSUM50.txt"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.IsNull(foundParser); // Should not auto-locate FieldTextParser. }
public void TestGffFileExtension() { string filepath = @"TestUtils\Simple_Gff_Dna.gff"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.IsNotNull(foundParser); Assert.IsInstanceOf <GffParser>(foundParser); }
public void TestSffFileExtension() { string filepath = @"TestUtils\dummy.sff"; ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath); Assert.IsNotNull(foundParser); Assert.IsInstanceOf <SFFParser>(foundParser); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { String inputFileName = InputFile; ISequenceParser parser = SequenceParsers.FindParserByFile(inputFileName); SequenceResult = parser.ParseOne(inputFileName); return(ActivityExecutionStatus.Closed); }
/// <summary> /// Constructor for trimming sequences based on length or percentage /// </summary> /// <param name="parser">Input sequences parser</param> /// <param name="filtered">Output sequences formatter</param> /// <param name="discarded">Discarded sequences formatter</param> /// <param name="newLength">If > 1, this is the minimum length (rounded to the nearest integer) /// sequences will be trimmed at. If between 0 and 1, this will be treated as /// a percentage and reads are trimmed based on this amount (i.e. if newLength = 0.5, 50% /// of the read will be trimmed.</param> /// <param name="fromStart">Trim from the start of the read</param> public TrimByLength(ISequenceParser parser, ISequenceFormatter filtered, ISequenceFormatter discarded, double newLength, bool fromStart) : base(parser, filtered, discarded, fromStart) { if (newLength <= 0) { throw new ArgumentOutOfRangeException("Trim length cannot be less than zero."); } this.TrimLength = newLength; }
// Parses a sequence and adds it to the displayed list private void ParseSequence(ISequenceParser parser, string filename) { IList <ISequence> parsed = parser.Parse(filename); ListBox sequenceList = (ListBox)FindName("SequencesListBox"); foreach (ISequence seq in parsed) { sequenceList.Items.Add(seq); } }
/// <summary> /// Constructor for processing the input file /// </summary> /// <param name="file">Input filename</param> public InputSubmission(string file) { if (file == null) { throw new ArgumentNullException("file"); } this.Filename = file; this.Parser = SequenceParsers.FindParserByFileName(file); }
/// <summary> /// Helper method to parse the given filename into a set /// of ISequence elements. This routine will load sequences from /// any support sequence parser in .NET Bio. /// </summary> /// <param name="fileName">Filename to load data from</param> /// <returns>Enumerable set of ISequence elements</returns> protected static IEnumerable <ISequence> ParseFile(string fileName) { ISequenceParser parser = SequenceParsers.FindParserByFileName(fileName); if (parser == null) { throw new Exception("Could not locate an appropriate sequence parser for " + fileName); } return(parser.Parse()); }
/// <summary> /// Helper method to parse the given filename into a set /// of ISequence elements. This routine will load sequences from /// any support sequence parser in .NET Bio. /// </summary> /// <param name="fileName">Filename to load data from</param> /// <returns>Enumerable set of ISequence elements</returns> internal static IEnumerable <ISequence> ParseFile(string fileName) { ISequenceParser parser = SequenceParsers.FindParserByFileName(fileName); if (parser == null) { parser = new FastAParser(fileName); } return(parser.Parse()); }
// Parses a sequence and adds it to the displayed list private void ParseSequence(ISequenceParser parser, string filename) { parser.Open(filename); IEnumerable <ISequence> parsed = parser.Parse(); ListBox sequenceList = (ListBox)FindName("SequencesListBox"); foreach (ISequence seq in parsed) { sequenceList.Items.Add(seq); } parser.Close(); }
public void ValidateParserExceptions(ISequenceParser parser) { try { var parserTypes = parser.GetType(); Assert.IsNotNull(parserTypes); } catch (NullReferenceException exception) { // Log to VSTest GUI. ApplicationLog.WriteLine(string.Format((IFormatProvider) null, "Sequence Parser P2 : Validated Exception {0} successfully", exception.Message)); } }
/// <summary> /// This method is called when the user wants to import a Sequence file /// into excel. The user chooses a particular Sequence file which will /// be parsed by parsers available in our framework and is then imported /// into a excel file. /// </summary> /// <param name="parser">SequenceParser instance.</param> /// <param name="fileName">Name of the file</param> /// <param name="currentRow">Current row of insertion</param> private void ReadSequences(ISequenceParser parser, string fileName, ref int currentRow) { this.ScreenUpdate(false); if (this.sequencesPerWorksheet == 1) { this.ImportSequencesOnePerSheet(parser, fileName); } else if (this.sequencesPerWorksheet <= 0) { this.ImportSequencesAllInOneSheet(parser, fileName, ref currentRow); } else if (this.sequencesPerWorksheet > 0) { this.ImportSequencesAcrossSheets(parser, fileName, ref currentRow); } this.ScreenUpdate(true); }
/// <summary> /// This method breaks the sequences across multiple worksheets. /// </summary> /// <param name="parser"></param> /// <param name="fileName"></param> /// <param name="currentRow"></param> private void ImportSequencesAcrossSheets(ISequenceParser parser, string fileName, ref int currentRow) { Workbook workBook = Globals.ThisAddIn.Application.ActiveWorkbook; int sequenceCount = 0; Worksheet worksheet = null; Globals.ThisAddIn.Application.EnableEvents = false; try { foreach (ISequence sequence in parser.Parse()) { if (worksheet == null || sequenceCount++ >= this.sequencesPerWorksheet) { if (worksheet != null) { worksheet.Cells[1, 1].EntireColumn.AutoFit(); // Autofit first column } currentRow = 1; sequenceCount = 1; worksheet = workBook.Worksheets.Add( Type.Missing, workBook.Worksheets.Item[workBook.Worksheets.Count], Type.Missing, Type.Missing) as Worksheet; if (worksheet == null) { return; } // Get a name for the worksheet. string validName = this.GetValidFileNames( string.IsNullOrEmpty(sequence.ID) ? Path.GetFileNameWithoutExtension(fileName) : sequence.ID); worksheet.Name = validName; ((_Worksheet)worksheet).Activate(); Globals.ThisAddIn.Application.ActiveWindow.Zoom = ZoomLevel; } // If sequence ID cannot be used as a sheet name, update the sequence DisplayID with the string used as sheet name. if (string.IsNullOrEmpty(sequence.ID)) { sequence.ID = Path.GetFileNameWithoutExtension(fileName) + "_" + sequenceCount; } this.WriteOneSequenceToWorksheet(parser, ref currentRow, sequence, worksheet); } if (worksheet != null) { worksheet.Cells[1, 1].EntireColumn.AutoFit(); // Autofit first column } } finally { this.EnableAllControls(); Globals.ThisAddIn.Application.EnableEvents = true; } }
public void openProject(String file) { Sequence sequence = null; parser = SequenceParsers.GenBank; parser.Open(file); sequence = (Sequence)parser.Parse().ToList()[0]; parser.Close(); Fragment project = new Fragment(file, "project", sequence); GenBankMetadata meta = sequence.Metadata["GenBank"] as GenBankMetadata; FragmentDict = new Dictionary<string, Fragment>(); foreach (var feat in meta.Features.MiscFeatures) { String subseq = project.GetString().Substring(feat.Location.LocationStart-1, feat.Location.LocationEnd - feat.Location.LocationStart + 1); FragmentDict.Add(feat.StandardName, new Fragment(file, feat.StandardName, new Sequence(Alphabets.AmbiguousDNA, subseq))); } }
/// <summary> /// This method imports a set of sequences, one per worksheet. /// </summary> /// <param name="parser">SequenceParser instance.</param> /// <param name="fileName">Name of the file</param> private void ImportSequencesOnePerSheet(ISequenceParser parser, string fileName) { Workbook workBook = Globals.ThisAddIn.Application.ActiveWorkbook; foreach (ISequence sequence in parser.Parse()) { var worksheet = workBook.Worksheets.Add( Type.Missing, workBook.Worksheets.Item[workBook.Worksheets.Count], Type.Missing, Type.Missing) as Worksheet; if (worksheet == null) { return; } string validName = this.GetValidFileNames( string.IsNullOrEmpty(sequence.ID) ? Path.GetFileNameWithoutExtension(fileName) : sequence.ID); // If sequence ID cannot be used as a sheet name, update the sequence DisplayID with the string used as sheet name. if (string.IsNullOrEmpty(sequence.ID)) { sequence.ID = validName; } worksheet.Name = validName; ((_Worksheet)worksheet).Activate(); Globals.ThisAddIn.Application.ActiveWindow.Zoom = ZoomLevel; Globals.ThisAddIn.Application.EnableEvents = false; try { int currentRow = 1; this.WriteOneSequenceToWorksheet(parser, ref currentRow, sequence, worksheet); this.currentFileNumber++; } finally { worksheet.Cells[1, 1].EntireColumn.AutoFit(); // Autofit first column this.EnableAllControls(); Globals.ThisAddIn.Application.EnableEvents = true; } } }
/// <summary> /// Parses a fragment using an appropriate parser. /// </summary> /// <param name="parser">Open parser.</param> /// <param name="fragmentName">Fragment name.</param> /// <returns>Fragment sequence.</returns> private ISequence ParseFragment(ISequenceParser parser, String fragmentName) { List<ISequence> sequences; using (parser) { sequences = parser.Parse().ToList(); } if (sequences.Count != 1) { throw new SequenceCountException(fragmentName + " contains " + sequences.Count + " well-formatted sequences. It should contain exactly one."); } if (sequences.First().Count < 150) { throw new SequenceLengthException("Sequence in " + fragmentName + " is shorter than 150nt. It should not be used as a fragment.", sequences.First()); } return sequences.First(); }
/// <summary> /// Parses a file containing a sequence in .NET Bio supported formats. /// </summary> /// <param name="file">Path to a parsed file.</param> /// <returns>Fragment sequence.</returns> private ISequence ParseFile(String file) { parser = SequenceParsers.FindParserByFileName(file); if (parser == null) { throw new FileFormatException("Parser for " + file + " not found."); } return ParseFragment(parser, file); }
/// <summary> /// This method imports a set of sequences, one sequence per row. /// </summary> /// <param name="parser">SequenceParser instance.</param> /// <param name="fileName">Name of the file</param> /// <param name="currentRow">Next row of insertion</param> private void ImportSequencesAllInOneSheet(ISequenceParser parser, string fileName, ref int currentRow) { Workbook workBook = Globals.ThisAddIn.Application.ActiveWorkbook; var worksheet = workBook.Worksheets.Add( Type.Missing, workBook.Worksheets.Item[workBook.Worksheets.Count], Type.Missing, Type.Missing) as Worksheet; worksheet.Name = this.GetValidFileNames(Path.GetFileNameWithoutExtension(fileName)); ((_Worksheet)worksheet).Activate(); Globals.ThisAddIn.Application.ActiveWindow.Zoom = ZoomLevel; Globals.ThisAddIn.Application.EnableEvents = false; try { int sequenceCount = 0; foreach (ISequence sequence in parser.Parse()) { sequenceCount++; if (string.IsNullOrEmpty(sequence.ID)) { sequence.ID = Path.GetFileNameWithoutExtension(fileName) + "_" + sequenceCount; } this.WriteOneSequenceToWorksheet(parser, ref currentRow, sequence, worksheet); this.currentFileNumber++; } } finally { worksheet.Cells[1, 1].EntireColumn.AutoFit(); // Autofit first column this.EnableAllControls(); Globals.ThisAddIn.Application.EnableEvents = true; } }
/// <summary> /// This writes out a single sequence with header, data, quality scores and metadata into the worksheet. /// </summary> /// <param name="parser"></param> /// <param name="currentRow"></param> /// <param name="sequence"></param> /// <param name="worksheet"></param> private void WriteOneSequenceToWorksheet( ISequenceParser parser, ref int currentRow, ISequence sequence, Worksheet worksheet) { // Write the header (sequence id) if (!string.IsNullOrEmpty(sequence.ID)) { string[,] formattedMetadata = ExcelImportFormatter.SequenceIDHeaderToRange(sequence); Range range = this.WriteToSheet(worksheet, formattedMetadata, currentRow, 1); if (range != null) { range.WrapText = false; currentRow += range.Rows.Count; } } // Write out the data Range dataRange; if (sequence.Count > 0) { currentRow = this.WriteSequence(worksheet, sequence, currentRow, out dataRange); if (dataRange != null) { dataRange.Columns.AutoFit(); // Autofit columns with sequence data } } // Write quality values if file is FastQ if (sequence is QualitativeSequence) { currentRow++; worksheet.Cells[currentRow, 1].Value2 = Resources.Sequence_QualityScores; currentRow = this.WriteQualityValues( sequence as QualitativeSequence, worksheet, currentRow, 3, out dataRange); if (dataRange != null) { dataRange.Columns.AutoFit(); // Autofit columns with quality scores } } // Write out the metadata Range metadataRange; this.WriteMetadata(sequence, parser, worksheet, currentRow, out metadataRange); if (metadataRange != null) { currentRow += metadataRange.Rows.Count; } currentRow++; // Add space row between sequences }
/// <summary> /// Formats the metadata depending on the sequence type and displays it. /// </summary> /// <param name="sequence">Sequence which is holding the metadata</param> /// <param name="parserUsed">Parser used to read data</param> /// <param name="worksheet">Sheet on to which the metadata should be written.</param> /// <param name="startingRow">Row we are on</param> /// <param name="metadataRange">Will have the range to which the metadata was written</param> private void WriteMetadata( ISequence sequence, ISequenceParser parserUsed, Worksheet worksheet, int startingRow, out Range metadataRange) { if (parserUsed is GenBankParser) { if (sequence.Metadata.ContainsKey(GenbankMetadataKey)) { string[,] formattedMetadata = ExcelImportFormatter.GenBankMetadataToRange( sequence.Metadata[GenbankMetadataKey] as GenBankMetadata); metadataRange = this.WriteToSheet(worksheet, formattedMetadata, startingRow, 1); if (metadataRange != null) { // Turn off wrapping for metadata values. metadataRange.WrapText = false; } } else { metadataRange = null; } } else if (parserUsed is GffParser) { string[,] formattedMetadata = ExcelImportFormatter.GffMetaDataToRange(sequence); metadataRange = this.WriteToSheet(worksheet, formattedMetadata, startingRow, 1); if (metadataRange != null) { metadataRange.Columns.VerticalAlignment = XlVAlign.xlVAlignTop; metadataRange.WrapText = false; // Now wrap data columns metadataRange.Columns[2].AutoFit(); metadataRange.Columns[2].WrapText = true; metadataRange.Columns[2].AutoFit(); } } else { metadataRange = null; // No error on this. //MessageBox.Show(Resources.MetadataFormatError, Resources.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }