ClustalParser 1.0.0 → 1.0.1
raw patch · 4 files changed
+130/−30 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bio.ClustalParser: ClustalGuideTree :: [ClustalGuideTreeEntry] -> ClustalGuideTree
- Bio.ClustalParser: ClustalGuideTreeEntry :: String -> Double -> ClustalGuideTreeEntry
- Bio.ClustalParser: data ClustalGuideTree
- Bio.ClustalParser: data ClustalGuideTreeEntry
- Bio.ClustalParser: entryDesignation :: ClustalGuideTreeEntry -> String
- Bio.ClustalParser: entryDistance :: ClustalGuideTreeEntry -> Double
- Bio.ClustalParser: guideTreeEntries :: ClustalGuideTree -> [ClustalGuideTreeEntry]
+ Bio.ClustalParser: StructuralClustalAlignment :: [ClustalAlignmentEntry] -> String -> Double -> StructuralClustalAlignment
+ Bio.ClustalParser: StructuralClustalAlignmentEntrySlice :: String -> String -> StructuralClustalAlignmentEntrySlice
+ Bio.ClustalParser: StructuralClustalAlignmentSlice :: [StructuralClustalAlignmentEntrySlice] -> StructuralClustalAlignmentSlice
+ Bio.ClustalParser: data StructuralClustalAlignment
+ Bio.ClustalParser: data StructuralClustalAlignmentEntrySlice
+ Bio.ClustalParser: data StructuralClustalAlignmentSlice
+ Bio.ClustalParser: energy :: StructuralClustalAlignment -> Double
+ Bio.ClustalParser: parseStructuralClustalAlignment :: String -> Either ParseError StructuralClustalAlignment
+ Bio.ClustalParser: readStructuralClustalAlignment :: String -> IO (Either ParseError StructuralClustalAlignment)
+ Bio.ClustalParser: secondaryStructureTrack :: StructuralClustalAlignment -> String
+ Bio.ClustalParser: structuralAlignmentEntries :: StructuralClustalAlignment -> [ClustalAlignmentEntry]
+ Bio.ClustalParser: structuralEntryAlignedSliceSequence :: StructuralClustalAlignmentEntrySlice -> String
+ Bio.ClustalParser: structuralEntrySequenceSliceIdentifier :: StructuralClustalAlignmentEntrySlice -> String
+ Bio.ClustalParser: structuralEntrySlices :: StructuralClustalAlignmentSlice -> [StructuralClustalAlignmentEntrySlice]
Files
- ClustalParser.cabal +8/−4
- ClustalParserTest.hs +2/−4
- src/Bio/ClustalData.hs +16/−7
- src/Bio/ClustalParser.hs +104/−15
ClustalParser.cabal view
@@ -5,7 +5,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.0.0+version: 1.0.1 synopsis: Libary for parsing Clustal tools output description: Currently contains parsers and datatypes for: clustalw2, clustalo .@@ -30,8 +30,8 @@ source-repository this type: git- location: https://github.com/eggzilla/ClustalParser/tree/1.0.0- tag: 1.0.0+ location: https://github.com/eggzilla/ClustalParser/tree/1.0.1+ tag: 1.0.1 library -- Modules exported by the library.@@ -40,10 +40,14 @@ -- Other library packages from which modules are imported. build-depends: base >=4.5 && <5, parsec- + -- compiler options+ ghc-options: -Wall -O2 -fno-warn-unused-do-bind -- Directories containing source files. hs-source-dirs: src executable ClustalParserTest main-is: ClustalParserTest.hs build-depends: base >= 4 && <= 5, cmdargs, ClustalParser+ -- compiler options + ghc-options: -Wall -O2+
ClustalParserTest.hs view
@@ -1,11 +1,9 @@ module Main where import System.Environment (getArgs)-import System.IO-import System.Environment import Bio.ClustalParser-import Data.Either- ++main :: IO () main = do args <- getArgs let input_file = (head args)
src/Bio/ClustalData.hs view
@@ -42,7 +42,6 @@ } deriving (Show, Eq) - -- | Data structure for Clustal alignment format data ClustalAlignment = ClustalAlignment { @@ -73,16 +72,26 @@ } deriving (Show, Eq) -data ClustalGuideTree = ClustalGuideTree+-- | Data structure for structural Clustal alignment format+data StructuralClustalAlignment = StructuralClustalAlignment { - guideTreeEntries :: [ClustalGuideTreeEntry]+ structuralAlignmentEntries :: [ClustalAlignmentEntry],+ secondaryStructureTrack :: String,+ energy :: Double } deriving (Show, Eq) -data ClustalGuideTreeEntry = ClustalGuideTreeEntry- { - entryDesignation :: String,- entryDistance :: Double+data StructuralClustalAlignmentSlice = StructuralClustalAlignmentSlice+ {+ structuralEntrySlices :: [StructuralClustalAlignmentEntrySlice] } deriving (Show, Eq)++data StructuralClustalAlignmentEntrySlice = StructuralClustalAlignmentEntrySlice+ {+ structuralEntrySequenceSliceIdentifier :: String,+ structuralEntryAlignedSliceSequence :: String+ }+ deriving (Show, Eq)+
src/Bio/ClustalParser.hs view
@@ -1,17 +1,17 @@ -- | Parse Clustal output-+-- For more information on Clustal tools consult: <http://www.clustal.org/> module Bio.ClustalParser ( parseClustalAlignment, readClustalAlignment,+ parseStructuralClustalAlignment,+ readStructuralClustalAlignment, parseClustalSummary, readClustalSummary, module Bio.ClustalData ) where import Bio.ClustalData-import Text.ParserCombinators.Parsec-import Text.ParserCombinators.Parsec.Token-import Text.ParserCombinators.Parsec.Language (emptyDef) +import Text.ParserCombinators.Parsec import Control.Monad import Data.List @@ -35,7 +35,7 @@ newline newline string "Sequence format is "- sequenceFormat <- many1 (noneOf "\n")+ sequenceFormat' <- many1 (noneOf "\n") newline sequenceParametersList <- many1 (try genParserSequenceParameters) string "Start of Pairwise alignments" @@ -45,7 +45,7 @@ newline pairwiseAlignmentSummaryList <- many1 genParserPairwiseAlignmentSummary string "Guide tree file created: ["- guideTreeFileName <- many1 (noneOf "]")+ guideTreeFileName' <- many1 (noneOf "]") char ']' newline newline@@ -60,16 +60,16 @@ newline groupSummaryList <- many1 genParserGroupSummary string "Alignment Score "- alignmentScore <- many1 digit+ alignmentScore' <- many1 digit newline newline string "CLUSTAL-Alignment file created ["- alignmentFileName <- many1 (noneOf "]")+ alignmentFileName' <- many1 (noneOf "]") char ']' newline newline eof - return $ ClustalSummary version sequenceFormat sequenceParametersList pairwiseAlignmentSummaryList guideTreeFileName (readInt numberOfGroups) groupSummaryList (readInt alignmentScore) alignmentFileName+ return $ ClustalSummary version sequenceFormat' sequenceParametersList pairwiseAlignmentSummaryList guideTreeFileName' (readInt numberOfGroups) groupSummaryList (readInt alignmentScore') alignmentFileName' genParserGroupSummary :: GenParser Char st GroupSummary genParserGroupSummary = do@@ -82,9 +82,9 @@ sequenceNumber <- optionMaybe (many1 digit) optional (many1 space) string "Score:" <|> string "Delayed"- groupScore <- optionMaybe (many1 digit) + groupScore' <- optionMaybe (many1 digit) newline- return $ GroupSummary (readInt groupIndex) (liftM readInt sequenceNumber) (liftM readInt groupScore)+ return $ GroupSummary (readInt groupIndex) (liftM readInt sequenceNumber) (liftM readInt groupScore') genParserPairwiseAlignmentSummary :: GenParser Char st PairwiseAlignmentSummary genParserPairwiseAlignmentSummary = do@@ -139,14 +139,14 @@ genParserClustalAlignmentSlice :: GenParser Char st ClustalAlignmentSlice genParserClustalAlignmentSlice = do- entrySlices <- many1 genParserClustalEntrySlice+ entrySlices' <- many1 genParserClustalEntrySlice --extract length of identifier and spacer to determine offset of conservation track- let offsetLenght = length (entrySequenceSliceIdentifier (head entrySlices)) + spacerLength (head entrySlices)+ let offsetLenght = length (entrySequenceSliceIdentifier (head entrySlices')) + spacerLength (head entrySlices') spacerAndConservationTrackSlice <- many1 (noneOf "\n")- let conservationTrackSlice = drop offsetLenght spacerAndConservationTrackSlice+ let conservationTrackSlice' = drop offsetLenght spacerAndConservationTrackSlice newline optional newline- return $ ClustalAlignmentSlice entrySlices conservationTrackSlice+ return $ ClustalAlignmentSlice entrySlices' conservationTrackSlice' genParserClustalEntrySlice :: GenParser Char st ClustalAlignmentEntrySlice genParserClustalEntrySlice = do@@ -156,6 +156,87 @@ newline return $ ClustalAlignmentEntrySlice sliceIdentifier sliceSequence (length spacer) +--Structural Clustal Parser functions++-- | Parse the input as ClustalAlignment datatype as used in mlocarna+genParserStructuralClustalAlignment :: GenParser Char st StructuralClustalAlignment+genParserStructuralClustalAlignment = do+ genParseMlocarnaHeader+ alignmentSlices <- many1 (try genParserStructuralClustalAlignmentSlice)+ secondaryStructure <- genSecondaryStructure + energy' <- genParseEnergy+ eof + return (mergeStructuralAlignmentSlices alignmentSlices secondaryStructure energy')++genSecondaryStructure :: GenParser Char st String+genSecondaryStructure = do+ string "alifold"+ many1 space+ secondaryStructure <- many1 (oneOf ".()")+ space+ return secondaryStructure++genParseEnergy :: GenParser Char st Double+genParseEnergy = do+ string "("+ many space + energy' <- many1 (noneOf " ")+ optional space+ char ('=')+ many1 (noneOf "\n")+ newline + return (readDouble energy')++genParseMlocarnaHeader :: GenParser Char st String+genParseMlocarnaHeader = do+ string "mLo"+ many1 (noneOf "\n")+ newline+ string "Copyright"+ many1 (noneOf "\n")+ newline+ newline + many1 genParseAlignmentProcessStep+ newline+ newline+ return ""++genParseAlignmentProcessStep :: GenParser Char st String+genParseAlignmentProcessStep = do+ many1 (noneOf ".\n")+ choice [try (string ("... ")), try (string ("..."))]+ 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)+ alignmentEntriesListBySlice = map (map structuralEntryAlignedSliceSequence) entrySlicesList + transposedAlignmentEntriesListbySlice = transpose alignmentEntriesListBySlice+ mergedAlignmentSequenceEntries = map concat transposedAlignmentEntriesListbySlice+ mergedAlignmentEntries = map constructStructuralAlignmentEntries (zip sequenceIdentifiers mergedAlignmentSequenceEntries)+ alignment = StructuralClustalAlignment mergedAlignmentEntries secondaryStructure energy' ++constructStructuralAlignmentEntries :: (String, String) -> ClustalAlignmentEntry+constructStructuralAlignmentEntries (entryIdentifier,entrySequence) = ClustalAlignmentEntry entryIdentifier entrySequence++genParserStructuralClustalAlignmentSlice :: GenParser Char st StructuralClustalAlignmentSlice+genParserStructuralClustalAlignmentSlice = do+ entrySlices' <- many1 (try genParserStructuralClustalEntrySlice)+ optional newline+ return $ StructuralClustalAlignmentSlice entrySlices'++genParserStructuralClustalEntrySlice :: GenParser Char st StructuralClustalAlignmentEntrySlice+genParserStructuralClustalEntrySlice = do+ sliceIdentifier <- many1 (noneOf " ")+ many1 (char ' ')+ sliceSequence <- many1 (oneOf "UAGCT-")+ newline+ return $ StructuralClustalAlignmentEntrySlice sliceIdentifier sliceSequence++-- exported functions+ -- | Parse Clustal alignment (.aln) from String parseClustalAlignment :: String -> Either ParseError ClustalAlignment parseClustalAlignment = parse genParserClustalAlignment "genParserClustalAlignment"@@ -163,6 +244,14 @@ -- | Parse Clustal alignment (.aln) from filehandle readClustalAlignment :: String -> IO (Either ParseError ClustalAlignment) readClustalAlignment = parseFromFile genParserClustalAlignment++-- | 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"++-- | Parse Clustal alignment (.aln) with secondary structure in dot-bracket notation from filehandle (as produced by mlocarna) +readStructuralClustalAlignment :: String -> IO (Either ParseError StructuralClustalAlignment) +readStructuralClustalAlignment = parseFromFile genParserStructuralClustalAlignment -- | Parse Clustal summary (printed to STDOUT) from String parseClustalSummary :: String -> Either ParseError ClustalSummary