ClustalParser 1.0.3 → 1.1.0
raw patch · 7 files changed
+77/−31 lines, 7 filesdep +either-unwrapdep +hspecdep +vectordep ~basedep ~parsecPVP ok
version bump matches the API change (PVP)
Dependencies added: either-unwrap, hspec, vector
Dependency ranges changed: base, parsec
API changes (from Hackage documentation)
+ Bio.ClustalParser: showAlignment :: Int -> Int -> Int -> [ClustalAlignmentEntry] -> String -> String
+ Bio.ClustalParser: showAlignmentBlock :: Int -> Int -> [ClustalAlignmentEntry] -> String -> String
+ Bio.ClustalParser: showAlignmentLine :: Int -> Int -> ClustalAlignmentEntry -> String
Files
- ClustalParser.cabal +12/−7
- ClustalParserTest.hs +5/−2
- README.md +7/−4
- changelog +3/−0
- src/Bio/ClustalData.hs +36/−2
- src/Bio/ClustalParser.hs +12/−16
- test-suite/Spec.hs +2/−0
ClustalParser.cabal view
@@ -5,9 +5,9 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.0.3+version: 1.1.0 synopsis: Libary for parsing Clustal tools output-description: Currently contains parsers and datatypes for: clustalw2, clustalo+description: Currently contains parsers and datatypes for: clustalw2, clustalo, mlocarna . For more information on clustal Tools refer to <http://www.clustal.org/> .@@ -33,8 +33,8 @@ source-repository this type: git- location: https://github.com/eggzilla/ClustalParser/tree/1.0.3- tag: 1.0.3+ location: https://github.com/eggzilla/ClustalParser/tree/1.1.0+ tag: 1.1.0 library -- Modules exported by the library.@@ -42,7 +42,7 @@ other-modules: Bio.ClustalData -- Other library packages from which modules are imported.- build-depends: base >=4.5 && <5, parsec+ build-depends: base >=4.5 && <5, parsec>=3.1.9, vector -- compiler options ghc-options: -Wall -O2 -fno-warn-unused-do-bind -- Directories containing source files.@@ -50,7 +50,12 @@ executable ClustalParserTest main-is: ClustalParserTest.hs- build-depends: base >= 4 && <= 5, cmdargs, ClustalParser+ build-depends: base >= 4 && <= 5, cmdargs, ClustalParser, either-unwrap -- compiler options ghc-options: -Wall -O2- ++test-suite hspec+ build-depends: base, parsec, ClustalParser, hspec >= 1.8+ hs-source-dirs: test-suite+ main-is: Spec.hs+ type: exitcode-stdio-1.0
ClustalParserTest.hs view
@@ -2,12 +2,15 @@ import System.Environment (getArgs) import Bio.ClustalParser+import Data.Either.Unwrap main :: IO () main = do args <- getArgs let input_file = (head args) -- read Clustal outputfile- parsedinput <- readStructuralClustalAlignment input_file- print parsedinput+ parsedinput <- readClustalAlignment input_file+ --parsedinput <- readStructuralClustalAlignment input_file+ --print (entrySequenceIdentifier (head (structuralAlignmentEntries(fromRight parsedinput))))+ print (fromRight parsedinput)
README.md view
@@ -1,12 +1,15 @@-ClustalParser [](https://travis-ci.org/eggzilla/ClustalParser)+ClustalParser [](https://hackage.haskell.org/package/ClustalParser) [](https://travis-ci.org/eggzilla/ClustalParser) ============= -Currently contains parsers and datatypes for: clustalw2, clustalo+Currently contains parsers and datatypes for: clustalw2, clustalo, mlocarna -Clustal tools are multipe sequence aligenment tools for biological sequences +Clustal tools are multiple sequence alignment tools for biological sequences like DNA, RNA and Protein. For more information on clustal Tools refer to <http://www.clustal.org/>. +Mlocarna is a multiple sequence alignment tool for RNA sequences with+secondary structure output. +For more information on molocarna refer to <http://www.clustal.org/>. 4 types of output are parsed @@ -14,7 +17,7 @@ * Parsing with readClustalAlignment from filepath (Bio.ClustalParser) * Parsing with parseClustalAlignment from String (Bio.ClustalParser) -- Alignment file with secondary structure (.aln): + - Alignment file with secondary structure (.aln): * Parsing with readStructuralClustalAlignment from filepath (Bio.ClustalParser) * Parsing with parsStructuralClustalAlignment from String (Bio.ClustalParser)
changelog view
@@ -1,4 +1,7 @@ -*-change-log-*-+1.1.0 Florian Eggenhofer <florian.eggenhofer@univie.ac.at> 1. July 2015+ * Added Hspec test-suite for Parsing functions+ * Added Show instances for ClustalAlignment and StructuralClustalAlignment 1.0.3 Florian Eggenhofer <florian.eggenhofer@univie.ac.at> 19. April 2015 * Added Y (pyrimidine) and R (purine) to sequence characters 1.0.2 Florian Eggenhofer <florian.eggenhofer@univie.ac.at> 19. March 2015
src/Bio/ClustalData.hs view
@@ -2,6 +2,7 @@ -- For more information on Clustal tools consult: <http://www.clustal.org/> module Bio.ClustalData where+import qualified Data.Vector as V -- | Data type for clustal summary, containing information about the alignment process, usually printed to STDOUT data ClustalSummary = ClustalSummary@@ -48,8 +49,32 @@ alignmentEntries :: [ClustalAlignmentEntry], conservationTrack :: String }- deriving (Show, Eq)+ deriving (Eq) +instance Show ClustalAlignment where+ show (ClustalAlignment _alignmentEntries _conservationTrack ) + | not (null _alignmentEntries) = header ++ alignmentString+ | otherwise = header+ where header = "CLUSTAL W (1.8) multiple sequence alignment\n\n\n" + longestSequenceIdLength = (maximum (map length (map entrySequenceIdentifier _alignmentEntries))) + 1+ totalSequenceLength = length (entryAlignedSequence (head _alignmentEntries))+ alignmentString = showAlignment totalSequenceLength longestSequenceIdLength 0 _alignmentEntries _conservationTrack++showAlignment :: Int -> Int -> Int -> [ClustalAlignmentEntry] -> String -> String+showAlignment totalSequenceLength longestSequenceIdLength currentWindowPosition _alignmentEntries _conservationTrack+ | totalSequenceLength == 0 = [] + | currentWindowPosition <= totalSequenceLength = showAlignmentBlock longestSequenceIdLength currentWindowPosition _alignmentEntries _conservationTrack ++ (showAlignment totalSequenceLength longestSequenceIdLength (currentWindowPosition + 60) _alignmentEntries _conservationTrack)+ | otherwise = "" ++showAlignmentBlock :: Int -> Int -> [ClustalAlignmentEntry] -> String -> String+showAlignmentBlock longestSequenceIdLength currentWindowPosition _alignmentEntries _conservationTrack = blockString+ where blockString = entries ++ extraTrack ++ "\n"+ entries = concatMap (showAlignmentLine longestSequenceIdLength currentWindowPosition) _alignmentEntries+ extraTrack = concat (replicate longestSequenceIdLength " ") ++ V.toList (V.slice currentWindowPosition 60 (V.fromList _conservationTrack)) ++ "\n"++showAlignmentLine :: Int -> Int -> ClustalAlignmentEntry -> String+showAlignmentLine longestSequenceIdLength currentWindowPosition _alignmentEntry = (entrySequenceIdentifier _alignmentEntry) ++ concat (replicate (longestSequenceIdLength - length (entrySequenceIdentifier _alignmentEntry)) " ") ++ V.toList (V.slice currentWindowPosition 60 (V.fromList (entryAlignedSequence _alignmentEntry))) ++ "\n"+ data ClustalAlignmentEntry = ClustalAlignmentEntry { entrySequenceIdentifier :: String,@@ -79,7 +104,16 @@ secondaryStructureTrack :: String, energy :: Double }- deriving (Show, Eq)+ deriving (Eq)++instance Show StructuralClustalAlignment where+ show (StructuralClustalAlignment _alignmentEntries _secondaryStructureTrack _energy) + | not (null _alignmentEntries) = header ++ alignmentString+ | otherwise = header+ where header = "CLUSTAL W \n\n" + longestSequenceIdLength = (maximum (map length (map entrySequenceIdentifier _alignmentEntries))) + 1+ totalSequenceLength = length (entryAlignedSequence (head _alignmentEntries))+ alignmentString = showAlignment totalSequenceLength longestSequenceIdLength 0 _alignmentEntries _secondaryStructureTrack data StructuralClustalAlignmentSlice = StructuralClustalAlignmentSlice {
src/Bio/ClustalParser.hs view
@@ -118,14 +118,14 @@ newline newline newline- alignmentSlices <- many1 genParserClustalAlignmentSlice+ alignmentSlices <- many1 (try genParserClustalAlignmentSlice) eof return (mergealignmentSlices alignmentSlices) mergealignmentSlices :: [ClustalAlignmentSlice] -> ClustalAlignment mergealignmentSlices slices = alignment where entrySlicesList = map entrySlices slices -- list of lists of entry slices- sequenceIdentifiers = map entrySequenceSliceIdentifier (head entrySlicesList)+ sequenceIdentifiers = nub (map entrySequenceSliceIdentifier (head entrySlicesList)) alignmentEntriesListBySlice = map (map entryAlignedSliceSequence) entrySlicesList transposedAlignmentEntriesListbySlice = transpose alignmentEntriesListBySlice mergedAlignmentSequenceEntries = map concat transposedAlignmentEntriesListbySlice@@ -152,7 +152,7 @@ genParserClustalEntrySlice = do sliceIdentifier <- many1 (noneOf " ") spacer <- many1 (char ' ')- sliceSequence <- many1 (oneOf "NYRUAGCT-")+ sliceSequence <- many1 (oneOf "SNYRUAGCT-") newline return $ ClustalAlignmentEntrySlice sliceIdentifier sliceSequence (length spacer) @@ -189,29 +189,25 @@ genParseMlocarnaHeader :: GenParser Char st String genParseMlocarnaHeader = do- string "mLo"- many1 (noneOf "\n")+ string "mLocARNA"+ many1 (choice [alphaNum,oneOf "-: ()."]) newline string "Copyright"- many1 (noneOf "\n")+ many1 (choice [alphaNum,char ' ']) newline newline - many1 genParseAlignmentProcessStep+ string "Compute pair probs ..." newline+ string "Perform progressive alignment ..." newline- return ""--genParseAlignmentProcessStep :: GenParser Char st String-genParseAlignmentProcessStep = do- many1 (noneOf ".\n")- choice [try (string ("... ")), try (string ("..."))] newline+ newline return "" mergeStructuralAlignmentSlices :: [StructuralClustalAlignmentSlice] -> String -> Double -> StructuralClustalAlignment mergeStructuralAlignmentSlices slices secondaryStructure energy' = alignment where entrySlicesList = map structuralEntrySlices slices -- list of lists of entry slices- sequenceIdentifiers = map structuralEntrySequenceSliceIdentifier (head entrySlicesList)+ sequenceIdentifiers = (map structuralEntrySequenceSliceIdentifier (head entrySlicesList)) alignmentEntriesListBySlice = map (map structuralEntryAlignedSliceSequence) entrySlicesList transposedAlignmentEntriesListbySlice = transpose alignmentEntriesListBySlice mergedAlignmentSequenceEntries = map concat transposedAlignmentEntriesListbySlice@@ -231,7 +227,7 @@ genParserStructuralClustalEntrySlice = do sliceIdentifier <- many1 (noneOf " ") many1 (char ' ')- sliceSequence <- many1 (oneOf "NYRUAGCT-")+ sliceSequence <- many1 (oneOf "SNYRUAGCT-") newline return $ StructuralClustalAlignmentEntrySlice (filter (/='\n') sliceIdentifier) sliceSequence @@ -247,7 +243,7 @@ -- | Parse Clustal alignment (.aln) with secondary structure in dot-bracket notation from String (as produced by mlocarna) parseStructuralClustalAlignment :: String -> Either ParseError StructuralClustalAlignment -parseStructuralClustalAlignment = parse genParserStructuralClustalAlignment "genParserClustalAlignment"+parseStructuralClustalAlignment = parse genParserStructuralClustalAlignment "genParserStructuralClustalAlignment" -- | Parse Clustal alignment (.aln) with secondary structure in dot-bracket notation from filehandle (as produced by mlocarna) readStructuralClustalAlignment :: String -> IO (Either ParseError StructuralClustalAlignment)
+ test-suite/Spec.hs view
@@ -0,0 +1,2 @@+-- test-suite/Spec.hs+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}